使用maven-assembly-plugin
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.1</version>
<configuration>
<descriptors>
<descriptor>descriptor.xml</descriptor>
</descriptors>
<finalName>xxx-impl-${pom.version}</finalName>
<outputDirectory>target/assembly</outputDirectory>
<workDirectory>target/assembly/work</workDirectory>
</configuration>
在descriptor.xml文件中我们可以指定
<fileSets>
<fileSet>
<directory>src/install</directory>
<outputDirectory>/</outputDirectory>
</fileSet>
</fileSets>
是否可以根据个人资料包含此文件夹或子文件夹中的特定文件?或者其他一些方式...
像这样:
<profiles>
<profile>
<id>dev</id>
<activation>
<activeByDefault>false</activeByDefault>
</activation>
<build>
<resources>
<resource>
<directory>src/install/dev</directory>
<includes>
<include>**/*</include>
</includes>
</resource>
</resources>
</build>
</profile>
<profile>
<id>prod</id>
<build>
<resources>
<resource>
<directory>src/install/prod</directory>
<includes>
<include>**/*</include>
</includes>
</resource>
</resources>
</build>
</profile>
</profiles>
但它在包装时将资源放入罐子里。但是我们需要在组装时将其放入拉链中,如上所述:( 谢谢!
答案 0 :(得分:15)
如果您的资源有一个模式(比如说*.properties
),那么您可以在程序集描述符文件中执行类似的操作:
<fileSets>
<fileSet>
<directory>${project.build.directory}</directory>
<outputDirectory>/</outputDirectory>
<includes>
<include>*.properties</include>
</includes>
</fileSet>
</fileSets>
这会将*.properties
文件夹中的所有target
复制到程序集zip的根文件夹中。根据正在运行的pom.xml
中的个人资料,target
文件夹中只会显示相应的资源。
答案 1 :(得分:2)
将插件的执行放在标签构建内的每个配置文件中。
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<phase>grr</phase>
<goals>
<goal>tree</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>2.3.1</version>
<configuration>
<excludes>
<exclude>**/*.xml</exclude>
</excludes>
</configuration>
</plugin>
</plugins>
</build>
<profiles>
<profile>
<id>dev</id>
<activation>
<activeByDefault>false</activeByDefault>
</activation>
<build>
<plugins>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.1</version>
<configuration>
<descriptors>
<descriptor>descriptor.xml</descriptor>
</descriptors>
<finalName>xxx-impl-${pom.version}</finalName>
<outputDirectory>target/assembly</outputDirectory>
<workDirectory>target/assembly/work</workDirectory>
</configuration>
</plugin>
<resources>
<resource>
<directory>src/install/dev</directory>
<includes>
<include>**/*</include>
</includes>
</resource>
</resources>
</build>
</profile>
<profile>
<id>prod</id>
<build>
<resources>
<resource>
<directory>src/install/prod</directory>
<includes>
<include>**/*</include>
</includes>
</resource>
</resources>
</build>
</profile>
</profiles>