• Post Reply Bookmark Topic Watch Topic
  • New Topic

How to detect whether java installed or not ?  RSS feed

 
Sanjeev Charla
Ranch Hand
Posts: 90
Firefox Browser Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

1. How to detect whether Java installed or not ? is there any unique solution for this task for all the platforms ? If not, please specify how to check this in windows.

2. How to get the locations of different JDKs and JREs installed in the system ?

Thank you.
 
Krishna Chhabra
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In windows, their is one environment variable named "JAVA_HOME" which should point to your installed JDK.

You can check the same....
 
Jesper de Jong
Java Cowboy
Sheriff
Posts: 16060
88
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Krishna Chhabra wrote:In windows, their is one environment variable named "JAVA_HOME" which should point to your installed JDK.

That's not always true; the JDK installer does not set JAVA_HOME, in fact the JRE or JDK does not even use this environment variable at all. So this is not a reliable way of checking if a JRE or JDK is installed and what its location is.
 
Sanjeev Charla
Ranch Hand
Posts: 90
Firefox Browser Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes,

it is not reliable, that is why i am not using it.
 
Henry Wong
author
Sheriff
Posts: 23295
125
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sanjeev Charla wrote:
1. How to detect whether Java installed or not ? is there any unique solution for this task for all the platforms ? If not, please specify how to check this in windows.

2. How to get the locations of different JDKs and JREs installed in the system ?


IMO, for Windows, your best option is probably to use a Windows Search.

Henry
 
Sanjeev Charla
Ranch Hand
Posts: 90
Firefox Browser Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I just want to have some thing like a launcher to my application. this launcher checks for the JDKs and JREs installed in the system and asks to specify if nothing found.
 
Henry Wong
author
Sheriff
Posts: 23295
125
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sanjeev Charla wrote:I just want to have some thing like a launcher to my application. this launcher checks for the JDKs and JREs installed in the system and asks to specify if nothing found.


Well, if you don't want to search the whole disk, then just search the recommended install locations -- which is the java directory under "C:\Program Files" (or "C:\Program Files (x86)").

Henry
 
Aniruddh Joshi
Ranch Hand
Posts: 275
Eclipse IDE jQuery Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
shell command will give you the path of java home.
If it does not return anything, there is no java.

In what language are you planning to write the launcher?

Maybe you could write a simple shell or dos script that runs .
If it says
java - command not found
. You get to know if java is on your path.
 
Jesper de Jong
Java Cowboy
Sheriff
Posts: 16060
88
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You could use a tool that makes an installer for your Java application. Some of these tools can check for you if Java is installed, and even download and install it automatically if it isn't.

See this list of Java installer generators.
 
Jesper de Jong
Java Cowboy
Sheriff
Posts: 16060
88
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Aniruddh Joshi wrote:shell command will give you the path of java home.
If it does not return anything, there is no java.

That doesn't work on Windows, only on Mac OS X, Linux and other Unix-like operating systems.
 
Sanjeev Charla
Ranch Hand
Posts: 90
Firefox Browser Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Install launchers may be a best solution. In this case i have to make a launcher for various platforms as per the requirement. Thanks.
 
Stuart A. Burkett
Ranch Hand
Posts: 679
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sanjeev Charla wrote:I just want to have some thing like a launcher to my application. this launcher checks for the JDKs and JREs installed in the system and asks to specify if nothing found.

On Windows the registry contains that sort of information. Have a look under HKEY_LOCAL_MACHINE\SOFTWARE\JavaSoft\Java Runtime Environment. You will find a subbranch for each JRE that is installed that includes their location.
 
Aniruddh Joshi
Ranch Hand
Posts: 275
Eclipse IDE jQuery Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jesper de Jong wrote:That doesn't work on Windows, only on Mac OS X, Linux and other Unix-like operating systems.

Agree, but aren't launchers and installers usually platform dependent?
 
Sanjeev Charla
Ranch Hand
Posts: 90
Firefox Browser Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
in case of launchers, we can specify which version to use on which platform before the actual execution of the application. Users can select the related version for the OS they are using. If we embed the selection code inside the application, if we run that application on different platform it may fail and not reliable. And ofcourse native launchers work with out java as they are native, exactly what is the requirement.
 
fred rosenberger
lowercase baba
Bartender
Posts: 12565
49
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you are installing an app, why do you care if the JDK is installed? Don't you only need the JRE?
 
Sanjeev Charla
Ranch Hand
Posts: 90
Firefox Browser Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Of course, to run an application just JRE is enough. But, what if i want to know about the JDKs or if i want to know different versions of JREs among which i want to select a particular JRE to run the application. And what if we want to check whether there is any JRE installed or not.
 
Jesper de Jong
Java Cowboy
Sheriff
Posts: 16060
88
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Aniruddh Joshi wrote:Agree, but aren't launchers and installers usually platform dependent?

Yes, but if there's no JRE installed at all on the machine then your installer must be platform-dependent, native OS code. Most of those installer-generators can create installers for the major operating systems (Windows, Mac OS X, Linux).
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!