如何使Maven EAR插件自动管理依赖项的类路径?

Jam*_*mes 3 ear maven-plugin maven maven-ear-plugin

我大约12个月前开始使用maven ear插件,想知道是否有其他选择.Maven的一个好处是依赖管理,但你似乎几乎完全失去了耳塞.它将所有依赖的jar构建到耳朵中,但实际上不会将它们中的任何一个放在类路径上而不添加以下配置:

<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>
Run Code Online (Sandbox Code Playgroud)

我错过了一些更新版本的插件消除了对此的需求,是否有替代方案可以为您管理?我无法相信每次向模块添加依赖项时我需要将其添加到耳塞配置中.最令人沮丧的是,即使我记得在上面的配置中添加一个依赖库,如果它依赖于其他东西(就像轴的情况一样),我只是在部署耳朵时才发现.

khm*_*ise 5

首先,您应该为耳朵(当然还有耳朵)设置一个单独的模块,如下所示:

root
  +-- client
  !     +--- pom.xml
  +-- service
  !     +--- pom.xml
  +-- ear
        +--- pom.xml
Run Code Online (Sandbox Code Playgroud)

其次你应该更新ear插件的版本,因为当前版本是2.6.此外,将您的零件定义为依赖项

 <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>
Run Code Online (Sandbox Code Playgroud)

您正在使用的配置适用于应打包的补充第三方库.