且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何使用依赖项jar创建可执行jar

更新时间:2022-03-26 21:48:58

您可以使用Ant轻松完成:

You can do that easily with Ant:

<jar jarfile="MyJar.jar" basedir="bin">
    <manifest>
    <attribute name="Class-Path" value="lib/lib1.jar lib/lib2.jar lib/lib3.jar"/>
    <attribute name="Built-By" value="me"/>
    <attribute name="Main-Class" value="mypackage.Myclass"/>
    </manifest>
</jar>

这会将所有相应的条目添加到Manifest文件中。为了能够运行jar,您还需要创建一个lib文件夹并将所有依赖项放在那里:

This will add all the appropriate entries to the Manifest file. In order to be able to run the jar, you also need to create a lib folder and place all the dependency jars there:

myjar.jar
lib/lib1.jar
lib/lib2.jar
lib/lib3.jar