Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / May 2007

Tip: Looking for answers? Try searching our database.

Finding Java Home path via command line

Thread view: 
Nigel - 01 May 2007 18:51 GMT
Hi,

Without manually adding enviornment variables, Is there a way I can
find the home directory of Java via the command line? (i.e: C:\Program
Files\Java\jre1.6.0)

I know in using Java API I can find  the home path by performing
System.getProperty("java.home"), but I would like to be able to run a
Perl script that can parse command line output and grab the Java home
path.

Not sure if I'm asking for a miracle or not... :)
Any help would be appreciated.

Thanks.
- Nigel
Richard Reynolds - 01 May 2007 22:28 GMT
> Hi,
>
[quoted text clipped - 12 lines]
> Thanks.
> - Nigel

not sure what you mean, JAVA_HOME __is__ an environment variable, if you
mean the java install dir that would be used if you just typed "java" then
that would be determined by your PATH environment variable. Either way
they're just env vars that have to be set up and can be accessed normally
e.g. $PATH or %PATH%
Lew - 01 May 2007 23:25 GMT
>> Hi,
>>
[quoted text clipped - 18 lines]
> they're just env vars that have to be set up and can be accessed normally
> e.g. $PATH or %PATH%

#!/bin/bash
$ jh=$(dirname `which java`)
$ echo $jh
/usr/java/java/bin
$

Signature

Lew

Richard Reynolds - 02 May 2007 00:02 GMT
>>> Hi,
>>>
[quoted text clipped - 24 lines]
> /usr/java/java/bin
> $

'which' will give you the java executable though, and dirname the bin dir,
you'd still have to work out the home dir, also, there may be symlinks
involved. Is there a "which" for windows?
Lew - 02 May 2007 04:10 GMT
> 'which' will give you the java executable though, and dirname the bin dir,
> you'd still have to work out the home dir, also, there may be symlinks
> involved. Is there a "which" for windows?

<http://www.cygwin.com/>

Signature

Lew

Real Gagnon - 01 May 2007 23:14 GMT
> Without manually adding enviornment variables, Is there a way I can
> find the home directory of Java via the command line? (i.e: C:\Program
> Files\Java\jre1.6.0)

You can use the regedit utilty`to dump the JRE location installed on your
workstation and then parse the output.

Example at :
http://www.rgagnon.com/javadetails/java-0525.html

Bye.
Signature

Real Gagnon  from  Quebec, Canada
* Java, Javascript, VBScript and PowerBuilder code snippets
* http://www.rgagnon.com/howto.html
* http://www.rgagnon.com/bigindex.html

printdude1968@gmail.com - 02 May 2007 02:31 GMT
> Hi,
>
[quoted text clipped - 12 lines]
> Thanks.
> - Nigel

If you type "set" from the command line you will get a listing of all
the env vars that are set.
If I were working on a win machine using ksh or some other *nix build,
I would simply do
% set | grep "JAVA_HOME"
and use the the results of that.

$ set | grep "JAVA_HOME"
JAVA_HOME='/dev/fs/C/Program Files/Java/jdk1.6.0'

The same basic command would work for a real *nix installation.
My understanding is that you don't always need to set a JAVA_HOME
variable which
would mean that you need to parse the "echo %PATH%" results and try to
get it from there.

J:\>echo %PATH%
C:\Tcl\bin;C:\Python25\;J:\apache-ant-1.7.0\bin;C:\oraclexe\app\oracle
\product\1
0.2.0\server\bin;c:\ruby\bin;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS
\System32\
Wbem;C:\Program Files\ATI Technologies\ATI Control Panel;C:\Program
Files\QuickT
ime\QTSystem\;C:\SFU\common\;C:\Program Files\Subversion\bin;C:
\Program Files\My
SQL\MySQL Server 4.1\bin;C:\Program Files\Common Files\GTK\2.0\bin;C:
\Program Fi
les\Java\jdk1.6.0\bin;C:\Sun\jwsdp-2.0\jwsdp-shared\bin

You should be able to traverse the output until you find a jdk or jre
on the PATH and
pull out the contents of JAVA_HOME from there.

I'm not a DOS guru so I've no idea how to do this.

It's much easier if the JAVA_HOME variable in DOS is already set.
Arne Vajhøj - 02 May 2007 03:28 GMT
> Without manually adding enviornment variables, Is there a way I can
> find the home directory of Java via the command line? (i.e: C:\Program
[quoted text clipped - 6 lines]
>
> Not sure if I'm asking for a miracle or not... :)

What do you want on a system with more than one Java version
installed ?

JAVA_HOME is used to give the run script the capability to specify
which Java version to use.

Arne


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.