Maven - 如何向 jar 添加任意类路径条目? [英] Maven - how can I add an arbitrary classpath entry to a jar?

查看:27
本文介绍了Maven - 如何向 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-plugin 使用 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 将类路径过滤到批处理文件中.

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.

推荐答案

我发现这个问题有一个简单的解决方案.您可以将 元素添加到 元素,并设置 true 元素.所以 元素的值会自动添加到 class-path 中.示例:

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 - 如何向 jar 添加任意类路径条目?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆