views:

293

answers:

1

Hi,

I'm trying to create an eclipse project from scratch using m2eclipse plugin to help resolving dependencies.

The project consists of the following modules:

test-ear test-ejb test-war

The ear references both other projects, and pom files are ready and working in each project.

Still I have one situation:

Instead of just maven building my project, I want to be able to export the ear from eclipse and have a working project, so I could be able to hot-deploy it in a server.

But I have one problem ... the ejb uses an external jar (jbpm), the dependency is correctly specified in pom, and it appears in the "Maven Dependencies" user lib definition, and I have no compilation errors.

But to successfully export the EAR, I have to add the jar (jbpm) to the ejb manifest file. Going to project properties "Java EE Module Dependencies" I only have the entry "Maven Dependencies" lib, and selecting it will not add any info to the manifest file.

After that, exporting the EAR will show the dependency jar files in EAR root, but opening the included EJB shows that the manifest has no classpath entry at all.

Deploying the EAR then fails with info about a ClassNotFoundException in the EJB, on a class that is inside the dependency jar.

To bypass this, I can include the jar into the EAR module (project->properties->Java EE Module Dependencies), then I can add it in the EJB, and the manifest file is updated accordingly.

But the project will have tons of jars, and I don't want to include them all by hand in the EAR and then pick them all in each project.

I know that those entries are in .settings/org.eclipse.wst.common.component file, but shouldn't maven plugin update it automatically in EAR project? At least on the Java EE Module Dependency, so I could just check the jars on each sub-project (ejb, war, ...)

Thanks

A: 

If I understand you correctly you want to package all 3rd party libs that are used by your EJBs in the resulting EAR file. If your EAR project has the packaging-type ear and the dependencies to your EJB modules are specified correctly with type ejb those 3rd party libs should be automagically included in the resulting EAR file. You can also specify a custom lib directory inside the EAR.

Example:

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"&gt;

    <modelVersion>4.0.0</modelVersion>

    <groupId>yourGroup</groupId>
    <artifactId>test-ear</artifactId>
    <version>1.0.0-SNAPSHOT</version>
    <!-- We want the resulting artifact to be an .ear file -->
    <packaging>ear</packaging>

    <dependencies>
        <!-- Internal dependencies -->
        <dependency>
            <groupId>yourGrup</groupId>
            <artifactId>test-ejb</artifactId>
            <version>1.0.0-SNAPSHOT</version>
            <!-- We have an ejb dependency here - take care of it! -->
            <type>ejb</type>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <artifactId>maven-ear-plugin</artifactId>
                <configuration>
                    <version>5</version>
                    <!-- put all 3rd party libs into the lib directory -->
                    <defaultLibBundleDir>lib</defaultLibBundleDir>
                </configuration>
            </plugin>
        </plugins>
    </build>

</project>

So this should not have anything with m2e imo. You might have to update the project configuration in Eclipse.

Roland Schneider