开发者

Export a java library in a .jar file

开发者 https://www.devze.com 2023-04-07 04:05 出处:网络
I\'m still pretty new to java and I\'m VERY new to exporting .jar files. I\'ve got a little game that I want to send to some friends and I was told in another question that I should export it to an ex

I'm still pretty new to java and I'm VERY new to exporting .jar files. I've got a little game that I want to send to some friends and I was told in another question that I should export it to an executable jar file. Well I finally got that working on my computer but when I send it to other people it doesn't work because they don't have the library.

I'm importing the objectdraw library and without that my program won't run at all!

So basically I need to find a way to export the object draw library as part of my .jar file so that they can use it too. Do I simply include it in the included file开发者_运维问答s part of the jar command? ex: jar cmf MANIFEST.mf Archery.jar * /System/Library/Java/Extensions/objectdraw.jar

or what? I'm working out of the command line right now.


The simplest way is to send the JAR library file too and add a Class-Path entry to the manifest. This entry would look like:

Class-Path: objectdraw.jar

You could also set the CLASSPATH environment variable manually.

Alternatively, you can unpack the library and add all (or just the required files) to your final jar. This doesn't always work though, because some libraries rely on the integrity of teir JAR file.

Finally, it is possible to include the dependency in the main JAR, but it would require a custom class loader.


Turns out the best way I've found to do this is to unpack the library and then put all the resulting files in with your final archive. This way it actually works on other computers.

jar xf library_wanted.jar; jar cvmf MANIFEST.mf end_result.jar *.class library_wanted/
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号