I've created a program in java and now I want to create an executable from it.
I'm new to java, I don't know if i开发者_开发问答t should be a .exe
.
I'we exported my project to a .jar
file, but when I double-click it it opens "open with" window.
I want to export my project to a file that runs my program on double-click.
Is there any solution?
Export --> Java --> Runnable Jar file --> Specify the class with static main method to run.
Double click on the Jar file to run..
Thanks...
Java compiliation creates byte code for the JVM, so a native, binary executable is not created during compiliation (like C or C++ programs). This is a feature of Java.
To deploy an application to multiple systems they must have the JRE. These .jar files can be launched from the command line (see this: http://download.oracle.com/javase/tutorial/deployment/jar/run.html)
Some vendors get around this with batch files that launch the JRE to run their application's JAR (and then put these in the start menu, desktop, etc with a fancy icon).
If you want people to install your app (especially from a web page or over a network) you probably want a Java Web Start package (see this for crating one in Eclipse: http://help.eclipse.org/indigo/index.jsp?topic=%2Forg.eclipse.platform.doc.isv%2Fguide%2Fjava_web_start.htm)
If you just want it to be runnable on your computer, you can use the open with dialog to open it with javaw.exe in JDK_DIRECTORY\bin. Alternatively, if you really wanted to make it an EXE, you could look at some of the answers here.
Either do as in the link mentioned by @dacwe or I would suggest to depending on operating system set a permanent connection between java and jars, then it will always happen. On Windows you do it by right clicking on any jar then open with and find your javaw.exe in bin folder of your jre installation.
I think you are looking for a simpler approach than Java Web Start.
I assume that you are a Windows User, since you want a .exe file.
So once you have the exported MyProgram.jar file, you only need to create a .bat file that contains a sole line:
java -jar MyProgram.jar
and place this execute.bat
file in the same folder as your MyProgram.jar
This approach works for Linux too, only you need to place it inside a similar file and execute the same command.
Read here http://javabeanz.wordpress.com/2009/01/29/running-an-executable-jar-from-command-line/ for more explanations.
精彩评论