How do I run a .jar executable java file from outside NetBeans IDE?

若如初见. 提交于 2019-11-28 07:32:26

问题


How do I run a .jar executable java file from outside NetBeans IDE? (Windows Vista). My project has a .jar file created by Netbeans. We'd like to run it. Either: how do we run the file or how do we create a 'proper' executable file in NetBeans 6.1?


回答1:


Running a jar is as simple as

java -jar filename.jar



回答2:


as Laplie said, java -jar your.jar

EXECUTABLE file : see this thread for answers How can I convert my Java program to an .exe file?




回答3:


One of the best technique to run the jar file or jar jar file

  1. Create the jar file by jar command choose your jar filename Java_Jar_File.jar
  2. Run the jar file us the command like java -jar Java_Jar_File.jar



回答4:


You can do it from the command prompt if java isn't in your path by finding the full path to your java install, something like:

C:\java\java.exe -jar C:\jar_you_want_to_run.jar

or if java is in your path:

java.exe -jar jar_you_want_to_run.jar

This will run the jar produced by netbeans.




回答5:


First, make sure you set the Main Class in your NetBeans project properties dialog.
Then, you can either

  • Double-click the jar file (This should work on any machine with an installed JRE)

or

  • Make sure that java.exe is in the path (or replace java below with the fullpath and file name of the executable), put the following in a batch file:
    java -jar filename.jar
    Then you can double-click the batch file instead of the jar (useful if you have people unaccustomed to using naked jar files)

OR

  • You can go down the path described here How can I convert my Java program to an .exe file? to build a .exe for windows.



回答6:


Make a BAT file with

java -jar filepath.jar



回答7:


from a command prompt you can run this command: java -jar your_jar.jar.




回答8:


To run a java jar file its file association should be properly configured. There is a free tool called jarfix to fix all jar file association problems. Run this file to fix all jar issues.




回答9:


In the project properties dialog in NetBeans you need to set the Main Class - otherwise the generated .jar will not be executable. Then, as already indicated, either double clicking on the .jar or the command java -jar will start the program.




回答10:


If you have problems with running your jar, make sure you are trying to run your current version to get newest version in Netbeans: GoTo Run Menu --> Clean and build



来源:https://stackoverflow.com/questions/176902/how-do-i-run-a-jar-executable-java-file-from-outside-netbeans-ide

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