Search code examples
javaeclipsemavenjbossm2e

Deploy Maven artifacts to <container>/shared/lib for Eclipse debugging?


I'm working with some very old, monolithic software that is basically a heavily customized JBoss deployment. Unfortunately, this means that JBoss can't be started from the "Servers" view in Eclipse, it must be started as a Windows service or via the command line. There are multiple WARs/EARs, but the WAR classloaders are rarely used and most of the actual class files are located in jboss/shared/lib as .jars.

We need a way to run a Maven build in Eclipse (via m2e) and deploy the class files in the resulting .jar to C:/product/jboss/shared/lib so that when we start JBoss, we can use Eclipse to debug (as a remote java application). Ideally, the artifact that Maven pushes will not overwrite the existing .jar file that was originally installed. For example, if the Maven project builds an artifact named myjar-1.0.0.jar, we need a way to deploy the classes inside of myjar-1.0.0.jar to C:/product/jboss/shared/lib/classes so that they are picked up by the classloader prior to C:/product/jboss/shared/lib/myjar-1.0.0.jar, which was installed with the product.

Currently, our (very hacky) solution is this:

  1. Under the project configuration's Java Build Path > Source tab, we use the "symlink" functionality under Advanced to map the Default Output Directory (e.g. project/target/classes) to a class folder (e.g. C:/product/jboss/shared/lib/classFolder). This modifies the .project file, which is checked into source control.

    symlink madness

  2. We build the project normally with a m2e launcher (e.g. clean install).
  3. Assuming the Maven build is successful, we run an Eclipse project build. This pushes the class files to C:/product/jboss/shared/lib/classFolder:

    classFolder

  4. We restart JBoss. Since classFolders take precedence over jars, JBoss will load the classes in C:/product/jboss/shared/lib/classFolder, which are identical to the classes in our Eclipse workspace.
  5. We attach to JBoss and debug the project as a remote java application.

Pros:

  • We're able to push our new classes to JBoss and test them without backing up the original jars and copy/pasting the new ones by hand (jar hell).

Cons:

  • We're compiling twice -- once with the maven-compiler-plugin, and once with an Eclipse project build (Java Builder).
  • The symlink functionality is hit or miss in my experience. Sometimes we need to do the refresh project/close project/build project dance to get it to work.

Is there a better way to do this? I cannot force them to restructure the project so heavily that all deployables are container-agnostic WARs, but our developers need to be able to make changes and quickly test them without manually copy/pasting .jars.


Solution

  • How old is old?

    Have you looked at the Cargo plugin? http://cargo.codehaus.org/Quick+start

    It can deploy to JBoss 3.x. It has a Java API so you should be able to write something to extend it to do what you want.

    Why are you trying to deploying classes instead of jar files? You can still remote debug via Eclipse with jar files.

    Worst case scenario - use Ant. Maven is not designed for this kind of stuff, trying to force it to work will just cause you pain.
    Once you have got Maven generated the right artifacts, work out what you would do manually and then script it via Ant.