Maven的 - 我怎么可以添加任意的类路径条目到一个罐子? [英] Maven - how can I add an arbitrary classpath entry to a jar?
问题描述
我有一个不寻常的情况下,我需要(点即JAR文件)添加任意的类路径进入一个可执行的JAR的清单。 (这是一个Swing桌面应用程序。)
I have an unusual situation where I need to add an arbitrary classpath entry (that points to a jar file) into the manifest of an executable jar. (This is for a Swing desktop application.)
Maven的-JAR-插件生成使用Maven依赖的jar清单中的类路径项,并有不似乎将任意条目的任何方式。
The maven-jar-plugin generates the "Class-Path" entry for the jar manifest using the maven dependencies, and there doesn't appear to be any way of adding arbitrary entries.
我也看了看硬编码任意类路径进入启动应用程序的批处理文件,使用-classpath参数,但我无法弄清楚如何让Maven的classpath中筛选到一个批处理文件
I also looked at hard-coding the arbitrary classpath entry into the batch file that starts the application, using the "-classpath" parameter, but I can't figure out how to get Maven to filter the classpath into a batch file.
推荐答案
我发现有这个问题的一个简单的解决方案。您可以添加<类路径>
元素< manifestEntries>
元素,并设置< addClassPath>真< / addClassPath>
到<&舱单GT;
元素。因此,&LT价值;类路径>
元素被自动添加到类路径。例如:
I found that there is an easy solution for this problem. You can add a <Class-Path>
element to <manifestEntries>
element, and set <addClassPath>true</addClassPath>
to <manifest>
element. So value of <Class-Path>
element is added to class-path automatically. Example:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<configuration>
<archive>
<manifest>
<addDefaultImplementationEntries>true</addDefaultImplementationEntries>
<addClasspath>true</addClasspath>
<mainClass>your.main.Class</mainClass>
</manifest>
<manifestEntries>
<Class-Path>../conf/</Class-Path>
</manifestEntries>
</archive>
</configuration>
</plugin>
这篇关于Maven的 - 我怎么可以添加任意的类路径条目到一个罐子?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!