Creating and running a Jar file

好久不见. 提交于 2020-01-06 16:54:54

问题


I am a beginner in java programming. I have created a package called Comp Project which contains two classes....

  1. ATM: It has various functions to carry out actions of atm screen.
  2. Main: This class calls all the functions from ATM and executes them.

Now the program is running good and I have to create a jar file. I created a Jar file with the main class selected as Main. But when I try to run it....it doesn't work. The problem is that i don't understand what creating a manifest is...I looked onto other posts but i did not understand anything.

Can anyone tell me the steps to follow for creating a proper Jar file and Running it?? I need both as I don't know where i am going wrong.

Update: I am using BlueJ.


回答1:


Create a manifest.txt file.

Main-Class: fully.qualified.class.name of your main class

Uses Main-Class as the entry point of this Jar file, when you double click on this Jar file, the “Example.class” main() method will be launched.

And then on command line

jar -cvfm Example.jar manifest.txt your-package-structure/*.class

Hope this helps.




回答2:


You can use jar cf yourCompAppJar.jar Main.class to create your jar file, if you have JDK 6 you can use the cfe to specify the entry point.


If you are using Eclipse :

  • Right-click the project > click Export > select "Runnable JAR file" under the Java folder > In the launch configuration select the class name > choose where to save your jar > finish.


来源:https://stackoverflow.com/questions/36823394/creating-and-running-a-jar-file

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