TimeTracker Tour

Before we start building TimeTracker from scratch, let's take a test drive of the finished application. This will give you a good feel for what you are about to embark on and also give you some direction in case you get stuck. You will also get hands on experience with various development procedures, such as administering JBoss. These will be helpful when you start building your application from scratch.

Follow these steps to build and run TimeTracker:

  1. Download the source for the finished application and unzip it at C:\. You will get a directory called C:\Workspaces\timetracker-completed. Note: If you decide to unzip the tutorial at a different location, make sure there are no spaces in your pathname - otherwise Maven will run into build problems.
  2. Open a Command Prompt in the directory C:\Workspaces\timetracker-completed.
  3. Execute the command mvn install to build the application. This step downloads all the libraries needed to build the TimeTracker application from remote Maven repositories. These libraries have been specified in the various pom.xml files under the TimeTracker source tree. Due to the sheer number and size of these libraries, this step will take a significant amount of time. However, be assured that your next build will be much faster because all the necessary dependencies will be available locally. Note that sometimes due to bad Internet connectivity or server load, Maven may not be able to download all dependencies in one go. If your build fails due to this reason, try to issue the command again until you get a successful build.
  4. Let this Command Prompt remain open for subsequent steps.
  5. Now that we have built the application, let us create a datasource for the H2 database on the target server. For JBoss7:
            <subsystem xmlns="urn:jboss:domain:datasources:1.0">
                <datasources>
                    <datasource jndi-name="java:jboss/datasources/ExampleDS" pool-name="H2DS" enabled="true" jta="true" use-java-context="true" use-ccm="true">
    ...
                    <datasource jndi-name="java:/jdbc/timetracker" pool-name="timetracker_Pool" enabled="true" jta="true" use-java-context="true" use-ccm="true">
                        <connection-url>
                            jdbc:h2:~/timetracker;AUTO_SERVER=TRUE;AUTO_RECONNECT=TRUE;DB_CLOSE_ON_EXIT=FALSE;DB_CLOSE_DELAY=-1
                        </connection-url>
                        <driver>h2</driver>
                        <security>
                            <user-name>sa</user-name>
                            <password>sa</password>
                        </security>
                    </datasource>
                        
    • We do not need to copy the h2-version.jar file to JBoss because H2 is already the default DBMS. You can also use the JBoss Admin console at http://localhost:8080/admin to create the datasource, but it is easier to simply edit the configuration file directly
  6. If using Tomcat7 for deployment testing:
    • Download Tomcat (current version 7.0.22) from http://tomcat.apache.org, unzip to a local directory, verify that bin\startup.bat or .sh starts the server properly. Shutdown.
    In tomcat conf\context.xml:
    <Context>
    ...
        <ResourceLink global="jdbc/timetracker" name="jdbc/timetracker" type="javax.sql.DataSource"/>
        <Resource
           name="TransactionSynchronizationRegistry"
           auth="Container"
           type="javax.transaction.TransactionSynchronizationRegistry"
           factory="org.objectweb.jotm.TransactionSynchronizationRegistryFactory"/>
        <Transaction factory="org.objectweb.jotm.UserTransactionFactory" jotm.timeout="60"/>
    
    In tomcat conf\server.xml:
      <GlobalNamingResources>
    ...
       <Resource name="jdbc/timetracker" auth="Container"
                 type="javax.sql.DataSource"
                 maxActive="4" maxIdle="2" maxWait="10000"
                 username="sa"  password="sa"
                 driverClassName="org.h2.Driver"
                 url="jdbc:h2:~/timetracker;AUTO_SERVER=TRUE;AUTO_RECONNECT=TRUE;DB_CLOSE_ON_EXIT=FALSE;DB_CLOSE_DELAY=-1"/>
    
    • Copy the h2-version.jar file from web\target\timetracker\version\WEB-INF\lib to Tomcat \lib. Copy jta.jar from http://java.sun.com/products/jta (or other jta provider) to the same directory.
    • There is a bug in JBoss6.1 and 7 where the standard datasource lookup java:comp/env fails during deployment. Tomcat (and every other app server) requires the java:comp/env/jdbc/timetracker format for JNDI datasource lookups. The bug is fixed in JBoss7.1. See https://issues.jboss.org/browse/AS7-2184. To workaround: Edit timetracker/pom.xml to change the property dataSource from java:/${dataSource.name} to
      <dataSource>java:comp/env/${dataSource.name}</dataSource>
      and clean/build timetracker again. Specifically this changes the output in the following files: core/src/main/resources/META-INF/persistence.xml jta-data-source, and core/src/main/resources/applicationContext-dataSource.xml
  7. Let's start the JBoss server so we can deploy the TimeTracker application to it. To do this, open a second Command Prompt in the JBoss bin directory ( C:\Programs\JBoss\7\bin) and execute the command standalone.sh or standalone.bat. JBoss should start up in about 5 seconds. Wait for a message similar to this to make sure JBoss has started successfully:
    17:57:19,981 INFO [org.jboss.as] (Controller Boot Thread) JBoss AS 7.0.2.Final "Arc" started in 2775ms - Started 97 of 152 services (55 services are passive or on-demand).
  8. Now we are ready to deploy the finished application to the JBoss server. Copy timetracker.war from web\target to Jboss standalone\deployments directory. The JBoss console displays several messages indicating that it is deploying the application. Wait for a message similar to this to make sure TimeTracker has started successfully:
    19:28:59,154 INFO [org.jboss.web] (MSC service thread 1-4) registering web context: /timetracker 19:28:59,237 INFO [org.jboss.as.server.controller] (DeploymentScanner-threads - 2) Deployed "timetracker.war"
  9. Now we are ready to test the application. Open a browser and make it point to http://localhost:8080/timetracker. (If you have changed the JBoss HTTP port, then replace 8080 with the appropriate port number.) The TimeTracker home page should appear with links to various sections of the application.
  10. Click onSearch Timecards. The search screen should appear. Try changing the search criteria and click the Search button. The Search Results panel should show appropriate results. Note that the remaining TimeTracker screens are under construction.
  11. When you are satisfied with the TimeTracker tour, you may stop the JBoss Server by typing Control-C in the JBoss Command Prompt.

Well, now that you have seen the TimeTracker application in action, are you ready to recreate it from scratch? I am hearing a resounding yes! Alright, click here to go ahead.