java - 如何使用 Maven 程序集插件将 war 捆绑到 package/.zip 中

标签 java maven

我的要求是构建一个包含 test.war 和 test.properties 的包(test.zip 文件)。

pom.xml

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
  <modelVersion>4.0.0</modelVersion>

  <groupId>com.karthik</groupId>
  <artifactId>test</artifactId>
  <packaging>war</packaging>
  <version>0.0.1-SNAPSHOT</version>

  <dependencies>
    <dependency>
        <groupId>junit</groupId>
        <artifactId>junit</artifactId>
        <version>3.8.1</version>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>org.apache.struts</groupId>
        <artifactId>struts2-core</artifactId>
        <version>2.3.32</version>
    </dependency>
  </dependencies>
 <build>
    <finalName>test</finalName>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>3.6.2</version>
            <configuration>
                <source>1.8</source>
                <target>1.8</target>
            </configuration>
        </plugin>
        <plugin>
                <artifactId>maven-assembly-plugin</artifactId>
                <executions>
                    <execution>
                        <id>make-bundles</id>
                        <goals>
                            <goal>single</goal>
                        </goals>
                        <phase>package</phase>
                        <configuration>
                            <descriptors>
                                <descriptor>test-assembly.xml</descriptor>
                            </descriptors>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
    </plugins>
  </build> 

测试.Assembly.xml

 <assembly
    xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2 http://maven.apache.org/xsd/assembly-1.1.2.xsd">
    <formats>
        <format>zip</format>
    </formats>
    <id>test</id>
    <includeBaseDirectory>false</includeBaseDirectory>
    <files>
        <file><outputDirectory>.</outputDirectory><source>test.properties</source></file>
        <file><outputDirectory>.</outputDirectory><source>test.war</source></file>
    </files>
</assembly>  

当我运行 mvn package 或 mvn assembly: assembly 时,出现以下错误:

[INFO] Reading assembly descriptor: test-assembly.xml
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 9.116s
[INFO] Finished at: Tue Sep 12 08:28:58 EDT 2017
[INFO] Final Memory: 36M/355M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-assembly-plugin:2.6:single (make-bundles) on project test: Failed to create assembly: Error adding file to archive: C:\DEV\eclipse-jee-luna-SR2-win32-x86_64\MavenWorkspace\***\test.war -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException

test.war 已成功构建,但未捆绑到 test.zip
是什么导致了这个错误?如何将 test.war 打包到 test.zip 中?

最佳答案

像这样的事情应该可以解决问题:

<assembly>
...
<files>
 <file>
  <source>target/${artifactId}.${packaging}</source
  <outputDirectory>war</outputDirectory>
  <destName>${artifactId}.${packaging}</destName>
 </file>
</files>

关于java - 如何使用 Maven 程序集插件将 war 捆绑到 package/.zip 中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46176682/

相关文章:

java - jenkins在这个环境下没有提供编译器

maven - 为什么 Maven 的依赖调解不选择最新版本?

ftp 服务器上的 Java Applet 需要几分钟才能连接到 MySQL 数据库

java - Hadoop上出现UnsupportedClassVersionError,版本没有明显变化

java - 如何在groovy中编写通用的数据库实用程序类?

java - 将选定的文件复制到项目目录

java - mvn执行:java fails with FileNotFoundException

maven - Weblogic Maven 部署

java - 所有不带参数的方法都可以访问变量吗?

java - 将列表添加到另一个 Arraylist 会清除输出