简体   繁体   English

在没有JVM的计算机上运行Java应用程序

[英]Running a Java application on a machine that doesn't have a JVM

I have created an .exe file of my software (which is a Java swing application). 我创建了一个我的软件的.exe文件(这是一个Java swing应用程序)。 But the .exe file is running only on those computers which have the JVM installed. 但.exe文件仅在安装了JVM的计算机上运行。 I want to run it on computers which do not have the JVM installed. 我想在没有安装JVM的计算机上运行它。 How do I accomplish this? 我该如何做到这一点?

You need a JVM to run Java. 您需要一个JVM来运行Java。 There's no getting around that. 没有解决这个问题。

Users that don't have a JRE installed will have to get one. 没有安装JRE的用户必须获得一个。 Don't confuse that with the JDK. 不要将它与JDK混淆。 They don't need all the development tools, just the runtime engine. 它们不需要所有的开发工具,只需要运行时引擎。

You'll need to ship JVM with your application one way or another anyway. 无论如何,您都需要以某种方式运送JVM。 So why not include JRE into the installation bundle? 那么为什么不将JRE包含在安装包中呢?

Another option would be creating an installer that will download JRE automatically from the Internet if it isn't installed. 另一种选择是创建一个安装程序,如果没有安装,它将自动从Internet下载JRE。 For example you might want to check out this guide http://nsis.sourceforge.net/Java_Launcher_with_automatic_JRE_installation (but read about NSIS first if you're unfamiliar with it). 例如,您可能想查看本指南http://nsis.sourceforge.net/Java_Launcher_with_automatic_JRE_installation (但如果您不熟悉NSIS,请先阅读NSIS)。

我不知道你用什么应用程序将jar包装为exe,但是我建议你使用Launch4j ,它是一个包装器,可以在尝试执行应用程序之前检查用户是否已经安装了JRE / JDK,如果它没有它会显示一条消息并打开浏览器下载java。

  1. Use deployJava.js to help ensure the user has the minimum version of Java needed to run the app. 使用deployJava.js可帮助确保用户具有运行应用程序所需的最低Java版本。
  2. Launch the app. 启动应用程序。 using Java Web Start . 使用Java Web Start

This should work on systems for which Java is available (ie not just Windows). 这应该适用于Java可用的系统(即不仅仅是Windows)。

If you really want to do this, give GCJ a look. 如果你真的想这样做,请给GCJ看看。 Bear in mind however that AWT / Swing support, amongst many other things is pretty much dead. 请记住,AWT / Swing的支持,以及其他很多东西都已经死了。

Even if you won't lose anything in terms of language features, before you go plummeting ahead stop and think if this is something you really need. 即使你不会在语言功能方面失去任何东西,在你前进直线下降停止并认为这是你真正需要的东西。 The vast majority of users have Java and by using GCJ to compile to machine code you're missing all the potential hotspot optimisations, creating a much bigger footprint in a lot of cases and losing cross-platform compatibility. 绝大多数用户拥有Java,并且通过使用GCJ编译为机器代码,您缺少所有潜在的热点优化,在很多情况下创建了更大的占用空间并失去了跨平台兼容性。

It's perfectly acceptable to distribute a jar file and then direct your users to download the JDK if they haven't already, and unless you're doing something very specialised it's what I'd recommend in this case. 分发jar文件然后指导用户下载JDK(如果还没有),这是完全可以接受的,除非你做的非常专业,否则我会在这种情况下推荐它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM