Java - Command line to run a class with another jvm
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
java
add a comment |
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
java
2
No. But you can use the standard way:/path/to/jdk-9/bin/java MyClass
– JB Nizet
Nov 23 '18 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.
– Henry
Nov 23 '18 at 9:28
If I'm not mistaken you can also change the default java version to always use jdk-9
– Andreas
Nov 23 '18 at 9:36
are you using Windows Mac or Linux
– preciousbetine
Nov 23 '18 at 9:40
add a comment |
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
java
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
java
java
asked Nov 23 '18 at 9:26
Jacopo SabatiniJacopo Sabatini
1
1
2
No. But you can use the standard way:/path/to/jdk-9/bin/java MyClass
– JB Nizet
Nov 23 '18 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.
– Henry
Nov 23 '18 at 9:28
If I'm not mistaken you can also change the default java version to always use jdk-9
– Andreas
Nov 23 '18 at 9:36
are you using Windows Mac or Linux
– preciousbetine
Nov 23 '18 at 9:40
add a comment |
2
No. But you can use the standard way:/path/to/jdk-9/bin/java MyClass
– JB Nizet
Nov 23 '18 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.
– Henry
Nov 23 '18 at 9:28
If I'm not mistaken you can also change the default java version to always use jdk-9
– Andreas
Nov 23 '18 at 9:36
are you using Windows Mac or Linux
– preciousbetine
Nov 23 '18 at 9:40
2
2
No. But you can use the standard way:
/path/to/jdk-9/bin/java MyClass
– JB Nizet
Nov 23 '18 at 9:28
No. But you can use the standard way:
/path/to/jdk-9/bin/java MyClass
– JB Nizet
Nov 23 '18 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.
– Henry
Nov 23 '18 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.
– Henry
Nov 23 '18 at 9:28
If I'm not mistaken you can also change the default java version to always use jdk-9
– Andreas
Nov 23 '18 at 9:36
If I'm not mistaken you can also change the default java version to always use jdk-9
– Andreas
Nov 23 '18 at 9:36
are you using Windows Mac or Linux
– preciousbetine
Nov 23 '18 at 9:40
are you using Windows Mac or Linux
– preciousbetine
Nov 23 '18 at 9:40
add a comment |
2 Answers
2
active
oldest
votes
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.
add a comment |
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.
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53443840%2fjava-command-line-to-run-a-class-with-another-jvm%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
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.
add a comment |
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.
add a comment |
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.
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.
answered Nov 23 '18 at 9:39
GhostCatGhostCat
91.1k1688147
91.1k1688147
add a comment |
add a comment |
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.
add a comment |
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.
add a comment |
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.
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.
answered Nov 23 '18 at 10:07
saurav omarsaurav omar
767
767
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53443840%2fjava-command-line-to-run-a-class-with-another-jvm%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
2
No. But you can use the standard way:
/path/to/jdk-9/bin/java MyClass
– JB Nizet
Nov 23 '18 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.
– Henry
Nov 23 '18 at 9:28
If I'm not mistaken you can also change the default java version to always use jdk-9
– Andreas
Nov 23 '18 at 9:36
are you using Windows Mac or Linux
– preciousbetine
Nov 23 '18 at 9:40