How to create an executable (a file that starts the program on double-click like an .exe) in JAVA with Eclipse?

蹲街弑〆低调 提交于 2019-12-11 00:00:58

问题


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 it 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?


回答1:


Export --> Java --> Runnable Jar file --> Specify the class with static main method to run.

Double click on the Jar file to run..

Thanks...




回答2:


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)




回答3:


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.




回答4:


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.




回答5:


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.



来源:https://stackoverflow.com/questions/7233727/how-to-create-an-executable-a-file-that-starts-the-program-on-double-click-like

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