Edd*_*_42 6 java eclipse jar maven
在执行 maven 构建时,我试图将许可证文件添加到我的所有 jar 中。我在每个类文件上都有许可证,但我希望将 License.txt 添加到每个 jar 中的每个 META-INF 文件夹
我的项目有一个主 pom,它有六个模块,然后这些模块有自己的模块,最终进入一个生成 /target/<.jar-file> 的项目。构建和类级别的许可证正在工作,我只是想将物理 License.txt 添加到 META-INF 文件夹中。
我的文件(相对于主 POM)存储在 /src/resources/src-license.txt 中。我真的需要自动化方法来确保如果/当许可证更改时,我不必更新 50 个文件,我可以只更新一个,然后将其复制到其他位置。
我试过使用
<build>
<sourceDirectory>src</sourceDirectory>
<resources>
<resource>
<directory>src/resources</directory>
<targetPath>/META-INF</targetPath>
<includes>
<include>src-license.txt</include>
</includes>
</resource>
</resources>
....
</build>
Run Code Online (Sandbox Code Playgroud)
但这似乎不起作用。我还尝试了一些输出路径的替代方法,例如 ${project.build.outputDirectory}/META-INF 或 */META_INF,也无济于事。有没有人有关于如何实现这一点的经验?谢谢
此外,我使用 maven-license-plugin 来确保每个类文件都粘贴了许可证信息,并且按预期运行。但同样,在类文件中,我在每个 <*.jar>/META-INF/ 中寻找外部 .txt 文件
使用父relativePath 中的资源至少很困难(如果您有复杂的目录结构怎么办?)。
一种简单而干净的方法是创建一个包含 src-license.txt 文件的单独模块。然后使其成为模块的依赖项并在目标/类内部的生成资源阶段解压缩它(依赖项:解包依赖项)。
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<id>unpack-license</id>
<phase>generate-resources</phase>
<goals><goal>unpack</goal></goals>
<configuration>
<artifactItems>
<artifactItem>
<groupId>com.acme</groupId>
<artifactId>com.acme.license</artifactId>
<version>${project.version}</version>
</artifactItem>
</artifactItems>
<outputDirectory>${project.build.outputDirectory}</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
5867 次 |
| 最近记录: |