简体   繁体   中英

How to use a different version of Java on the command line

OK I have 2 different version of Java install on my machine (CentOS 5), the system defaults to 1.5.0_14 but I need to run a command on the command line with the newer version of Java. How can I pass the newer version in the command line?

Sorry this is such a n00b question but I googled and didn't find anything, thanks.

Just use the full pathname for your java executable, rather than allowing the OS to pick one based on your PATH.

Use the absolute path to the java executable:

/opt/java-1.4/bin/java

You could make a link to the file:

ln myJava1 <java version you want>
ln myJava2 <java version you want>

and then when you want one or the other, type the appropriate link.

Or if you want a standard java and just have the other for one offs, you could do:

ln theJava <myJava1 or myJava2>

and then just use theJava (or whatever you want to call it

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM