问题描述
嗨,我有以下项目树:
src/
main
└── java
└── com
└── ...
└── assembly
└── main-assembly.xml
└── test
├── resources
│ └── config.properties
│ └── log4j.properties
│
└── java
└── com
└── development
└── feature
└── Sample.java
我的目标是通过“mvn package”生成一个包含以下内容的 zip 文件:
- 示例.java
- config.properties
- log4j.properties
我发现这样做的唯一方法是在我的项目 pom.xml 中如下所示:
...
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<appendAssemblyId>false</appendAssemblyId>
</configuration>
<executions>
<execution>
<id>samplezip</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
<configuration>
<descriptors>
<descriptor>src/assembly/main-assembly.xml</descriptor>
</descriptors>
</configuration>
</execution>
</executions>
</plugin>
...
在 main-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">
<id>sample</id>
<formats>
<format>zip</format>
</formats>
<includeBaseDirectory>false</includeBaseDirectory>
<fileSets>
<fileSet>
<directory>src/test</directory>
<outputDirectory>/sample</outputDirectory>
</fileSet>
</fileSets>
</assembly>
请注意,我必须将 main-assembly.xml 文件放在 test 文件夹之外的 assembly 文件夹中,否则我的结果 zip 文件中会有 main-assembly.xml 文件。
sample/
└── java
└── com
└── development
└── feature
└── Sample.java
└── resources
└── config.properties
└── log4j.properties
但我宁愿有这样的东西:
sample/
└── java
└── Sample.java
└── resources
└── config.properties
└── log4j.properties
或者至少有:
sample/
└── Sample.java
└── config.properties
└── log4j.properties
因此,maven 程序集有没有办法在输入目录范围内拥有多个目录(它们不在同一个关闭的父目录中) 并将所有输入元素放在同一个 outputDirectory 中?
事实上,我希望能够写出类似的东西(即使我知道在 main-assembly.xml 中使用 maven 是不正确的):
<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">
<id>sample</id>
<formats>
<format>zip</format>
</formats>
<includeBaseDirectory>false</includeBaseDirectory>
<fileSets>
<fileSet>
<directory>src/test/java/com/development/feature/Sample.java;src/test/resource</directory>
<outputDirectory>/sample</outputDirectory>
</fileSet>
</fileSets>
</assembly>
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)