创建包含类路径的 jar

Creating jar which includes classpath

我正在尝试将我的 jar 文件发送给其他人,而不需要将多个 jar 文件发送给一个人以便他们 运行 我的应用程序。有没有办法在我的 jar 中包含一个辅助 jar 文件并将其作为我的 Class 路径而不是在我的工作目录中?

这是我创建 Jar 时的清单。

Manifest-Version: 1.0
Main-Class: MultipleLinearRegression
Class-Path: Jama.jar

这就是我创建 jar 文件的方式

jar cvfm MyApplication.jar manifest.txt Jama.jar *.class

对于创建jar文件,我们可以按照以下步骤操作,

1) Class-Path: <lib1.jar> <lib2.jar> <path/lib3.jar>
2) Main-Class: <classname>
3) Place a new line at the end of this file

Maven and the Shade plugin you can create an Uber JAR, containing all dependend JARs in one JAR file. There is also a Shade Plugin for Gradle(如果你不使用 Maven 或 Gradle,你真的应该考虑这样做。)

这里有一篇有趣的文章:Creating Executable Uber Jar’s and Native Applications with Java 8 and Maven

还有其他类似的工具,例如 One-JAR