Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Detecting JRE

 
Rajendra Gangarde
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 15272
37
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Rajendra Gangarde
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 3640
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
Mahesh Rana
Ranch Hand
Posts: 139
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
See if it helps:

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

if [ $jrePresent = 1 ]

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

fi
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic