简体   繁体   中英

Install JRE if not installed

I've been looking, on the web and this forum, for the correct way to include the Java Runtime Environment with my Java application.

I know that the JRE is machine-dependant and thus, the JRE to provide with my application will change if I want to deploy for MAC or Linux for example.

What I really want to know (assuming what I said before is correct), is :

"Is there a way to check whether a JRE is installed on the client machine, and if not install it before trying to run my application ?"

Because I do not think it is possible :

Do you think I should deploy my application with the JRE folder adapted to the client system, and launch my application with a script using the java.exe contained in the JRE folder ?

This avoids installing any Java stuff, but it doesn't look like a good practice to me...

If your application is client-side, I would offer both options: installation with and w/o JRE. Many java applications offers both installations. For example, SmartGit application allows you to download installation with bundled JRE or one that uses existing JRE (where its users responsibility to have the compatible version of java). Many application servers comes with their own JDK already included with the installation.

So, bundling deployment with your JRE is fine if you don't want any trouble with your customers; however, I would allow non-JRE installation as well (to satisfy picky ones :).

If your application is server-side, usually it doesn't come with JRE, but again, this is not a rule.

Moreover, your running/installation script may check if correct JRE or JDK is installed (by checking if the JAVA_HOME is set etc) and then exit if JRE is missing. Even more, the script can even download java and install it locally - although it would be more practical to just use bundled JRE that you have prepared with the application. Or, if JRE is detected, you may ask user if they want to use existing java or bundled.

Bundling JRE is not a big deal. Even I sometimes install java application with bundled JRE, because I switched on my system to eg new version or 64-bit version of java that is not supported by application and so on...

Hope this helps ;)

java -version command on CMD of windows tells JVM version; so you can decide if you need to install or not based on the output of this command.

C:\\Users\\501200I958>java -version

java version "1.7.0_17" Java(TM) SE Runtime Environment (build 1.7.0_17-b02) Java HotSpot(TM) 64-Bit Server VM (build 23.7-b01, mixed mode)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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