Are both the JRE and the JDK required to run a JAR

2020-02-27 11:37发布

问题:

It is possible to run a JAR file locally. The next step is to run it on a different PC.

The question is whether the JRE, the JDK or both are required to run the JAR file?

回答1:

The JDK contains the JRE.

Most program only need the JRE (Java Runtime Environment) but some programs need the Compiler at runtime in which case you need the JDK.

If you have the JDK, you don't need the JRE as well.



回答2:

To run a jar file you only need java.exe(windows). JDK is the development kit for Java and JRE is the runtime. JDK contains JRE.



回答3:

In the comments on the accepted answer nobalG asked, "Why the compiler is needed if jre is already there?"

At the time of writing I did not have enough reputation to comment, so I replied here instead.

I had a situation where I wanted to write code that compiles other code at runtime and then uses that compiled code. In my case I was creating a tool that could take a test class based on a particular framework, compile it, load the class, and extract test data from it so that the data could be used as part of an end-to-end test. In order for this tool to run properly it must be run with the JDK so that it can use the Java compiler.



回答4:

To run a jar file you only need the JRE. You can run the jar file with the following command:

java -jar [jar file Name]



回答5:

JRE is enough to run

JDK is used for development



回答6:

You only need JRE.

If the jar file you are trying to run has the Main-Class: <classname> header present in manifest file, then you can simply run the jar file by the command:

java -jar [your jar file name]

If the manifest file does not have that entry (and you know the fully qualified class name of the class containing main function), then you can run the jar file by the command:

java -cp [absolute path to jar file] [full qualified class name containing the main function]



回答7:

You need a JRE but not the JDK. The JRE is the java runtime environment and java code cannot be executed without it. The .jar is a compiled java file can and this needs the java runtime environment to be run.



回答8:

You want to run the jar file; so you just need Java Runtime environment ( i.e. JRE).



标签: java jar