Environment setup for Scalable Enterprise Applications

About this file

These are step-by-step instructions that describe how you can set up an environment for the Scalable Enterprise Applications course.

Setting up the examples’ environment

Get the tools.

Install Eclipse modules.

Setup Eclipse.

Setup library access paths.

  1. Open Window⇉Preferences⇉Java⇉Build Path⇉Classpath Variables.
  2. Click New... to add the following variable.
  3. If the Markers tab shows Unbound classpath variable problems, open the related project’s properties, then Java Build Path⇉Libraries. There, all items with variables should show the resolved full paths. If some of them are missing, fix the variable’s contents.

Prepare the examples.

  1. Download the examples and unzip them into the workspace folder.
  2. File⇉Import, select Existing Projects into Workspace.
    1. Browse your workspace folder.
    2. Click Finish.
  3. File⇉Import⇉Working Sets. Select enterprise-applications-working-sets.wst (the only file in the workspace folder, below the directories) in your workspace folder, then click Finish.
  4. Note that you will need to start the database server before you can run the examples.

These additional steps are also suggested for extra comfort.

Setup the application server. [Not needed for JPA only]

  1. In File⇉New⇉Other...⇉Server, choose GlassFish.
  2. Start GlassFish. (Right click on it.)
  3. Once it’s running, in the GlassFish administrator console, add the following.

Setup the database viewer. [Optional for JPA]

  1. Go to Window⇉Show view⇉Data Source Explorer. The Data Source Explorer tab opens.
  2. In the tab, right click on Database Connections, and select New...
  3. Choose Derby, then click Next.
  4. Click the globe with star/green plus icon (tooltip: New Driver Definition)
  5. Choose Derby Client JDBC Driver, 10.2.
    1. You’ll see a red error indicator. Don’t worry, we’ll fix it.
    2. Choose the JAR List tab.
    3. Click on derbyclient.jar, then on Edit JAR/Zip...
      • Select GLASSFISH/javadb/lib/derbyclient.jar under your JDK folder.
  6. Click OK to exit "Edit Driver Definition"
  7. To test the connection, the database has to be running, of couse.
  8. Click Finish.
  9. You can use the Database Connections tab to check the actual contents of the database when you run the examples.

Common tasks

Running the database server

In most of the examples, we use JPA, which is configured to try to connect to a running Derby instance. The following steps help you start a Derby instance. You need to do this again every time you start working with the examples.

  1. Open a command prompt (Windows key, then type cmd), then execute the following commands.
    mkdir derbytmp
    cd derbytmp
    set "DERBY_OPTS=-Duser.language=en -Dderby.drda.debug=true"
  2. After some seconds, you will see the message Apache Derby Network Server started and ready to accept connections on port 1527. If you don’t, there is something wrong.
  3. Keep this command line window open as long as you need the Derby connection.


Creating a Web application

You can create a web application in Eclipse in the following way.

  1. Make a new Dynamic Web Project.
  2. Right click on the project in Project Explorer, and choose Java EE Tools⇉Generate Deployment Descriptor Stub. This generates a web.xml file in WebContent/WEB-INF.
  3. If you are using JPA within GlassFish, you have to set that up as well.
    1. Go to the GlassFish Console: in your browser, go to the URL http://localhost:4848.
    2. Select Create New JDBC Resource.
      • Create the resource jdbc/YOURPERSISTENCEUNIT.
      • For older versions of GlassFish, you have to create two resources for each JTA data source: jdbc/YOURPERSISTENCEUNIT__pm and jdbc/YOURPERSISTENCEUNIT__nontx.
        • Note the double underscore.
      • The JTA data source can be found under JPA Content⇉persistence.xml⇉Source⇉jta-data-source in your project.
    3. Now, we are using Derby even more indirectly: we use JTA (Java Transaction API), which has to be indicated in META-INF/persistence.xml.
    4. Of course, Derby has to be running when you are deploying your application. See the section Running the database server.
  4. Basic setup is done, now you can create HTML files, servlets, JSP files, @WebMethods etc.
  5. If you encounter any problems, see the GlassFish part of Troubleshooting.

Unfortunately, the GlassFish admin console sometimes fails spectacularly when you try creating a resource with it. Here is another approach.

  1. Run $GLASSFISH/bin/asadmin start-domain in a console.
  2. Run $GLASSFISH/bin/asadmin create-jdbc-resource --connectionpoolid=DerbyPool RESOURCENAME

Creating an EJB

You can create a basic EJB following these steps. You will need to create four projects.

  1. Make a Java project for the interface of the EJB.
  2. Make an EJB project for the implementation of the EJB.
  3. Make an Enterprise Application Project that deploys the EJB.
  4. Make a Java project for the client.