How to create an executable jar file which can be distributed or packaged?

假如想象 提交于 2019-12-12 12:19:35

问题


I am using getdown to create a means to update a java application. When I have completed this tutorial, I tested if it works on command line as below:

% java -jar c:/downloads/getdown-X.Y.jar c:/netBeans/getdown/src

Thankfully, this works and launches the application. Great.

How do I make a jar file and distribute this?

I tried to make a jar file on this project but it didn't work, this project does not run. When I run this getdown-X.Y.jar on command line.

I think it still using the same file which I created before c:/netBeans/getdown/src. Eventually, it is failing to execute since it is missing the jar file. So, how to make this project into a jar file and distribute it.


回答1:


I am not sure what OS you are working on.You can do this by creating an executable jar file. Please follow the steps here:

If you want to create a jar file with additional file. Here in below, if you want to create a jar file of imagine src.class with additonal text file with it which is readme.txt

c:\patel\projects\netbeans\getdown\src.class
c:\patel\projects\readme.txt

Run this command: jar -cvfm src.jar readme.txt netbeans\getdown\*.class

which is: c:\patel\projects\jar -cvfm src.jar readme.txt netbeans\getdown\*.class Now your executable jar file is ready. To run this jar file:

run this on command prompt: java -jar src.jar



来源:https://stackoverflow.com/questions/32353265/how-to-create-an-executable-jar-file-which-can-be-distributed-or-packaged

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!