Java 如何使用 maven 将 Class-Path 添加到清单文件
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/23688063/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to add Class-Path to the manifest file with maven
提问by JavaSheriff
When using the maven-jar-plugin
I would like to add entry to the Manifest.mf
So it will contain:
Class-Path: .
When i add this entry to the Pom:
使用 maven-jar-plugin 时,
我想向 Manifest.mf 添加条目,
因此它将包含:
Class-Path: 。
当我将此条目添加到 Pom 时:
<Class-Path>.</Class-Path>
It will create Class-Path with all dependency
Like:
Class-Path: . jar1name.jar jar2name.jar etc
Instead of just
Class-Path: .
Is there a way to avoid maven from adding all jar names to the Class-Path?
Thanks
它将创建具有所有依赖项的 Class-Path,例如
:
Class-Path: 。jar1name.jar jar2name.jar etc
而不仅仅是
Class-Path: 。
有没有办法避免 Maven 将所有 jar 名称添加到类路径?
谢谢
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<configuration>
<archive>
<manifest>
<addClasspath>true</addClasspath>
</manifest>
<manifestEntries>
<Built-By>Me</Built-By>
<Class-Path>.</Class-Path>
</manifestEntries>
</archive>
</configuration>
</plugin>
采纳答案by JavaSheriff
This did the trick
Omitting the addClasspath and adding manifestEntries
Now, log4j.properties can reside outside the jar - and still be found...
这做到了
省略 addClasspath 并添加 manifestEntries
现在,log4j.properties 可以驻留在 jar 之外 - 仍然可以找到......
<manifest>
<addClasspath>true</addClasspath>
</manifest>
This is working:
这是有效的:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<configuration>
<archive>
<manifestEntries>
<Built-By>Me</Built-By>
<Class-Path>.</Class-Path>
</manifestEntries>
</archive>
</configuration>
</plugin>
Output:
输出:
Manifest-Version: 1.0
Archiver-Version: Plexus Archiver
Created-By: Apache Maven
Build-Jdk: 1.6.0_45
Built-By: Me
Class-Path: .