0

I've java 1.8.0_131 by default on my machine but also java 9, so can I run a compiled class with jdk-9? is it possible anything like this:

    java -v path/to/jdk-9 myClass 

Thanks

4
  • 2
    No. But you can use the standard way: /path/to/jdk-9/bin/java MyClass Commented Nov 23, 2018 at 9:28
  • No, this command is not possible. But you can run the class with the java command that comes with your Java9 installation. Commented Nov 23, 2018 at 9:28
  • If I'm not mistaken you can also change the default java version to always use jdk-9 Commented Nov 23, 2018 at 9:36
  • are you using Windows Mac or Linux Commented Nov 23, 2018 at 9:40

2 Answers 2

1

The java command actually invokes the JVM. That JVM starts up, and reads your classes, and runs what you tell it to run.

There is no way to tell the "starting" JVM to actually use a different JVM. java isn't some sort of wrapper that "later" invokes some binary. It is already the binary that starts the JVM.

In other words: what you are asking for isn't possible. A simple workaround can be to define "aliases" on the command line, like java-8 to start your java8 installation, and java-9 to point to that other installation.

Sign up to request clarification or add additional context in comments.

Comments

0

By default java command call the installed java version which can be checked by command:

One way could be update the java:

sudo update-alternatives --config java.  

O/P of above command:

  Selection    Path                                     Priority   Status
------------------------------------------------------------
 0            /usr/lib/jvm/java-8-oracle/jre/bin/java   1081      auto mode
* 1            /usr/lib/jvm/java-8-oracle/jre/bin/java   1081      manual mode


 Press <enter> to keep the current choice[*], or type selection number: 

In your case java 9 will also come. update java version and run java command.

Or you can do directly call your java9 script which you can find ${Java9 Installation Directory}/jre/bin/java -v class.

PS: Above description of commands is based on ubuntu.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.