Enterprise Java Development@TOPIC@

Enterprise Java (605.784.31) Development Environment Setup

Revision: v2013-09-02

Built on: 2014-03-07 00:43 EST

Abstract

This paper contains setup information required to begin building, deploying, running, and modifying examples. It also provides a basis for building class projects to be turned in.


Purpose
1. Java JDK Setup
1.1. Download and Install JDK
1.2. Verify your JDK is installed
2. Git Client Setup
2.1. Install Git Client
2.2. Get Class Repository
3. Maven Environment Setup
3.1. Maven Installation
3.2. Maven Configuration
3.3. Test Maven Build
3.4. Missing Dependencies
4. (Optional!!!) Maven Proxy Setup
4.1. Nexus OSS Manual Setup
4.2. Integrate Proxy with Maven
5. JBoss Setup
5.1. Download and Install JBoss EAP 6.1.0.Final
5.2. Configure JBoss Server
5.3. Add JBoss Admin Account
5.4. Enable JBoss Remote Debugging
5.5. Define JBoss Maven Properties in settings.xml
6. H2 Database Setup
6.1. Locate the h2*.jar file
6.2. Start Server
6.3. Access DB User Interface
6.4. Activate H2 Server Profile for Builds
6.5. Update JBoss to use Server Mode
7. Eclipse Setup
7.1. Download and Install Eclipse Kepler
7.2. Define JDK location
7.3. Setup Maven Eclipse Integration (m2e)
7.4. Setup EGit Eclipse Team Provider
7.5. Setup JBoss Eclipse Integration
8. Ant Setup
8.1. Install Ant

You will need a copy of either Java 6 or Java 7 SDK installed. JavaEE 6 only requires JDK 6 but but JDK 6 will soon hit its end-of-life. The instructions describe downloading JDK 7.

Java 6 source environment/Java 7 target environment

The Maven configuration for class will default to Java 6-compliant source while targeting a Java 7 runtime. This should give us a decent fallback option between the two versions during this transition period. To use a Java 6 runtime, simply override the default "java.target.version=1.7" property using your Maven .m2/settings.xml.

Keep 32/64-bit choices consistent

Keep the 32/64-bit choice consistent with what you download later for Eclipse.

You will use Git in this class to perform an initial checkout and get updates for source files. Any Git client should be able to perform that function. You can determine if you have a command line Git client already installed using the following simple command.


There are a number of options and some are going to be based on on your platform. Your basic options include command line or using an Eclipse plugin

The class repository is located on github and can be browsed using the following http URL https://github.com/jcstaff/ejava-javaee. With a cloned copy, you can receive file updates during the semester.

  1. CD to a directory you wish to place source code. Make sure the path to this directory contains no spaces.

  2. Clone the class repository using the following URL git://github.com/jcstaff/ejava-javaee.git

    git clone git://github.com/jcstaff/ejava-javaee.git
    ...
    
    $ ls ejava-javaee/
    ...
    
    $ cd ejava-javaee
    $ git branch -a    //list all branches -- local and remote
    * master
      ...
      remotes/origin/HEAD -> origin/master
      remotes/origin/master
      remotes/origin/working
    

    Note

    Git leaves you with all branches fetched and a local master branch referencing the class' master branch on github. You will be using the master branch for the duration of the semester. The other branch of interest is 'working'. This contains my in-progress daily changes. The master branch is usually updated the evening before or the day of class and should always be stable.

  3. Perform a mock update. This is what you will be doing several times this semester to get file updates.

    $ git checkout master //switches to master branch
    $ git pull            //downloads changes and attempts merge
    Already up-to-date.
    

    Note

    There are many modules within the class repository. Some are ready for use, some are still being worked, and some are not for use this semester. The ones ready for your use will be wired into the build and will be compiled during a follow-on section. The list will increase as the semester moves forward. Please ignore these extra modules. Keeping them within the baseline helps me keep related things centralized.

    Note

    If you ever make changes to the class examples and would like to keep those changes separate from the updates. Store them in a new branch at any time using the following git commands.

    $ git checkout -b new-branch master  //creates new branch from master 
                                         //and switches to that branch
    $ git commit -a -m "saving my stuff" //commits all dirty files to new branch
    $ git checkout master                //switches back to the master branch 
    

    If you simply want to throw away any changes you made, you can discard those changes to tracked files using the following git commands.

    $ git reset --hard master
    $ git clean -rn  //shows you what it would delete without deleting 
    $ git clean -rf  //deletes files not managed or specifically ignored by git
    

  1. Download Maven 3 http://maven.apache.org/download.html

  2. Unzip the contents into a directory with no spaces in its path.

    $ ls apache-maven-3.1.0/
    bin  boot  conf  lib  LICENSE.txt  NOTICE.txt  README.txt
    
  3. Add an environment variable for MAVEN_HOME and add MAVEN_HOME/bin to your PATH

    //my linux system -- should be done in .bashrc
    export MAVEN_HOME=/opt/apache-maven-3.1.0
    export PATH=$MAVEN_HOME/bin:$PATH
    
    //my windows system -- should be done in Advanced System Settings->Environment Variables
    set MAVEN_HOME=/apps/apache-maven-3.1.0
    set PATH=%MAVEN_HOME%\bin;%PATH%
    
  4. Verify maven is installed and in the path (TODO:Update Windows Example)

    //my fedora system
    $ mvn --version
    Apache Maven 3.1.0 (893ca28a1da9d5f51ac03827af98bb730128f9f2; 2013-06-27 22:15:32-0400)
    Maven home: /opt/apache-maven-3.1.0
    Java version: 1.7.0_25, vendor: Oracle Corporation
    Java home: /usr/lib/jvm/java-1.7.0-openjdk-1.7.0.25.x86_64/jre
    Default locale: en_US, platform encoding: UTF-8
    OS name: "linux", version: "3.8.13-100.fc17.x86_64", arch: "amd64", family: "unix"
    
    //my windows xp system
    > mvn --version
    Apache Maven 3.0.4 (r1232337; 2012-01-17 03:44:56-0500)
    Maven home: C:\apps\apache-maven-3.0.4\bin\..
    Java version: 1.7.0_11, vendor: Oracle Corporation
    Java home: C:\apps\Java\jdk1.7.0_11\jre
    Default locale: en_US, platform encoding: Cp1252
    OS name: "windows xp", version: "5.1", arch: "x86", family: "windows"
    
  1. Add a skeletal settings.xml file that will be used to provide local overrides for the build. This is the place where you can customize the build for local environment specifics like directory locations, server address, server ports, etc.

    1. Add the following to the.m2/settings.xml file in your HOME directory.

      
      
      <?xml version="1.0"?>
      <settings xmlns="http://maven.apache.org/POM/4.0.0"
          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
          xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd">

          <offline>false</offline>
          
          <profiles>
          </profiles>
          
          <activeProfiles>
          </activeProfiles>
      </settings>    
    2. You can test whether your settings.xml file is seen by Maven by temporarily making it an invalid XML file and verifying that the next Maven build command fails with a parsing error.

      $ mvn clean
      [ERROR] Error executing Maven.
      [ERROR] 1 problem was encountered while building the effective settings
      [FATAL] Non-parseable settings /home/user/.m2/settings.xml: only whitespace content allowed before start tag and not s (position: START_DOCUMENT seen <?xml version="1.0"?>\ns... @2:2)  @ /home/user/.m2/settings.xml, line 2, column 2
      
    3. Add a default specification for the database profile we will be using for class at the bottom of the .m2/settings.xml file in your HOME directory.

      
      
          <activeProfiles>
              <activeProfile>h2db</activeProfile>
          </activeProfiles>
    4. If your operating system HOME directory has spaces in the path (e.g., Windows XP's Documents and Settings) then add a localRepository path specification to the .m2/settings.xml file and have it point to a location that does not have spaces in the path. The path does not have to exist. It will be created during the next build.

      
      
          <offline>false</offline>
          <!-- this overrides the default $HOME/.m2/repository location. --> 
          <localRepository>c:/jhu/repository</localRepository>

There are a few cases where dependencies cannot be hosted in public repositories and must be downloaded and installed manually. Oracle DB Client is one example.


If the message is a warning (i.e., for site/javadoc documentation -- it can be ignored). If you want to eliminate the warning or it is coming up as an error, you can download the artifact directly from the vendor and manually install it in your local repository.

  1. Download the driver jar from Oracle accept the license agreement.

  2. Install it manually into your localRepository

    $ mvn install:install-file -Dfile=/home/jcstaff/Downloads/ojdbc6.jar -DgroupId=com.oracle -DartifactId=ojdbc6 -Dversion=11.2.0.3 -Dpackaging=jar
    [INFO] Scanning for projects...
    ...
    [INFO] --- maven-install-plugin:2.4:install-file (default-cli) @ standalone-pom ---
    [INFO] Installing /home/jcstaff/Downloads/ojdbc6.jar to /home/jcstaff/.m2/repository/com/oracle/ojdbc6/11.2.0.3/ojdbc6-11.2.0.3.jar
    [INFO] ------------------------------------------------------------------------
    [INFO] BUILD SUCCESS
    ...
    

Artifacts are Best Placed in Network Repositories

This artifact would ideally be placed within a network cache/repository (i.e., Nexus) and not into individual localRepositories. In the next chapter you will be shown how could could setup a Maven Nexus for team use. If you go that route -- it would be better to upload the file to that archive.

Rogue Internet Repositories

Probably violating license restrictions, but the following network repository does contain the missing Oracle driver. One could add that as an upstream repository in their Nexus or define it as an artifact repository in the pom to avoid having to manually import the artifact.

As you should have noticed in the previous section, you can function just fine as a developer connected to the Internet as long as the critical Internet resources are available when they are needed to populate your localRepository cache. However, if you were part of a larger development team you would not want each separate developer reaching out the Internet to locate a common dependency. There is both a speed and failure issue with that type of setup.

The steps listed in this chapter are not necessary for class because you work alone and you have a localRepository cache. In fact -- I urge you not to follow them unless you feel the strong desire to dig deeper in this enterprise development setup. However, it does provide you with some experience in setting up and using a realistic production maven environment.

Still here? Okay -- lets get started...

In the previous section we installed and setup Maven in a stand-alone client mode. In that mode the individual environment communicated directly with the external Internet organizations to obtain missing artifacts. In this section we will add a proxy server between the developer and the Internet so that one or more developers can share what has already been downloaded and be completely isolated from network and remote outages. Ideally this proxy would be placed on a shared server somewhere on your local Intranet with access to the outside Internet. The instructions will act as though you are installing it locally. It is your decision whether to use it and where to install it. If you do not install and configure a proxy -- you will notice small delays in your builds while your local maven client checks Internet sources for new artifacts and updates to existing artifacts.


This procedure will take you through a manual download and setup of the Nexus OSS software and have you go thru a manual setup of all items. Use this approach if you want a minor amount of experience in setting up the sever.

  1. Download the Nexus OSS Software from Sonatype http://www.sonatype.org/nexus/go

  2. Unzip the the compressed file to your filesystem. There will be two directories created; one for the software (nexus-(version)) and another for the repository caches (sonatype-work)

    $ tar tzf ~/Downloads/nexus-2.6.1-02-bundle.tar.gz 
    nexus-2.6.1-02/nexus/WEB-INF/plugin-repository/nexus-healthcheck-oss-plugin-2.6.1-02/nexus-healthcheck-oss-plugin-2.6.1-02.jar
    ...
    
    
    $ ls nexus-2.6.1-02/ sonatype-work/
    nexus-2.6.1-02/:
    bin  conf  lib  LICENSE.txt  logs  nexus  NOTICE.txt  tmp
    
    sonatype-work/:
    nexus  README.txt
    
  3. The server will listen on port 8081 on all interfaces (0.0.0.0) by default. Modify nexus-2.6.1-02/conf/nexus.properties if you want something different.

    $ more nexus-2.6.1-02/conf/nexus.properties                                                                                                                                       
    ...
    # Jetty section
    application-port=8081
    application-host=0.0.0.0
    ...
    
  4. Locate the startup script in the NEXUS_HOME/bin directory.

    $ ls nexus-2.6.1-02/bin/
    jsw  nexus  nexus.bat                 
    

    Tip

    Linux users might want to register this script in /etc/init.d. If you also configure it to automatically start at boot -- supply a value for RUN_AS_USER to keep the server from running as root. I also needed to change "su - $RUN_AS_USER" to "su -m $RUN_AS_USER..." because of the way my legacy nexus account was setup for nologin.

  5. Use the script appropriate for your platform to start and perform other controls on the server.

    $ nexus-2.6.1-02/bin/nexus
    Usage: nexus-2.6.1-02/bin/nexus { console | start | stop | restart | status | dump }
    
    $ nexus-2.6.1-02/bin/nexus start
    Starting Nexus OSS...
    Started Nexus OSS.
    

    Note

    The above command attempts to run Nexus as a service. If you do not have the permission on your system to register nexus as a service, you can optionally run it as an interactive command.

                        
    $ nexus-2.6.1-02/bin/nexus console
    /etc/init.d/nexus console
    Running Nexus OSS...
    wrapper  | --> Wrapper Started as Console
    wrapper  | Launching a JVM...
    jvm 1    | Wrapper (Version 3.2.3) http://wrapper.tanukisoftware.org
    jvm 1    |   Copyright 1999-2006 Tanuki Software, Inc.  All Rights Reserved.
    jvm 1    | 
    jvm 1    | 2012-04-26 12:14:38.531:INFO:oejs.Server:jetty-7.5.4.v20111024
    

    The specific error observed on Windows was

                        
    wrapper | The nexus-webapp service is not installed - The specified service does not exist as an installed service. (0x424)                            
    

  6. Access the Web UI for Nexus OSS http://localhost:8081/nexus

  7. Login with the default account of admin/admin123

  8. Change the admin password (or not) using Security->Change Password

  9. Add remote repositories

    1. Click on Views/Repositories->Repositories

    2. Click the +Add...Proxy Repository

    3. Fill in the data for the repositories in the following Repositories table. Use default values for anything not included in the table.

    4. Press Save


    Note

    If the provided list is missing any sources, check for a current list of repositories and plugin repositories in ejava-build/dependencies/pom.xml from the class source tree and add those as well.

    Note

    Nexus will check each repository as they are added. Try restarting if things get stuck.

    $ service nexus restart
    Stopping Nexus OSS...
    Stopped Nexus OSS.
    Starting Nexus OSS...
    Started Nexus OSS.
    
  10. Add the created repositories to the Public Repositories

JBoss Application Server (AS) and JBoss Enterprise Application Platform (EAP)

JBoss has a community version (JBoss AS) and commercial version (JBoss EAP) of their JavaEE application server. Both are open source and built off the same code base. In theory, changes propagate through the community version first in daily changes and short iterations. In theory, commercial version is a roll-up of a stable version of the community version with the ability to purchase support on that specific version. With commercial version support -- you can receive patches for a specific issue prior to upgrading to the latest release. With the community version -- you pretty much need to keep up with the latest release to get any patches. Of course, with either version you are free to perform your own support and code changes, but you can only get this commercially with the EAP release.

JBoss has recently changed its distribution policy. It now makes the EAP version available for *development* use. You will be asked to download EAP and accept licensing terms that forbids you from using the software in production and using whatever support you receive from them on that product from setting up your own re-selling business.

JBoss AS version numbers are ahead of JBoss EAP because not every community version becomes a commercial version. JBoss AS 6 was skipped entirely by EAP. There is a good article on the pairings between the two product lines on the RedHat Customer Portal

JBoss AS 7.2.0.Final <= JBoss EAP 6.1.0.Final

We will be downloading JBoss EAP server for class use since that is the most stable release available. Build dependencies will use the community version since those versions are available from an Internet-accessible Nexus repository. If that becomes an issue, we can switch versions without much issue.

  1. Download JBoss 6.1.0 EAP http://www.jboss.org/jbossas/downloads. The 'Quickstarts' examples are also helpful but class notes, exercises, and guidance may have simplified, generalized, or alternative approaches to what is contained in the guides.

  2. Install JBoss into a directory that does not have any spaces in its path.

    $ unzip ~/Downloads/jboss-eap-6.1.0.Final.zip                
                    
    $ ls jboss-eap-6.1.0.Final/
    
  3. Test the installation by starting the default configuration installation.

    $ ./jboss-eap-6.1.0.Final/bin/standalone.sh 
    =========================================================================                                                                                                                     
                                                                                                                                                                                                  
      JBoss Bootstrap Environment                                                                                                                                                                 
                                                                                                                                                                                                  
      JBOSS_HOME: /opt/jboss-eap-6.1                                                                                                                                                              
                                                                                                                                                                                                  
      JAVA: /usr/bin/java                                                                                                                                                                         
                                                                                                                                                                                                  
      JAVA_OPTS:  -server -XX:+UseCompressedOops -Xms1303m -Xmx1303m -XX:MaxPermSize=256m -Djava.net.preferIPv4Stack=true 
          -Djboss.modules.system.pkgs=org.jboss.byteman -Djava.awt.headless=true 
    
    =========================================================================
    
    13:26:53,149 INFO  [org.jboss.modules] (main) JBoss Modules version 1.2.0.Final-redhat-1
    13:26:53,423 INFO  [org.jboss.msc] (main) JBoss MSC version 1.0.4.GA-redhat-1
    13:26:53,554 INFO  [org.jboss.as] (MSC service thread 1-3) JBAS015899: JBoss EAP 6.1.0.GA (AS 7.2.0.Final-redhat-8) starting
    ...
    13:26:59,008 INFO  [org.jboss.as] (Controller Boot Thread) JBAS015961: Http management interface listening on http://127.0.0.1:9990/management
    13:26:59,009 INFO  [org.jboss.as] (Controller Boot Thread) JBAS015951: Admin console listening on http://127.0.0.1:9990
    13:26:59,010 INFO  [org.jboss.as] (Controller Boot Thread) JBAS015874: JBoss EAP 6.1.0.GA (AS 7.2.0.Final-redhat-8) started in 6349ms - 
        Started 146 of 217 services (70 services are passive or on-demand)
    

    Note

    There are .sh version of scripts for *nix platforms and .bat forms of the scripts for Windows platforms. Use the one that is appropriate for your environment.

  4. Verify you can access the server

Prepare your server for remote debugging for later.

  1. Uncomment the following line in either bin/standalone.conf (Linux) or bin/standalone.conf.bat (Windows)

    # Sample JPDA settings for remote socket debugging
    JAVA_OPTS="$JAVA_OPTS -Xrunjdwp:transport=dt_socket,address=8787,server=y,suspend=n"
    
  2. Restart the server and notice the additional listen output. Use control-C to stop the server.

    $ ./jboss-eap-6.1.0.Final/bin/standalone.sh 
    =========================================================================
    ...
    
    Listening for transport dt_socket at address: 8787
    13:26:53,149 INFO  [org.jboss.modules] (main) JBoss Modules version 1.2.0.Final-redhat-1
    13:26:53,423 INFO  [org.jboss.msc] (main) JBoss MSC version 1.0.4.GA-redhat-1
    
  3. If you already have a process listening on 8080 or any of the other JBoss ports on 127.0.0.1, you can switch addresses by editing the interfaces section of standandalone.xml. You can also do this at runtime by adding -Djboss.bind.address.management=... and/or -Djboss.bind.address=... on the command line.

    
    
        <interfaces>
            <interface name="management">
                <loopback-address value="${jboss.bind.address.management:127.0.0.5}"/>
            </interface>
            <interface name="public">
                <loopback-address value="${jboss.bind.address:127.0.0.5}"/>
            </interface>
            <interface name="unsecure">
                <inet-address value="${jboss.bind.address.unsecure:127.0.0.5}"/>
            </interface>
        </interfaces>

The application server and application clients used in class require a relational database. Application server vendors generally package a lightweight database with their downloads so that the server can be used immediately for basic scenarios. JBoss comes packaged with the H2 database. This database can run in one of three modes

  • Embedded/in-memory

  • Embedded/file

  • Server-based

File-based versus in-memory allows you to do post-mortem analysis of the database after a test completes. File-based also allows you to initialize the database schema in one process and use the database within another. Using server-based mode allows you to inspect the database while the application is running.

JBoss and the class examples come setup with embedded drivers. You can change the configuration at any time to a server-based configuration using the following instructions.

Choose Right Mode for Right Need

Using embedded mode requires less administration overhead in the test environment.

Using server mode provides access to database state during application execution -- which is good for debugging.

Note

This will create a database folder called "ejava" relative to where you started the database server.

Note

LOCK_MODE refers to how you want your connection impacted by other transactions in progress. A normal application would want some isolation between transactions, but it is useful to have the UI be able to watch in-progress transactions (i.e., perform dirty reads). The options include:

  • 0 - Read Uncommitted - transaction isolation disabled

  • 1 - Serializable - database is (read and write) locked until transaction commits

  • 3 - Read Committed (default) - read locks released after statement completes

The most current version of Eclipse is Kepler. I am just now starting to use it and so far it is fantastic. If we run into issues, we could drop back to Juno SR2, but at this point I do not anticipate any issues.

  1. Download Eclipse IDE for JavaEE Developers http://eclipse.org/downloads

  2. Unzip the downloaded archive.

    $ tar xzf ~/Downloads/eclipse-jee-kepler-R-linux-gtk-x86_64.tar.gz
    
    $ ls eclipse
    about_files  about.html  artifacts.xml  configuration  dropins  eclipse  eclipse.ini  
    epl-v10.html  features  icon.xpm  notice.html  p2  plugins  readme
    
  3. Create a shortcut for starting Eclipse

  4. Start Eclipse

m2e is a plugin installed into Eclipse that configures Eclipse based on the Maven pom.xml configuration. When adjusting your builds, you should always define changes within the Maven pom.xml and rely on m2e to translate that into Eclipse. Any changes added directly to Eclipse will not be seen by the command-line build.

  1. Add the Java Package Explorer to the JavaEE Perspective. I find this easier to work with than the Project Explorer used by default in the JavaEE perspective.

  2. Import the class examples into Eclipse as a Maven Project

Add the following repository to your Eclipse instance and install the plugin

  1. Open the Eclipse Marketplace panel using Help->Eclipse Marketplace

  2. Type JBoss into the seach field and press Go

  3. Click Install for the JBoss Tools (Kepler)

  4. Complete the installation steps for JBoss Tools. There are many tools in the repository. Not all of them are needed for class or obvious how to use them without more investigation. Choose the following suggested minimal set.

  5. Define a Server Instance for JBoss

Ant is used in class to wrap command lines and encapsulate the building of classpaths for stand-alone applications. Just download and add Ant to your PATH here.

Note

The latest version of Ant is 1.9.2. The latest version I have tested with is 1.8.4. Until told otherwise, please download and configure the 1.8.4 version from the Ant archive until I get a chance to try things with the newer release.