de.velopmind | The Det about Programming

February 10, 2010

How to setup NB for GAE with Scala – Part II

Filed under: GoogleAppEngine, Netbeans, Scala — de.velopmind @ 12:55 am

Create Projects

After we set up Netbeans with the necessary plugins and user defined libraries, we will now create our first Google App Engine  web project and corresponding Scala project.

Create a Web Application Project for Google App Engine

First we create a typical Web Application project with Google App Engine (GAE) as the server. You should have already read how this works in the plugin’s starter tutorial linked above.

This project will be our main project for packaging and deployment, and will contain all the web specific stuff like JSPs or GWT code and so on.

Step 1: Select New Project in the project view’s context menu or the file menu and choose type “Web Application”

Step 2: Set Name and Location

Step 3: Select Google App Engine as Server

After pressing Finish you see the project in the project view. If you do this the first time, you perhaps want to follow the guideline of the linked starter tutorial to do a first local and possibly remote deployment and enjoy the Hello World jsp example. For the next steps I assume that you have already done such playing with GAE and now are interested in the Scala steps.

Create a new Scala Library project

So let’s now create a new Scala project by applying almost the same steps like before.

Step 4: Create a new Scala project of type Scala Class Library

Step 5: Set again theName and Location

Now your Project View should look like this

At this point we merely have two separate projects which know nothing about each other. The next part will be to construct a connection between them.

Configure the Web App project

To prepare the web project for the Scala part, we have to do two things.

First the Scala runtime library must be part of the project so that it is deployed together with the rest. Otherwise the compiled Scala will not find its dependencies.

Add Scala library

Step 5: Open library configuration dialog for your Web project

Step 6: Add Scala library

Connect Scala Project

Second, the Scala project is connected so that its eventually built jar file will also be referenced and deployed together with the other configured libraries.

Step 7 Now add the Scala Project to the Web Project

Step 8

Configure the Scala project

Step 9: Add App Engine Libraries to Scala Project

Ready for first test

Your project should now look like this

At this point you can write Scala code which is called for example in JSPs located in the Web project.

As an example create in your Scala project a package named “testapp” and in that create a Scala class with the following source:

package testapp
class FirstScala {
  def someMethod() = {
    "This comes from Scala!!"

Then in your web project change the autmatically created index.jsp like this:

    Document   : index
    Created on : 23.01.2010, 12:05:46
    Author     : Det

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@page import="testapp.FirstScala"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>JSP Page</title>
        <h1>Hello World!</h1>
        <p>Test: <%= new FirstScala().someMethod() %></p>

After deploying this app to your local GAE server or to your App Engine space on the google site, you should see a web page containing:

Please note that for local test deployment you only need to call “deploy” in the context menu of your Web project. The compilation of the connected Scala project and the packaging of all dependent libraries into the application’s war will work automatically without any further build file manipulation.

This example would not need the app-engine libraries we configured above. We did it to prepare access to all the GAE services from within Scala code without getting compile time errors. These two libraries are deployed with your app, but it is the Web project’s build process that automatically takes care about that.

In this state it is NOT possible so far to write Servlets in Scala.

So in the upcoming installment we will further setup our Scala project for Servlet development:  Follow me …



  1. […] the combination of projects for each application. Possibly related posts: (automatically generated)How to setup NB for GAE with Scala – Part IIMy current playground (NB, GAE, Groovy, Scala, […]

    Pingback by How to setup Netbeans for Google App Engine with Scala « The Det about Programming — February 17, 2010 @ 5:05 am

  2. Hi, note about getting JDO to work on the scala classes:

    I had to add the following to my build.xml file since only the classes in the gae application got enhanced.

    Comment by jwiklund — April 23, 2010 @ 2:43 pm

  3. That did not work, can not post xml to comment. Trying with escaped.

    <property name="appengine" location="C:/NoInstall/appengine-java-sdk-1.3.3/lib"/>
    <property name="" location="${appengine}/appengine-tools-api.jar"/>
    <property name="appengine.classpath" location="${appengine}/user/appengine-api-1.0-sdk-1.3.3.jar"/>
    <taskdef name="enhance"
    classname="" />
    <target name="-post-compile">
    <enhance failonerror="true" api="JDO">
    <pathelement path="${}"/>
    <pathelement path="${appengine.classpath}"/>
    <pathelement path="${build.classes.dir}"/>
    <pathelement path="${scala.home}/lib/scala-library.jar"/>
    <fileset dir="${build.classes.dir}" includes="**/*.class"/>

    Comment by jwiklund — April 23, 2010 @ 2:45 pm

RSS feed for comments on this post. TrackBack URI

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

Create a free website or blog at

%d bloggers like this: