maven-war-plugin会忽略< archiveClasses> [英] maven-war-plugin ignores <archiveClasses>
问题描述
<archiveClasses>
选项具有没有效果.
The <archiveClasses>
option has no effect.
运行mvn clean compile war:exploded
会生成一个战争目录,其中在.c2>目录中具有.class文件,并且它们也都没有存档到lib
目录中的jar中. war:war
产生相同的结果.
Running mvn clean compile war:exploded
produces a war directory with .class files in the classes
directory, and they are not archived into a jar in the lib
directory neither. war:war
produces same result.
插件配置:
...
<plugin>
<artifactId>maven-war-plugin</artifactId>
<version>2.6</version>
<configuration>
<archiveClasses>true</archiveClasses>
</configuration>
</plugin>
...
解决方法?
Maven版本3.3.3,maven-war-plugin 2.6版本.
Maven version 3.3.3, maven-war-plugin version 2.6.
JIRA票证– https://issues.apache.org/jira/browse/MWAR -355
这是有问题的项目: https://bitbucket.org/dmos62/raudondvaris >
This is the project in question: https://bitbucket.org/dmos62/raudondvaris
推荐答案
第一件事是您应该将纯配置移到pluginManagement
The first thing is you should move the plain configuration into a pluginManagement
block like this:
<build>
<pluginManagement>
<plugins>
<plugin>
<artifactId>maven-war-plugin</artifactId>
<version>2.6</version>
<configuration>
<archiveClasses>true</archiveClasses>
</configuration>
</plugin>
</plugins>
</pluginManagement>
</build>
如果执行上述操作,则将使用以下命令在战争档案中创建这些类:mvn clean compile war:war
If you do the above the classes will be created within the war archive by using: mvn clean compile war:war
~/ws-git/so-questions/so-5 (master)$ unzip -t target/web-1.0.0-SNAPSHOT.war
Archive: target/web-1.0.0-SNAPSHOT.war
testing: META-INF/ OK
testing: META-INF/MANIFEST.MF OK
testing: WEB-INF/ OK
testing: WEB-INF/classes/ OK
testing: WEB-INF/lib/ OK
testing: WEB-INF/lib/commons-fileupload-1.1.1.jar OK
testing: WEB-INF/lib/commons-io-1.1.jar OK
testing: WEB-INF/lib/web-1.0.0-SNAPSHOT.jar OK
testing: WEB-INF/web.xml OK
testing: META-INF/maven/com.soebes.examples.so/web/pom.xml OK
testing: META-INF/maven/com.soebes.examples.so/web/pom.properties OK
testing: META-INF/INDEX.LIST OK
No errors detected in compressed data of target/web-1.0.0-SNAPSHOT.war.
这也将适用于您的呼叫mvn clean compile war:exploded
.
This will also working for your call mvn clean compile war:exploded
.
└── web-1.0.0-SNAPSHOT
├── META-INF
└── WEB-INF
├── classes
├── lib
│ ├── commons-fileupload-1.1.1.jar
│ ├── commons-io-1.1.jar
│ └── web-1.0.0-SNAPSHOT.jar
└── web.xml
此行为的原因仅是由于使用诸如war:war
或war:exploded
之类的目标而导致的,因此不会启动生命周期,这意味着未考虑pom中的配置.如果您希望对命令行调用进行配置,可以通过对命令行调用使用特殊的配置来做到这一点(id default-cli
是重要部分):
The reason for this behaviour is simply cause by using a goal like war:war
, or war:exploded
there will be no life cycle started which means the configuration in the pom is not taken into account. If you like having a configuration for your command line calls you can do this by using a special configuration for command line calls like this (The id default-cli
is the important part):
<project>
<build>
<plugins>
<plugin>
<groupId...>
<artifactId...>
<executions>
<execution>
<id>default-cli</id>
<configuration>
.....
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
这意味着对命令行调用具有特殊的配置.从Maven 3.3.1开始,可以通过以下方式使用多个配置来进行命令行调用:
which means having a special configuration for command line calls. Starting with Maven 3.3.1 it is possible having more than one configuration for command line calls by using it like:
<project...>
<build>
<plugins>
<plugin>
<groupId>...</groupId>
<artifactId>...</artifactId>
<executions>
<execution>
<id>first-cli</id>
<configuration>
....
</configuration>
</execution>
<execution>
<id>second-cli</id>
<configuration>
....
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
maven可以通过以下方式使用它:
This can be used by maven via the following:
mvn plugin:goal@second-cli
mvn plugin:goal@first-cli
另请参见 Maven 3.3.1的发行说明..
这篇关于maven-war-plugin会忽略< archiveClasses>的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!