14

I have downloaded and installed oraclejdk11 from oracle official site and modified PATH & JAVA_HOME variable in system environment variable on windows

C:\Users\Aviral>javac -version

javac 11.0.1

C:\Users\Aviral>java -version

java version "1.8.0_102"

Java(TM) SE Runtime Environment (build 1.8.0_102-b14)
Java HotSpot(TM) 64-Bit Server VM (build 25.102-b14, mixed mode)

i know that jdk11 do not contain jre but how can i run a java program from cmd in java 11

2
  • In bin path it is showing java version as 11.01 but how do i execute a program from another folder using java 11 Commented Nov 3, 2018 at 6:22
  • 1
    When you setting JAVA_HOME and PATH, you can access java command globally (means you can use it in any path). Commented Nov 3, 2018 at 6:28

4 Answers 4

18

The JDK includes the JRE which you can launch by using the java executable in the bin folder. You use this executable just like any other executable.

When you type java in the command line it is actually shorthand. It searches your PATH until it finds the first matching java executable. If you want to specify a different java executable you can give the absolute path to the executable.

C:\Users\Avril> "C:\Program Files\Java\jdk-11.0.1\bin\java" -jar path\to\file.jar

You may be wondering, if you've set JAVA_HOME and PATH to point to JDK-11, why does java -version still use Java 8?

Take a look at your PATH and you'll likely find something like C:\ProgramData\Oracle\Java\javapath as one of the first entries (see this). This entry was added automatically when you installed Java 8 and points to the Java 8 executables (java, javaw, and javaws). Since it's before your %JAVA_HOME%\bin entry, it takes precedence. However, ...\javapath doesn't contain javac and that's why javac -version used JAVA_HOME (Java 11).

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

5 Comments

My path variable only contains path of jdk11 bin folder
Then I'd assume java would not be using Java 8. Somewhere, something must be pointing to Java 8. If not, then maybe your environment hasn't been "refreshed".
Thanks @Slaw. I wasted long time to find out why java -version does not show Java 11 even after setting the right path to the bin. Removing C:\ProgramData\Oracle\Java\javapath from the path variable worked!
how to switch to java 11 by default while having multiple java version installed
@neo As long as your PATH points to Java 11, then using java on the command line should use version 11 "by default". If you have multiple entries in your PATH pointing to different Java installations, using java on the command line will always use the first matching entry.
8

bin folder contains all the traditional JRE tools. In Java 11, both JDK and JRE tools are consolidated so that there is no JRE within JDK 11.

Comments

2

In order to execte program from another folder than bin using java 11 you must set the JAVA_HOME path as follows from CMD:

Open CMD as Administrator

Set JAVA_HOME to JDK 11 bin folder

setx -m JAVA_HOME "C:\Program File\Java\..."

3 Comments

i used the command and got "SUCCESS: result value has been saved" but still getting java 1-8 as java version
Because it's wrong. You don't set it to the bin folder. Use the jdk folder.
Moving C:\ProgramData\Oracle\Java\javapath to the bottom , under Java 11 path solved the problem.
0

I upgraded to JDK 11 from JDK 8. After adding Java 11 to the path [ point path up to

bin foler ] and JAVA_HOME [ only upto jdk folder (don't include bin ) ]

successfully,

java -version was still pointing to the previous java version (java 8 in my case.)

Then, I ran a command "setx -m JAVA_HOME "C:\Program Files\Java\jdk-11.0.7"

Now java -version or javac -version both shows java 11.

I hope it helps you too.

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.