Maven - 使用所有依赖的 jar 构建 .ear 文件

Maven - Build .ear file with all dependent jars

我正在使用 Maven 构建一个 javaear 文件。当我们将ear部署到Weblogic时,我们得到了以下异常,这让我想到需要将依赖项添加到ear文件中(由maven打包到ear中):

<Feb 2, 2015 3:20:30 PM EST> <Error> <HTTP> <BEA-101371> <There was a failure when processing annotations for application /6v09bd/Develapp-0.1.war. Please make sure that the annotations are valid. The error is javax.faces.webapp.FacesServlet>
<Feb 2, 2015 3:20:30 PM EST> <Error> <Deployer> <BEA-149265> <Failure occurred in the execution of deployment request with ID '1422908423000' for task '18'. Error is: 'weblogic.application.ModuleException: Failed to load webapp: '/Develapp''
weblogic.application.ModuleException: Failed to load webapp: '/Develapp'
        at weblogic.servlet.internal.WebAppModule.prepare(WebAppModule.java:395)
        at weblogic.application.internal.flow.ScopedModuleDriver.prepare(ScopedModuleDriver.java:176)
        at weblogic.application.internal.flow.ModuleListenerInvoker.prepare(ModuleListenerInvoker.java:199)
        at weblogic.application.internal.flow.DeploymentCallbackFlow.next(DeploymentCallbackFlow.java:517)
        at weblogic.application.utils.StateMachineDriver.nextState(StateMachineDriver.java:52)
        Truncated. see log file for complete stacktrace
Caused By: java.lang.ClassNotFoundException: javax.faces.webapp.FacesServlet
        at weblogic.utils.classloaders.GenericClassLoader.findLocalClass(GenericClassLoader.java:297)
        at weblogic.utils.classloaders.GenericClassLoader.findClass(GenericClassLoader.java:270)
        at weblogic.utils.classloaders.ChangeAwareClassLoader.findClass(ChangeAwareClassLoader.java:64)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
        Truncated. see log file for complete stacktrace

根据 this SO solution,我尝试添加 maven 插件 "jar-with-dependencies"。但是我得到了插件的下载错误,maven 不会编译 pom.xml。而且我不确定这个插件是否真的适用于 ear 文件。

基本上,我需要知道如何将 war 的所有依赖项放入其中,以便 Weblogic 满意,如果这有意义的话。

我猜你没有使用 maven-war-plugin 来构建你的 war.. 因为这个插件可以满足你的要求.. 它复制了你的 war依赖于 lib 文件夹。

请记住,不会复制提供的范围依赖项。

插件文档:http://maven.apache.org/plugins/maven-war-plugin/

您的 war/pom.xml

中需要有这样的内容
<build>
  <finalName>${project.artifactId}</finalName>
  <plugins>
    <plugin>
      <groupId>org.apache.maven.plugins</groupId>
      <artifactId>maven-compiler-plugin</artifactId>
      <configuration>
        <source>1.7</source>
        <target>1.7</target>
      </configuration>
    </plugin>
    <plugin>
      <groupId>org.apache.maven.plugins</groupId>
      <artifactId>maven-war-plugin</artifactId>
      <configuration>
        <filteringDeploymentDescriptors>true</filteringDeploymentDescriptors>
      </configuration>
    </plugin>
  </plugins>
</build>

并且不要忘记 ear/pom.xml

 <build>
   <plugins>
      <plugin>
         <groupId>org.apache.maven.plugins</groupId>
         <artifactId>maven-ear-plugin</artifactId>
         <configuration>
            <modules>
               <webModule>
                  <moduleId>YOURService</moduleId>
                  <groupId>YOURGroupId</groupId>
                  <artifactId>YOURArtifactId</artifactId>
                  <contextRoot>/DevelApp</contextRoot>
               </webModule>
            </modules>
            <defaultLibBundleDir>APP-INF/lib</defaultLibBundleDir>
            <skinnyWars>true</skinnyWars>
         </configuration>
      </plugin>            
   </plugins>
</build>

如果您有一些特殊的 类,想要强制执行到网络应用程序中,您可以随时使用此插件:

<plugin>
   <groupId>org.apache.maven.plugins</groupId>
   <artifactId>maven-dependency-plugin</artifactId>
   <executions>
      <execution>
         <id>unpack-my-dependencies</id>
         <phase>process-resources</phase>
         <goals>
            <goal>unpack</goal>
         </goals>
         <configuration>
            <artifactItems>
               <artifactItem>
                  <groupId>another.groupId</groupId>
                  <artifactId>another.artifactId</artifactId>
                  <version>another.version</version>
                  <type>jar</type>
                  <overWrite>true</overWrite>
               </artifactItem>
            </artifactItems>
            <outputDirectory>${project.build.directory}/${project.artifactId}-${project.version}/APP-INF/classes
            </outputDirectory>
            <overWriteReleases>true</overWriteReleases>
            <includes>**/*.class</includes>
         </configuration>
      </execution>
   </executions>
</plugin>

您始终可以将依赖项传递给您的 war,只需将其标记为 <scope>runtime</scope>(参见:maven dependency scope