创建独立的 Java 应用程序
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/7978370/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Creating a stand alone Java application
提问by user2434
Is it possible to create a stand alone application in Java (using Swing) and package it into an exe file?
是否可以用 Java(使用 Swing)创建一个独立的应用程序并将其打包成一个 exe 文件?
My Idea is, we should be able to double click it and run the application.
我的想法是,我们应该能够双击它并运行该应用程序。
回答by Heisenbug
If you export a runnable .jar file you will be able to double click and run, but you'll still need the JVM in order to interpret the bytecode.
如果您导出可运行的 .jar 文件,您将能够双击并运行,但您仍需要 JVM 来解释字节码。
回答by Andrew Thompson
The best way to deploy a Swing based app. to a client's desktop is using Java Web Start.
部署基于 Swing 的应用程序的最佳方式。到客户端的桌面正在使用Java Web Start。
JWS offers desktop integration - making a desktop shortcut and menu item, each using an icon if specified. The end use can double-click the desktop shortcut cut to launch the app. ( or single-click the menu item to do the same ;).
JWS 提供桌面集成 - 制作桌面快捷方式和菜单项,如果指定,每个都使用一个图标。最终用户可以双击桌面快捷方式来启动应用程序。(或单击菜单项执行相同的操作;)。
Best of all, JWS works for all platforms for which the J2SE is supplied. Windows, Ubuntu, Fedora, Solaris, Mac. OS..
最重要的是,JWS 适用于提供 J2SE 的所有平台。Windows、Ubuntu、Fedora、Solaris、Mac。操作系统..
For ensuring the user has the correct minimum JRE needed to run the app., use deployJava.jsto write the link to the JNLPlaunch file.
为确保用户拥有运行应用程序所需的正确的最小 JRE,请使用deployJava.js编写指向JNLP启动文件的链接。
回答by sfrj
If you export your project in a .jar file, you will be able to run it when you click on it.
如果您将项目导出为 .jar 文件,则可以在单击它时运行它。
I suppose that you know that you must have the virtual machine installed in the computer that runs the program.(The virtual machine is the thing that allows java to be operative system independent)
我想你知道你必须在运行程序的计算机上安装虚拟机。(虚拟机是让java独立于操作系统的东西)
And also you must know that if you transform that .jar to an .exe file using some kind of gadget... Then java will not be java anymore, because will not be able to run it in non-windows operative systems.
而且您必须知道,如果您使用某种小工具将 .jar 转换为 .exe 文件……那么 java 将不再是 java,因为将无法在非 Windows 操作系统中运行它。
Remember java slogan
记住java口号
'Write once run everywhere"
'写一次到处跑'
See this image here i will explain you how to create a .jar using the eclipse IDE:
在此处查看此图像,我将向您解释如何使用 Eclipse IDE 创建 .jar:
1-Select your project in the package explorer
1-在包资源管理器中选择您的项目
2-Select File>Export from the menu
2-从菜单中选择文件>导出
3-Pick Runnable JAR file from the dialog and
3-从对话框中选择 Runnable JAR 文件并
4-Click next and follow the rest of the wizard
4-单击下一步并按照向导的其余部分进行操作
回答by Daggeto
You can package your application to JAR file. Application in jar file runs on duoble click. Here is tutorial. http://download.oracle.com/javase/tutorial/deployment/jar/
您可以将应用程序打包为 JAR 文件。jar 文件中的应用程序通过双击运行。这里是教程。http://download.oracle.com/javase/tutorial/deployment/jar/
回答by Johann du Toit
You can already do this with a normal .jar file if the user has configured the extension to be executed with the JRE. But you can always use something like Launch4J. Please Note this simply wraps the Jar in a EXE file. The file still needs your Dependencies (.jars) and the JRE enviroment.
如果用户已将扩展配置为使用 JRE 执行,则您已经可以使用普通的 .jar 文件执行此操作。但是你总是可以使用Launch4J 之类的东西。请注意,这只是将 Jar 包装在 EXE 文件中。该文件仍然需要您的依赖项 (.jars) 和 JRE 环境。