o7planning

Configuring Eclipse to use the JDK instead of JRE

  1. JDK vs JRE
  2. Use JDK instead of JRE

1. JDK vs JRE

JRE: Java Runtime Environment. It is basically the Java Virtual Machine where your Java programs run on. It also includes browser plugins for Applet execution.
JDK: Software Development Kit, It's the full featured Software Development Kit for Java, including JRE, and the compilers and tools (like JavaDoc, and Java Debugger) to create and compile programs.
Usually, when you only care about running Java programs on your browser or computer you will only install JRE. It's all you need. On the other hand, if you are planning to do some Java programming, you will also need JDK.
Sometimes, even though you are not planning to do any Java Development on a computer, you still need the JDK installed. For example, if you are deploying a WebApp with JSP, you are technically just running Java programs inside the application server. Why would you need JDK then? Because application server will convert JSP into Servlets and use JDK to compile the Servlets. I am sure there might be more examples.

2. Use JDK instead of JRE

If both JRE and JDK are installed on your computer, the Eclipse will use JRE as a a default tool to build your projects. But some projects or functions force you to use the JDK instead of the JRE. For example, you have a Maven application, and you want to use the "Maven install" function to package the application into a JAR/WAR file, an error may appear with the message as follows:
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.7.0:compile (default-compile) on project Translate: Compilation failure
[ERROR] No compiler is provided in this environment. Perhaps you are running on a JRE rather than a JDK?
[ERROR] -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoFailureException
My advice: It is best to use the JDK on all projects. Thus, how do you need to configure on Eclipse?
On the Eclipse, select:
  • Window/Preferences

If you find that the Eclipse uses JRE, you need to remove JRE and add JDK.
Select the JDK folder on your computer:

Java Basic

Show More