【问题标题】:Maven - Build .ear file with all dependent jarsMaven - 使用所有依赖的 jar 构建 .ear 文件
【发布时间】:2015-02-12 21:39:46
【问题描述】:

我正在使用 Maven 构建一个 java ear 文件。当我们将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$1.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。而且我不确定这个插件是否真的适用于耳朵文件。

基本上,我需要知道如何将战争的所有依赖项纳入其中,以便 Weblogic 对耳朵感到满意,如果这有意义的话。

【问题讨论】:

    标签: java maven jar dependencies ear


    【解决方案1】:

    我猜你没有使用 maven-war-plugin 来构建你的战争。因为这个插件可以满足你的要求。它会将你的战争依赖项复制到 lib 文件夹中。

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

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

    【讨论】:

      【解决方案2】:

      你需要在你的 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>
      

      您总是可以将依赖项传递给您的战争,只需用&lt;scope&gt;runtime&lt;/scope&gt; 标记它(请参阅:maven dependency scope

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2018-01-20
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2013-07-07
        相关资源
        最近更新 更多