简体   繁体   中英

How to make the Maven EAR Plugin automatically manage the classpath for dependencies?

I started using the maven ear plugin about 12 months ago and want to find out if there are any alternatives. One of the benefits of Maven is the dependency management however you seem to almost completely lost this with the ear plugin. It builds all the dependant jar's into the ear but won't actually put any of them on the classpath with out adding the configuration below:

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-ear-plugin</artifactId>
    <version>2.4</version>
    <configuration>
        <version>6</version>
        <modules>
            <ejbModule>
                <groupId>com.mycompany.app</groupId>
                <artifactId>MyApplication-ejb</artifactId>                          
            </ejbModule>

            <jarModule>
                <groupId>axis</groupId>
                <artifactId>axis</artifactId>
                <bundleDir>lib</bundleDir>
            </jarModule>
            <jarModule>
                <groupId>commons-discovery</groupId>
                <artifactId>commons-discovery</artifactId>
                <bundleDir>lib</bundleDir>
            </jarModule>
            <jarModule>
                <groupId>axis</groupId>
                <artifactId>axis-wsdl4j</artifactId>
                <bundleDir>lib</bundleDir>
            </jarModule>
        </modules>
    </configuration>
</plugin>

Am I missing something does a more recent version of the plugin eliminate the need for this, is there an alternative that manages this for you? I can't believe each time I add a dependency to a module I need to add it to the ear pom configuration. The most frustrating thing is even if I remember to add a dependant library to the above configuration, if that is in turn dependent on something else (as was the case with axis) I am only finding out when I deploy the ear.

First you should have a separate module for the ear (and of course ear ) which looks like the following:

root
  +-- client
  !     +--- pom.xml
  +-- service
  !     +--- pom.xml
  +-- ear
        +--- pom.xml

Second you should update the version of the ear plugin, cause the current version is 2.6. Furthermore define your parts as dependencies

 <build>
    <plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-ear-plugin</artifactId>
        <version>2.5</version>
      </plugin>
    </plugins>
  </build>

  <dependencies>
    <dependency>
      <groupId>${project.groupId}</groupId>
      <artifactId>webgui</artifactId>
      <version>${project.version}</version>
      <type>war</type>
    </dependency>
    <dependency>
      <groupId>${project.groupId}</groupId>
      <artifactId>service</artifactId>
      <version>${project.version}</version>
      <type>ejb</type>
    </dependency>
  </dependencies>

The configuration you are using is intended for supplemental 3rd party libs which should be packaged.

In addition to the answer of khmarbaise I want to note that in order for your EJB Module to be able to access the libraries you have to configure it to include the dependencies inside the META-INF/MANIFEST.MF like this:

<plugin>
    <artifactId>maven-ejb-plugin</artifactId>
    ...
    <configuration>
        ...
        <archive>
            <manifest>
                <addClasspath>true</addClasspath>
            </manifest>
        </archive>
    </configuration>
    ...
</plugin>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM