Java 如何将 JAR 文件转换为 EXE 文件?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/2272107/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-13 05:30:55  来源:igfitidea点击:

How can I convert a JAR file to an EXE file?

jarexejava

提问by Freeman

I want to created a JAR file and I want to run it on a client machine.So, I have a couple of questions:

我想创建一个 JAR 文件,我想在客户端机器上运行它。所以,我有几个问题:

  1. How can I convert the JAR file to an EXE file?
  2. How can I encrypt the JAR file's contents? The jar file could be extracted with WinRAR and the classes could be decompiled with any Java decompiler.
  3. How can I create an installer? My clients doesn't have any JVM and I don't want to ship JDK or JRE along, because they have big size.
  1. 如何将 JAR 文件转换为 EXE 文件?
  2. 如何加密 JAR 文件的内容?jar 文件可以用 WinRAR 提取,类可以用任何 Java 反编译器反编译。
  3. 如何创建安装程序?我的客户没有任何 JVM,我不想随附 JDK 或 JRE,因为它们的尺寸很大。

采纳答案by extraneon

  1. See this link: Java to Exe. It also explains what valid reasons are to do this, and when you should not.

  2. You can't really encrypt binaries as the machine has to understand them. That said, an optimized executable is very difficult to decompile, while plain class files are ease.

  3. If you have an exe there are installers enough.

  1. 请参阅此链接:Java to Exe。它还解释了这样做的正当理由,以及什么时候不应该这样做。

  2. 你不能真正加密二进制文件,因为机器必须理解它们。也就是说,优化的可执行文件很难反编译,而普通的类文件很容易。

  3. 如果你有一个exe,那么安装程序就足够了。

回答by Ganesh Shankar

JSmooth is a application which will wrap your Jar in an exe

JSmooth 是一个应用程序,它将您的 Jar 包装在一个 exe 文件中

it also allows you to check if the correct version of JRE is available on the system you're deploying to

它还允许您检查您要部署到的系统上是否有正确版本的 JRE

http://jsmooth.sourceforge.net/

http://jsmooth.sourceforge.net/

回答by Thorsten Dittmar

As for 1): I guess you can not. There may be tools out there, but you cannot do that with standard tools shipped with JDK, as it would destroy platform independance. (See other answers providing links to such 3rd party tools)

至于1):我猜你不能。可能有一些工具,但是您不能使用 JDK 附带的标准工具来做到这一点,因为它会破坏平台独立性。(请参阅提供此类 3rd 方工具链接的其他答案)

As for 3): Use InnoSetup to create the installer. Include JRE within setup and let InnoSetup install it on the fly.

至于 3):使用 InnoSetup 创建安装程序。在安装程序中包含 JRE 并让 InnoSetup 即时安装它。

回答by icktoofay

You can't prevent decompilation. The best you can do is make it harder or more time-consuming to do so. As an answer to your question though, I believe you can use gcjto compile Java into EXEs.

你无法阻止反编译。你能做的最好的事情就是让它变得更难或更耗时。不过,作为对您问题的回答,我相信您可以使用gcj将 Java 编译为 EXE。

回答by ponkin

May be Excelsior JETwill satisfy your needs.) IMHO very mature product.

可能Excelsior JET会满足您的需求。)恕我直言,非常成熟的产品。

回答by brian_d

1) I have recently tried the program jarToExeand like it. Some features are:

1) 我最近尝试了程序jarToExe并喜欢它。一些功能是:

  • free basic version or very cheap ($30) for 'enterprise'
  • ability to have windows task manager list your app's name instead of the default java.exe
  • extra obfuscation
  • runtime check that java is installed
  • 免费基本版或“企业版”非常便宜(30 美元)
  • 能够让 Windows 任务管理器列出您的应用程序的名称而不是默认的 java.exe
  • 额外的混淆
  • 运行时检查java是否安装

2) You can make it harderto reverse engineer using proguardor other obfuscator

2)你可以把它更难使用逆向工程的ProGuard或其他混淆

3) nsisis a very powerful, free scripting language to create windows installers. Good documentation on the site wiki and support on stack overflow as well.

3) nsis是一种非常强大的免费脚本语言,用于创建 Windows 安装程序。站点 wiki 上的良好文档以及对堆栈溢出的支持。

回答by Huy Hóm H?nh

Launch4jworked for me while some tools hadn't been working. It also have a good guide here.

Launch4j对我有用,而某些工具还没有工作。这里也有很好的指南。

Hope this help!

希望这有帮助!

回答by Pramod

We use a 7zip SFX install launcher. This is an open source simple tool. It will package your jar, a version of jre so it's not mandatory for the installing systems to have jre installed and a self extracting version of 7zip. Here is a tutorialwhich explains how to bundle and GitHub linkThe project is not maintained but works perfectly(tested until Java 1.8)

我们使用 7zip SFX 安装启动器。这是一个开源的简单工具。它将打包您的 jar,一个 jre 版本,因此安装系统不必安装 jre 和 7zip 的自解压版本。这是一个教程,它解释了如何捆绑和 GitHub链接该项目没有维护但运行良好(测试到 Java 1.8)

回答by dilanSachi

1) To create the exe, you can use Launch4j

1) 要创建exe,您可以使用Launch4j

2) As I have seen, you cannot encrypt the jar contents. I'm not sure though.

2)正如我所见,您无法加密 jar 内容。我不确定。

3) To create the installeryou can use the exeyou just created and use InnoSetupto create the files. You have to embedthe jreinside the installer and also any other librariesand extra filesthat may need in the runtime. When embedding the jre, the setup gets large and if you want to avoid that, you can ask the clients to install java in the machines. That way, you wont need to ship with the jre.

3) 要创建安装程序,您可以使用刚刚创建的exe并使用InnoSetup创建文件。你必须要嵌入JRE安装程序中以及任何其他库额外的文件,可能需要在运行时。嵌入 jre 时,设置会变大,如果您想避免这种情况,您可以要求客户端在机器中安装 java。这样,您就不需要随 jre 一起发货。