【问题标题】:Maven unpack war in destination folder [duplicate]Maven在目标文件夹中解压战争[重复]
【发布时间】:2018-06-05 14:37:01
【问题描述】:

我使用 Maven 创建我的 JEE 应用程序的 WAR。

这里是我的 pom.xml

<finalName>myproject</finalName>
<sourceDirectory>${basedir}/src</sourceDirectory>
<plugins>
  <plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-war-plugin</artifactId>
    <version>2.5</version>
    <configuration>
        <warSourceDirectory>WebContent</warSourceDirectory>
        <failOnMissingWebXml>false</failOnMissingWebXml>
        <outputDirectory>/var/www/myproject/webapp</outputDirectory>
    </configuration>    
  </plugin>

  <plugin>
     <inherited>true</inherited>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-compiler-plugin</artifactId>
    <version>3.2</version>
    <configuration>
      <source>1.8</source>
      <target>1.8</target>
    </configuration>
  </plugin>
</plugins> 

生成的 WAR 被复制到 pom.xml (/var/www/myproject/webapp) 中定义的输出文件夹中,但是我想在启动我的服务器 (Tomcat) 之前解压它。

我该怎么办?

谢谢, 洛伦佐

【问题讨论】:

  • 你为什么要打开它? Tomcat 可以处理 .war 文件
  • 因为我是“硬”开发阶段,我想检查战争是否包含所有需要的文件。
  • 您的&lt;sourceDirectory&gt;${basedir}/src&lt;/sourceDirectory&gt;&lt;warSourceDirectory&gt;WebContent&lt;/warSourceDirectory&gt; 保证了很多痛苦和头痛=/。为什么不使用 Maven 的约定?
  • 你有什么建议?最好的做法是什么?我是 Maven 新手。
  • 你的 Java 源文件应该在 src/main/java 下,战争源应该在 src/main/webapp 下。另见maven.apache.org/guides/introduction/…

标签: java maven tomcat


【解决方案1】:

如果你想解开战争,你可以使用 ma​​ven 汇编插件。例如:

 <plugin>
     <groupId>org.apache.maven.plugins</groupId>
     <artifactId>maven-dependency-plugin</artifactId>
     <version>2.10</version>
     <executions>
       <execution>
         <id>unpack</id>
         <phase>package</phase>
         <goals>
           <goal>unpack</goal>
         </goals>
         <configuration>
           <artifactItems>
             <artifactItem>
               <groupId>your group id</groupId>
               <artifactId>your artifact id</artifactId>
               <version> your version</version>
               <type>war</type>
               <overWrite>false</overWrite>
               <outputDirectory>${project.build.directory}/alternateLocation</outputDirectory>
               <destFileName>some name</destFileName>
               <includes>**/*.class,**/*.xml</includes>
               <excludes>**/*test.class</excludes>
             </artifactItem>
       </artifactItems>
       <includes>**/*.java</includes>
       <excludes>**/*.properties</excludes>
       <outputDirectory>your location</outputDirectory>
       <overWriteReleases>false</overWriteReleases>
       <overWriteSnapshots>true</overWriteSnapshots>
     </configuration>
   </execution>
 </executions>

您可以阅读https://maven.apache.org/plugins/maven-dependency-plugin/examples/unpacking-artifacts.html了解更多详情。

【讨论】:

    【解决方案2】:

    你可以使用maven目标war:exploded

    你可以看到这个question

    【讨论】:

      猜你喜欢
      • 2015-02-18
      • 1970-01-01
      • 1970-01-01
      • 2014-04-07
      • 1970-01-01
      • 2012-12-31
      • 1970-01-01
      • 1970-01-01
      • 2012-03-29
      相关资源
      最近更新 更多