aspose file tools*
The moose likes Java in General and the fly likes Detecting JRE Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Detecting JRE" Watch "Detecting JRE" New topic
Author

Detecting JRE

Rajendra Gangarde
Greenhorn

Joined: Sep 10, 2004
Posts: 7
I am not sure about this topic should be part of this form or not. But Still its related to java.
I have to write a shell script in java that will detect JRE and then start executing application bundled as jar file. Thanks in advance
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 14352
    
  22

You can't write shell scripts in Java.

If the user's environment is set up properly, you don't need to do complicated things to detect the JRE. Just run the application with:

java -jar TheJarFile.jar


Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 8 API documentation
Rajendra Gangarde
Greenhorn

Joined: Sep 10, 2004
Posts: 7
Sorry, I mean to say I have to write shell script in linux,
Which will
1) detect JRE is installed.
2) then check that required libraries are installed
if not then displays error message or else continue application bundled as jar file.
Hope this makes my question more clear
Chetan Parekh
Ranch Hand

Joined: Sep 16, 2004
Posts: 3636
If you want to check the version of JRE then use
System.getProperty("java.version") .

But if you want to check whether JRE is installed or not, this will not help you.

If you are getting ClassNotFound exception, you can say required library is missing.

But better way to do this would be getting jar list using

System.getProperty("java.class.path");
// Check your .jar files are there or not.

System.getProperty("java.library.path");
//Get list of files from the
resultant path and check your .jar files are there or not.

[ September 02, 2005: Message edited by: Chetan Parekh ]

My blood is tested +ve for Java.
Mahesh Rana
Ranch Hand

Joined: Sep 05, 2001
Posts: 139
See if it helps:

jrePresent=ls -1 `which java` | wc -l

if [ $jrePresent = 1 ]

jreBinDirectory=dirname `which java`
jreLibDirectory=$jreBinDirectory/../lib
.....
.....

fi


SCJP2
 
jQuery in Action, 2nd edition
 
subject: Detecting JRE