|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
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
|
||||
|
||||
|
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. |
|
#2
|
|||
|
|||
|
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 ![]() |
|
#3
|
||||
|
||||
|
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. |
|
#4
|
|||
|
|||
|
Quote:
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? |
|
#5
|
||||
|
||||
|
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. |
|
#6
|
|||
|
|||
|
Quote:
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 ![]() |
|
#7
|
|||
|
|||
|
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 |
![]() |
| Viewing: Dev Shed Forums > Operating Systems > UNIX Help > Looking for java |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|