Enterprise Java Development@TOPIC@
Up until now we have kept our focus away from the IDE and onto the filesystem and Maven configurations to give better insight into the structure of a multi-module application and to show how IDE-agnostic the build process is. This will be very important when you check in your modules to be built/tested by a build server (e.g., CruiseControl, Hudson, or Jenkins). However, we want to speed up the process to do actual development. We want to spend as much of our time as possible within a development/test-bench that promotes the efficient development of Java code. The command-line builds will still be leveraged but all those copy/pastes/edits I asked you do would more than likely be created with the use of a Java/JavaEE-knowledgeable IDE. The examples in this section use Eclipse. Any other credible IDE (e.g., NetBeans, IntelliJ) should work in a similar manner and offer comparable functionality.
To derive properties for the InitialContext -- we used filtered property files.
#jndi.properties java.naming.factory.initial=${jboss.remoting.java.naming.factory.initial} java.naming.factory.url.pkgs=${jboss.ejbclient.java.naming.factory.url.pkgs} java.naming.provider.url=${jboss.remoting.java.naming.provider.url} #java.naming.security.principal=${jndi.user} #java.naming.security.credentials=${jndi.password} jboss.naming.client.ejb.context=true
That got expanded by out initial Maven build to contain the following. The Maven/Eclipse plugin (m2e) within Eclipse will continue to keep this up to date. It has a plugin the provides understanding of what the maven-resource-plugin would do outside of the IDE and re-creates that functionality within the IDE environment.
#jndi.properties java.naming.factory.initial=org.jboss.naming.remote.client.InitialContextFactory java.naming.factory.url.pkgs=org.jboss.ejb.client.naming java.naming.provider.url=http-remoting://localhost:8080 #java.naming.security.principal=known #java.naming.security.credentials=password1! jboss.naming.client.ejb.context=true
There is nothing magical about jndi.properties. We can add more properties to that file (not common) or create other property files (e.g., it.properties) to be filtered and made available to the IT test. However, our other option was to pass in a system property (-DpropertyName=value) using the failsafe configuration.
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<configuration>
<systemPropertyVariables>
<jndi.name.reservation>ejb:basicejb-ear/basicejb-ejb/ReservationEJB!org.myorg.basicejb.ejb.ReservationRemote</jndi.name.reservation>
</systemPropertyVariables>
</configuration>
</plugin>
Anticipating the system property might not always be available or necessary in 99-100% of the IT tests once we stablized some values, we started processing the system properties by deriving a reasonable default. This can be overriden but when not overriden it will work 99%-100% of the time as well.
private static final String reservationJNDI = System.getProperty("jndi.name.reservation",
"ejb:basicejb-ear/basicejb-ejb/ReservationEJB!"+ReservationRemote.class.getName());
Let's show this in action by loading our application into the IDE, deploying the EAR and WAR, and executing the IT tests from within Eclipse.
If you have not already done so, import your multi-module project into the IDE. For Eclipse that involves using Right-Click, Import Existing Maven Projects,
We made several incremental changes to the plugins as we built the end-to-end application. If you initially loaded the project prior to making many of these incremental changes Eclipse could have some issues upgrading the "facet" of a particular module on the fly. That was the case in my environment so I ...
Removed all modules from Eclipse
Deleted all .settings directories and .project and .classpath files
Re-imported the modules fresh and everything cleared with the "facet" JavaEE versions.
Right Click on a Working Group or Select File
Select "Import Existing Maven Projects"
Navigate to the root module
Click OK. Eclipse will show you a list of modules at and under the root module.
Select all modules in the tree. They should now show up in the various explorer tabs
Leverage existing Maven configuration to deploy the EAR and WAR artifacts to the server.
This can be done at the command line command line using techniques you are already familiar with.
$ mvn pre-integration-test
The Eclipse/Maven integration can also provide access to that functionality through a re-usable Maven Build Run Configuration.
Right Click on the Root Module and select "Run As"
Select "Maven build...". An "Edit Configuration" panel is displayed
Type or select the variable "${project_loc}" for Base directory
Select "Run" in the Display in favorites menu
Make a change to the ReservationIT to invoke ping() several times in a row in a for-loop.
@Test
public void testPing() throws NamingException {
logger.info("*** testPing ***");
for (int i=0; i<10; i++) {
reservationist.ping();
}
}
2014-10-11 23:42:19,474 DEBUG [org.myorg.basicejb.ejb.ReservationEJB] (EJB default - 8) *** ReservationEJB.init() *** 2014-10-11 23:42:19,475 DEBUG [org.myorg.basicejb.ejb.ReservationEJB] (EJB default - 8) ping called 2014-10-11 23:42:19,475 DEBUG [org.myorg.basicejb.ejb.ReservationEJB] (EJB default - 8) *** ReservationEJB.destroy() *** 2014-10-11 23:42:19,521 DEBUG [org.myorg.basicejb.ejb.ReservationEJB] (EJB default - 7) *** ReservationEJB.init() *** 2014-10-11 23:42:19,522 DEBUG [org.myorg.basicejb.ejb.ReservationEJB] (EJB default - 7) ping called 2014-10-11 23:42:19,522 DEBUG [org.myorg.basicejb.ejb.ReservationEJB] (EJB default - 7) *** ReservationEJB.destroy() *** ...
wildfly-8.1.0.Final/bin/standalone.conf JAVA_OPTS="$JAVA_OPTS -agentlib:jdwp=transport=dt_socket,address=8787,server=y,suspend=n"
wildfly-8.1.0.Final/bin/standalone.conf.bat set "JAVA_OPTS=%JAVA_OPTS% -agentlib:jdwp=transport=dt_socket,address=8787,server=y,suspend=n"
========================================================================= Listening for transport dt_socket at address: 8787 00:09:23,260 INFO [org.jboss.modules] (main) JBoss Modules version 1.3.3.Final
Attach a debugger client to the server using the following...