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.

Component to download Notes More notes
Java Development Kit 1.8 Not JRE only. Any newer version (e.g. JDK 11) is incompatible with the described toolset currently.
Run the Eclipse Installer, install the Java EE Developers IDE Make sure you get the “EE” edition. Alternatively, download and extract the zip file.
EclipseLink Installer This is the persistence provider.
GlassFish 5.0 - Full Platform Not needed for JPA exercises.
Lombok Run the downloaded .jar file. In the installer, don’t rely on autodetection: select your Eclipse directory manually.
bin distribution of Derby Get the topmost .zip file.

Install Eclipse modules.

Eclipse menu to choose What Notes More notes
Help⇉Eclipse Marketplace AnyEdit Tools
Help⇉Install new software GlassFish Tools http://download.eclipse.org/glassfish-tools/1.0.0/repository Don’t install from Eclipse Marketplace.

Setup Eclipse.

Setup library access paths.

  1. Open Window⇉Preferences⇉Java⇉Build Path⇉Classpath Variables.
  2. Click New... to add the following variables.

    Variable name Type Set it to this content Notes More notes
    DERBY folder your extracted db-derby-10.14.2.0-bin folder Not the bin folder inside.
    ECLIPSELINK folder your extracted eclipselink folder Not the bin folder inside.
    GLASSFISH folder your extracted glassfish5 folder Not the bin folder inside.
    LOMBOK file your lombok.jar file
    PERS file the file jlib/jpa/javax.persistence_VSN.vVSN.jar under eclipselink Not the file with source in its name. VSN is a version number
  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.

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 db\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.

Additional settings for comfort. [Optional]

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.
    cd %USERPROFILE%
    mkdir derbytmp
    cd derbytmp
    
    set "DERBY_OPTS=-Duser.language=en -Dderby.drda.debug=true"
    
    "DERBY\bin\startNetworkServer.bat"
  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.

Notes:

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 underscores.
      • 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.

Troubleshooting