开发者

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

开发者 https://www.devze.com 2023-02-22 04:03 出处:网络
I have created an .exe file of my software (which is a Java swing application). But the .exe file is running only on开发者_如何学C those computers which have the JVM installed. I want to run it on com

I have created an .exe file of my software (which is a Java swing application). But the .exe file is running only on开发者_如何学C those computers which have the JVM installed. I want to run it on computers which do not have the JVM installed. How do I accomplish this?


You need a JVM to run Java. There's no getting around that.

Users that don't have a JRE installed will have to get one. Don't confuse that with the 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. So why not include JRE into the installation bundle?

Another option would be creating an installer that will download JRE automatically from the Internet if it isn't installed. 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).


I don't know what application you used for wrapping the jar as an exe but I recommend you to use Launch4j which is a wrapper who can check if the user has already installed JRE/JDK before trying to execute the application and if it doesn't it will display a message and open the browser to download java.


  1. Use deployJava.js to help ensure the user has the minimum version of Java needed to run the app.
  2. Launch the app. using Java Web Start.

This should work on systems for which Java is available (i.e. not just Windows).


If you really want to do this, give GCJ a look. Bear in mind however that AWT / Swing support, amongst many other things is pretty much dead.

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.

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消