Gerhard Schlager
Gerhard Schlager

Reputation: 3145

Transitive project dependencies in Eclipse WTP

I've created a bunch of projects in Eclipse 3.7.2. Let's give some of them a name:

Project A depends on project B, so B is in A's build path. Project W depends on project A so I've added A as Deployment Assembly in W.

When I export a WAR from within Eclipse only the JAR file for A gets added to WEB-INF/lib. Eclipse shows the following warning:

Classpath entry /B will not be exported or published. Runtime ClassNotFoundExceptions may result.

The warning is correct. I get a ClassNotFoundExceptions at runtime. Of course Eclipse provides a Quick fix for the warning which is "Mark the associated raw classpath entry as publish/export dependency". However, this doesn't fix my problem. B still doesn't get deployed with W.

I tried manually adding B as Deployment Assembly in A . That includes the B.jar within A.jar which isn't really what I want and I still get the ClassNotFoundExceptions.

The only thing that works is manually adding B as Deployment Assembly in W. Eclipse still shows the warning from above, but the runtime exceptions are gone.

Am I missing something or is this really the only way to get this working?

Upvotes: 4

Views: 1478

Answers (1)

Eugene Kuleshov
Eugene Kuleshov

Reputation: 31795

In order to make Eclipse's "Export / Web / WAR File" work, you have to make your project "b" to appear in the "Web App Libraries" container.

You can edit deployment configuration using Deployment Assembly page in the project properties and add your project "b" in there:

deployment assembly

Alternatively, you can open configuration file at /w/.settings/org.eclipse.wst.common.component and add reference to project "b" manually:

<?xml version="1.0" encoding="UTF-8"?>
<project-modules id="moduleCoreId" project-version="1.5.0">
    <wb-module deploy-name="w">
        <wb-resource deploy-path="/" source-path="/WebContent" tag="defaultRootSource"/>
        <wb-resource deploy-path="/WEB-INF/classes" source-path="/src"/>
        <dependent-module archiveName="a.jar" deploy-path="/WEB-INF/lib" handle="module:/resource/a/a">
            <dependency-type>uses</dependency-type>
        </dependent-module>
        <dependent-module archiveName="b.jar" deploy-path="/WEB-INF/lib" handle="module:/resource/b/b">
            <dependency-type>uses</dependency-type>
        </dependent-module>
        <property name="context-root" value="w"/>
        <property name="java-output-path" value="/w/build/classes"/>
    </wb-module>
</project-modules>

Once it is done, you'll see project "b" in the "Web App Libraries" classpath container and export to WAR file will also add b.jar into WEB-INF/lib.

Upvotes: 4

Related Questions