SunQuest
           UNIX Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsOperating SystemsUNIX Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
Stop making mediocre tutorials.The best tutorials are video! Camtasia Studio makes it easy to create engaging, buzz-building screen videos at any size, in any popular format. Download the free trial!
  #1  
Old February 2nd, 2005, 02:06 PM
StevenC's Avatar
StevenC StevenC is offline
PHP & Java Error Master
Dev Shed Beginner (1000 - 1499 posts)
 
Join Date: Jun 2003
Location: My Computer
Posts: 1,218 StevenC User rank is Sergeant (500 - 2000 Reputation Level)StevenC User rank is Sergeant (500 - 2000 Reputation Level)StevenC User rank is Sergeant (500 - 2000 Reputation Level)StevenC User rank is Sergeant (500 - 2000 Reputation Level)StevenC User rank is Sergeant (500 - 2000 Reputation Level) 
Time spent in forums: 1 Day 1 h 31 m 59 sec
Reputation Power: 15
Looking for java

Anyone know of a reliable way to look for java in a shell script on a system?
At the very least i'd need to check for java in a couple known directories.

Thanks.
__________________


Webinfractions.com
Think I'm wrong? You're probably right!

Reply With Quote
  #2  
Old February 2nd, 2005, 02:36 PM
zlutovsky zlutovsky is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2004
Location: Prague, Czech Rep.
Posts: 116 zlutovsky User rank is Corporal (100 - 500 Reputation Level)zlutovsky User rank is Corporal (100 - 500 Reputation Level)zlutovsky User rank is Corporal (100 - 500 Reputation Level)zlutovsky User rank is Corporal (100 - 500 Reputation Level) 
Time spent in forums: 22 h 34 sec
Reputation Power: 6
use find

If you know at least a part of the file name you are searching for, use find, i. e.

cd /
find . -name "*java*"

This command will take some time, because it will search
all filesystems you have in the box.


regards

Reply With Quote
  #3  
Old February 2nd, 2005, 03:26 PM
StevenC's Avatar
StevenC StevenC is offline
PHP & Java Error Master
Dev Shed Beginner (1000 - 1499 posts)
 
Join Date: Jun 2003
Location: My Computer
Posts: 1,218 StevenC User rank is Sergeant (500 - 2000 Reputation Level)StevenC User rank is Sergeant (500 - 2000 Reputation Level)StevenC User rank is Sergeant (500 - 2000 Reputation Level)StevenC User rank is Sergeant (500 - 2000 Reputation Level)StevenC User rank is Sergeant (500 - 2000 Reputation Level) 
Time spent in forums: 1 Day 1 h 31 m 59 sec
Reputation Power: 15
That doesn't help me much, as I need to use the path that java's located in to execute some classes in the shell script.

My problem is on some of our boxes we have multiple versions of java and I need to execute a specific version, but that version isn't always install in the same place.

Reply With Quote
  #4  
Old February 3rd, 2005, 04:42 AM
zlutovsky zlutovsky is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2004
Location: Prague, Czech Rep.
Posts: 116 zlutovsky User rank is Corporal (100 - 500 Reputation Level)zlutovsky User rank is Corporal (100 - 500 Reputation Level)zlutovsky User rank is Corporal (100 - 500 Reputation Level)zlutovsky User rank is Corporal (100 - 500 Reputation Level) 
Time spent in forums: 22 h 34 sec
Reputation Power: 6
Quote:
Originally Posted by StevenC
That doesn't help me much, as I need to use the path that java's located in to execute some classes in the shell script.

My problem is on some of our boxes we have multiple versions of java and I need to execute a specific version, but that version isn't always install in the same place.



Perhaps I do not quite understand your point. You must locate all your javas and then test their version. Is it so?
I do not know the java, but there must exist some means how to get its version. If so, I would search all possible directories and check for the version of found javas.

You could write something like:


while read DIR; do
NAME=$(find $DIR -name "*java*") # or whatever name it may have
VERSION=$(test the version of $NAME)
if [ $VERSION = ... ] ; then # is it the required version?
do what is necessary
break # out of loop
fi
done <<EOF
possible_directory1
possible_directory2
....
EOF

proceed....

I think, there is no other way but to use the find command, is it?

Reply With Quote
  #5  
Old February 3rd, 2005, 02:26 PM
StevenC's Avatar
StevenC StevenC is offline
PHP & Java Error Master
Dev Shed Beginner (1000 - 1499 posts)
 
Join Date: Jun 2003
Location: My Computer
Posts: 1,218 StevenC User rank is Sergeant (500 - 2000 Reputation Level)StevenC User rank is Sergeant (500 - 2000 Reputation Level)StevenC User rank is Sergeant (500 - 2000 Reputation Level)StevenC User rank is Sergeant (500 - 2000 Reputation Level)StevenC User rank is Sergeant (500 - 2000 Reputation Level) 
Time spent in forums: 1 Day 1 h 31 m 59 sec
Reputation Power: 15
Java is a programming language.
http://java.sun.com

What I need is to locate the path to java 1.3
It's usually in /usr/java131, but I've seen it in a different location.

I need to get the directory that java is installed in so that I can execute a java program.
Problem is, enviroment variables are either not setup, or point to an old version of java (1.1 for example).
So, I need to execute java from it's path.
Ex:
Code:
/usr/java131/bin/java my.package.MyClass

See my problem?
So I need 1 directory returned for java, and not a lot of output as I need to store the directory in a variable.

In order to get java's version, you have to know where it's installed.
The main executable takes in a parameter (-version) to display it's version.

Also, searching for *java* in every directory returns way too much.
Any .java files (source code) come up.

I guess the logic would flow something like this:

Try the normal way of executing a java program (java ClassName).
If that doesn't work, look for java in a couple of possible locations.

Reply With Quote
  #6  
Old February 4th, 2005, 04:12 AM
zlutovsky zlutovsky is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2004
Location: Prague, Czech Rep.
Posts: 116 zlutovsky User rank is Corporal (100 - 500 Reputation Level)zlutovsky User rank is Corporal (100 - 500 Reputation Level)zlutovsky User rank is Corporal (100 - 500 Reputation Level)zlutovsky User rank is Corporal (100 - 500 Reputation Level) 
Time spent in forums: 22 h 34 sec
Reputation Power: 6
Quote:
Originally Posted by StevenC
Java is a programming language.
http://java.sun.com

What I need is to locate the path to java 1.3
It's usually in /usr/java131, but I've seen it in a different location.

I need to get the directory that java is installed in so that I can execute a java program.
Problem is, enviroment variables are either not setup, or point to an old version of java (1.1 for example).
So, I need to execute java from it's path.
Ex:
Code:
/usr/java131/bin/java my.package.MyClass

See my problem?
So I need 1 directory returned for java, and not a lot of output as I need to store the directory in a variable.

In order to get java's version, you have to know where it's installed.
The main executable takes in a parameter (-version) to display it's version.

Also, searching for *java* in every directory returns way too much.
Any .java files (source code) come up.

I guess the logic would flow something like this:

Try the normal way of executing a java program (java ClassName).
If that doesn't work, look for java in a couple of possible locations.



Hi StevenC,

I have written you a pseudocode to search all possible directories for your target and when the target is found to do what is required. I think, this is perfectly what you need, is it? My pseudocode does not output many paths. To be accurate, it does not output any path.

Now I have more info from you, so I put here a better approximation. Consult it with somebody who can write shell scripts and fix it:

:
while read POSSIBLE_DIR; do
TARGET_DIR=$(find $POSSIBLE_DIR -name java131)
VERSION=$($TARGET_DIR/bin/java -version)
if [ "$VERSION" = "1.3" ] ; then
# Version OK, execute the application
$TARGET/bin/java my.package.MyClass
break # job finished, proceed
fi
done <<EOF
/usr
EOF

After the line /usr insert next lines with all directories to search. My test for version need not be correct, I do not know what precisely java -version returns. The same is true for the line that calls java. Correct it if necessary.

The best way to test such scripts is to put the line

set -xv

as the second line (following the colon and execute it. You will see all intermediate results and can locate and fix all possible errors

I cannot do more for you, I have no java to test my solution.

Regards zlutovsky

Reply With Quote
  #7  
Old February 4th, 2005, 08:48 AM
gruntz gruntz is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2004
Posts: 53 gruntz User rank is Private First Class (20 - 50 Reputation Level)gruntz User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 22 h 39 m 25 sec
Reputation Power: 5
find / -name java -print -a -exec {} -version \;

Start at root / or where ever you want /usr or whatever and find name = java. Will print path and on next line will exec java -version. Only problem is it hard to read.

Line look like
-path
-output from java version
-next path
-output from next

Also will print read permission denied errors

Reply With Quote
Reply

Viewing: Dev Shed ForumsOperating SystemsUNIX Help > Looking for java


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 

IBM developerWorks




© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 2 hosted by Hostway