How to combine library with my jar?

前端 未结 8 859
再見小時候
再見小時候 2020-12-01 17:38

Ok so i wrote a program that makes use of a 3rd party open source library and i want to package it with my program in a single jar. I\'m using netbeans 6.8 and everything I\

8条回答
  •  猫巷女王i
    2020-12-01 18:12

    I realize that this doesn't achieve exactly what you want, but I'll describe the customary method of distributing a standalone application. If it does meet your needs, you'll find that it's better supported by tools and more readily understood by users, because it follows established conventions.

    Put your code in a jar (I'll call it app.jar) along with a META-INF/MANIFEST.MF file with entries like this:

    Main-Class: com.y.app.AppMain
    Class-path: third-party.jar blort.jar foo.jar
    

    Then, you can throw all of the jars into a directory and run AppMain like this:

    java -jar app.jar
    

    If you want, you can put the third-party libraries in a single directory like lib and refer to them in the Class-path attribute using a path relative to the main jar: lib/third-party.jar That helps keep your distribution tidy.

提交回复
热议问题