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

发布于 2024-08-21 16:04:45 字数 216 浏览 8 评论 0 原文

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

  1. 如何将 JAR 文件转换为 EXE 文件?
  2. 如何加密 JAR 文件的内容? jar 文件可以使用 WinRAR 提取,并且类可以使用任何 Java 反编译器进行反编译。
  3. 如何创建安装程序?我的客户没有任何 JVM,我不想附带 JDK 或 JRE,因为它们体积很大。

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

  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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(9

香草可樂 2024-08-28 16:04:45
  1. 请参阅此链接:Java 到 Exe。它还解释了这样做的正当理由以及何时不应该这样做。

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

  3. 如果你有一个exe文件,就有足够的安装程序。

  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.

心碎无痕… 2024-08-28 16:04:45

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

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

http://jsmooth.sourceforge.net/

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

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

http://jsmooth.sourceforge.net/

弄潮 2024-08-28 16:04:45

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

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

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)

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

做个少女永远怀春 2024-08-28 16:04:45

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

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 gcj to compile Java into EXEs.

泪是无色的血 2024-08-28 16:04:45

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

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

听风吹 2024-08-28 16:04:45

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

  • 免费的基本版本或非常便宜(30 美元)的“企业”
  • 能力 让 Windows 任务管理器列出您的应用程序名称而不是默认的 java.exe
  • 额外的混淆
  • 运行时检查 java 是否已安装

2) 您可以使其 proguard 或其他混淆器进行逆向工程>更困难

3) nsis 是一种非常强大的免费脚本语言,用于创建 Windows 安装程序。网站 wiki 上有很好的文档,并且还支持堆栈溢出。

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

  • 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

2) You can make it harder to reverse engineer using proguard or other obfuscator

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

夜声 2024-08-28 16:04:45

Launch4j 对我有用,但有些工具不起作用。 此处也提供了很好的指南。

希望这有帮助!

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

Hope this help!

贩梦商人 2024-08-28 16:04:45

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

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 tutorial which explains how to bundle and GitHub link
The project is not maintained but works perfectly(tested until Java 1.8)

记忆之渊 2024-08-28 16:04:45

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

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

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

1) To create the exe, you can use Launch4j

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

3) To create the installer you can use the exe you just created and use InnoSetup to create the files. You have to embed the jre inside the installer and also any other libraries and extra files that 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文