我正在尝试通过使用配置文件从Maven战争版本中排除一些文件,只是想不通。
我在pom.xml中创建了两个配置文件,为每个配置文件创建了eclipse运行配置,并且可以分别调用它们。但是无论我如何尝试,生成的版本都具有eclipse项目中的所有文件。
我已将其简化为A和B,配置文件A是“默认”配置文件。
<profile>
<id>profile-a</id>
<build>
<finalName>builda</finalName>
<plugins>
<plugin>
<artifactId>cloud</artifactId>
<version>11.0.3</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
<classifier>profile-a</classifier>
<includes>
<include>**/*</include>
</includes>
</configuration>
</plugin>
</plugins>
</build>
</profile>
配置文件B是我要删除一些文件的文件,并且尝试了各种方式,并将其减少为不包含任何文件,并且还显示了所有可能的排除方法。
<profile>
<id>profile-B</id>
<build>
<finalName>buildb</finalName>
<plugins>
<plugin>
<artifactId>cloud</artifactId>
<version>11.0.3</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
<classifier>cloud-service</classifier>
<excludes>
<exclude>**/*.txt</exclude>
</excludes>
<packagingExcludes>**/*.txt</packagingExcludes>
<warSourceExcludes>**/*.txt</warSourceExcludes>
</configuration>
</plugin>
</plugins>
</build>
</profile>
但是builda.war和buildb.war都是相同的-我将war文件与Beyond Compare进行了比较,唯一的区别是清单中的时间戳。我还尝试删除.jar文件,只是看它是否与.txt文件有关,但没有任何区别。
因此,我认为构建信息来自我的eclipse项目,而不是pom.xml。还是我完全想念某些东西-我仍然是新手,所以这完全有可能。
但是如何完成呢?
答案 0 :(得分:1)
首先,我觉得我应该指出,您提供的POM似乎存在多个问题。我认为您应该花一些时间来阅读Maven POM Reference,Maven Build Lifecycle和相关文档。
根据您提供的内容,我认为您正在尝试根据构建期间处于活动状态的概要文件将分类器添加到工件中。我保留了此功能并尽我所能纠正了POM的其他方面,但是我做了一些假设。
这是经过修改的POM:
<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/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>web.example</groupId>
<artifactId>exampleWar</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>war</packaging>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.0</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
</plugins>
</build>
<profiles>
<profile>
<id>profile-a</id>
<build>
<plugins>
<plugin>
<artifactId>maven-war-plugin</artifactId>
<version>3.2.2</version>
<configuration>
<classifier>profile-a</classifier>
</configuration>
</plugin>
</plugins>
</build>
</profile>
<profile>
<id>profile-b</id>
<build>
<plugins>
<plugin>
<artifactId>maven-war-plugin</artifactId>
<version>3.2.2</version>
<configuration>
<classifier>profile-b</classifier>
<packagingExcludes>%regex[.*\.txt]</packagingExcludes>
<warSourceExcludes>%regex[.*\.txt]</warSourceExcludes>
</configuration>
</plugin>
</plugins>
</build>
</profile>
</profiles>
</project>