eclipse 如何在java中创建一个可执行文件?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/15347901/
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
How to create an executable file in java?
提问by user2158386
I did my project in Eclipse. I have *.java
, .project
, .classpath
and *.class
files in my Eclipse workspace. How do I create an executable?now.
我在 Eclipse 中完成了我的项目。我有*.java
,.project
,.classpath
和*.class
在我的Eclipse工作区文件。如何创建可执行文件?现在。
回答by Michael Berry
Eclipse will build an executable jar file for you, which is run with Java (java.exe if you're on windows) to launch your application. On a machine correctly set up with Java installed, double clicking an executable jar should run the program.
Eclipse 将为您构建一个可执行的 jar 文件,该文件使用 Java(如果您在 Windows 上为 java.exe)运行以启动您的应用程序。在安装了 Java 的正确设置的机器上,双击可执行 jar 应运行该程序。
If you want an exe, then there are ways to do itthat will generally wrap the jar file (and sometimes the JDK.) However, first ask yourself whyyou're doing it this way - often it's just a habitual desire to have an exe, without any great technical reason. All you're really doing through this is taking a cross-platform executable, and making it only work on Windows.
如果你想要一个 exe,那么有一些方法通常会包装 jar 文件(有时是 JDK)。但是,首先问问自己为什么要这样做 - 通常这只是一种习惯性的愿望exe,没有任何重大的技术原因。通过这个,你真正要做的就是获取一个跨平台的可执行文件,让它只在 Windows 上工作。
If you're distributing your application and your users expect an exe, then consider building platform dependant installers for each OS you wish to support, but leaving the jar file in tact. The average user will never usually need to touch it directly if your installer places shortcuts in the correct locations, they'll only ever need to run the installer directly (so your application file format becomes irrelevant, just an implementation detail as far as they're concerned.)
如果您正在分发您的应用程序并且您的用户需要一个 exe,那么请考虑为您希望支持的每个操作系统构建依赖于平台的安装程序,但保留 jar 文件。如果您的安装程序将快捷方式放置在正确的位置,普通用户通常永远不需要直接触摸它,他们只需要直接运行安装程序(因此您的应用程序文件格式变得无关紧要,就他们而言只是一个实现细节)重新关心。)
回答by LtWorf
You need to create a .jar file from your project. On windows normally with double click those files get executed if a java virtual machine is installed.
您需要从您的项目创建一个 .jar 文件。在 Windows 上,如果安装了 Java 虚拟机,通常双击这些文件就会被执行。
There are solutions to wrap an .exe file around your .jar, but I don't know how good they are so I can't suggest anything.
有一些解决方案可以将 .exe 文件包装在 .jar 周围,但我不知道它们有多好,所以我无法提出任何建议。
回答by Simon Arsenault
Java executables are runnable .JAR files. You need to export as Runnable Jar.
Java 可执行文件是可运行的 .JAR 文件。您需要导出为 Runnable Jar。
In Eclipse:
在日食中:
- Right click on your project
- Export
- Export...
- Runnable JAR file
- 右键单击您的项目
- 出口
- 出口...
- 可运行的 JAR 文件
回答by lancer
You would have to use chmod in the command line. This argument can change the permission of the file. It depends on three groups. Reading, writing, and executing can all be altered using this argument.
您必须在命令行中使用 chmod。此参数可以更改文件的权限。这取决于三个群体。使用此参数可以更改读取、写入和执行。
回答by Jean Waghetti
回答by A4L
like in ohter replies mentioned you need to create a jar
file witch packages all your compiled classes. while exporting from eclipse you can optionally export the dependecies that your project needs to run.
就像在其他回复中提到的那样,您需要创建一个jar
文件,将所有已编译的类打包。从 Eclipse 导出时,您可以选择导出项目需要运行的依赖项。
if you want to create an exe
file you can use some software witch packages/wraps your jar(s)
into an executable file. you can try jsmooth, it provides several exe wrappers and has the ability to integrate your jar an its dependencies into one single file witch you can distribute and will be per click executed.
如果你想创建一个exe
文件,你可以使用一些软件将你打包/包装jar(s)
成一个可执行文件。您可以尝试jsmooth,它提供了几个 exe 包装器,并且能够将您的 jar 及其依赖项集成到一个您可以分发的单个文件中,并且每次单击都会执行。