gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-30 06:30:47 25 4
gpt4 key购买 nike

我的要求是构建一个包含 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com