Background: I am deploying a dynamic web project to JBoss AS 7.1.1 using Eclipse 4.2 with JBoss Tools 3.3.0 Final. My project's build path includes the JRE System Library, JBoss 7.1 Runtime, and Web App Libraries (the WEB-INF/lib folder). I also have a jboss-deployment-structure.xml file that defines additional module dependencies such as the following:
<jboss-deployment-structure> <deployment> <dependencies> <module name="org.slf4j" /> <module name="org.apache.log4j" /> </dependencies> </deployment> </jboss-deployment-structure>
The problem is, the slf4j and log4j modules are not included in the project's build path. While the server resolves them correctly at runtime because of the jboss-deployment-structure.xml file, Eclipse doesn't include them. So the following declaration in the Java code would result in a build error because org.apache.log4j cannot be resolved to a type:
private static final org.apache.log4j.Logger log = org.apache.log4j.Logger.getLogger(Example.class);
The JBoss runtime that the project is using is configured correctly. It points to a valid JBoss directory, and the module dependencies are properly installed in the server.
So, is there a way to automatically add the jboss-deployment-structure module dependencies to the Eclipse build path? So far, I've been unable to find a way to do this.
I have found a few workarounds, but none of them are ideal, and they seem to completely miss the point of module-based dependencies:
- Customize the Default Classpath Entries for the server runtime. This is not acceptable because it must be done in each developer's workspace – and possibly per project since projects may have different, conflicting dependencies.
Add the libraries to WEB-INF/lib. This is not acceptable because it defeats the purpose of server modules.
- Add the libraries to a user library for the project. This could work, but it's very inconvenient, because each developer on the team would have to add the jars to the user libraries in their workspaces.
Have I missed a solution to this problem that JBoss Tools already provides? Or, does anyone have any other ideas?
Thanks in advance,
#1 is the only eclipse-only way.
To do better from eclipse we need better integration of JBoss Modules understanding into how eclipse runtimes define their classpath - that is a not available yet today.
Alternatively you can fix this by using maven which have a notion of scope="provided" that let you refer to it but not have it included in the build.