JDK for Eclipse(in windows platform) - java

My qustion is really simple, all in the title.
After some tests I found that by given a JRE/bin directory in the path(environment variable) , Eclipse can run normally with no problem. And Eclipse will never try to find the JRE by using JAVA_HOME variable.
And in eclipse, I know that I can add installed JREs in the window preference and choose a JDK folder instead of a JRE folder. And for each project, we can change the compiler level.
Since Eclipse can also compile the codes, when is JDK used? Debug? or what?

Eclipse uses its own compiler to compile Java code. It is different than the javac compiler that comes with a JDK. In fact, you don't need a JDK to compile and run normal Java projects in Eclipse. A JRE is obviously needed to reference the required Java libraries.
However if you are using Maven or some other tools that sometimes depend on a JDK component, then you need to install a JDK on your machine. For example, Maven has an option to rely on the tools.jar that comes shipped with a JDK.

Eclipse uses the JRE you specified as default or per project settings. This could be a (only) JRE installation or a JRE from a JDK installation.
I think the more interesting question is: When should I use a JDK instead of an JRE?
The JDK includes tool that are not included in the standalone JRE. E.g. the javadoc.exe for exporting the documentation from javadoc annotated comments in the code. This Program is not included in a standalone JRE. so if you want to export your javadoc documentation you need to add an installed JRE based on a JDK installation first, so Eclipse is able to use the javadoc tool.

It could be a little hard to give a thorough answer to this but I know that at least for using Maven/m2e Eclipse needs to be run in a JDK.

First of all eclipse is a java code it wouldn't run without java installed to prove it (on your personal expence) copy the eclipse folder elsewhere and uninstal the JDK and try to run jave it wouldn't it would output the error message no JDK but instal JDK and run eclipse from the copied location it would run as a first time asking you about the workplace directory!.

Related

Eclipse not using the specified JDK

Eclipse was so far using the installed jre "jre1.8.0_261". I want eclipse to use jdk. I have changed the eclipse.ini and have added the following :-
-vm
C:\Program Files\Java\jdk1.8.0_191\bin\javaw.exe
Moreover, I have changed the windows preferences with Installed JREs as the one offered by the jdk "jdk1.8.0_191". The java build path has been also aligned to use "jdk1.8.0_191" .
However under the configuration of Eclipse IDE Installation, I could still see that Eclipse is using the previously used jre version as vm.
-vm
C:\Program Files\Java\jre1.8.0_261\bin\server\jvm.dll
However, I want Eclipse only to use the mentioned JDK. Is there any solution to this?
Eclipse can use one Java distribution to run Eclipse, and any Java distribution to compile code with. It can certainly use a different distro to run than it uses to compile code. You can even have different projects using different distros.
It's probably best to have a single "-vm" option in the "eclipse.ini" file, which specifies the latest version of Java (I suppose it's possible it could just be a JRE, but I haven't tried that). Then, install the JDK of whatever version you need, and specify that in the "Installed JREs" list. Make sure that the page underneath that, "Execution Environments" maps the "JavaSE-1.8" to your installed JDK.

java version in not match for eclipse

I had java version 8 previous and my eclipse worked just fine. But now I have java version 7 and I can't open eclipse on my computer. What should I do? please help.
I think there are two options:
Upgrade to Java version 8 (or newer).
If you can't do that, downgrade to a version of eclipse that supports Java 7. eclipse 4.5 (Mars) (or earlier as noted on the linked page), as of eclipse 4.6 (Neon) Java 8 is required.
I feel I should note that newer versions of Java (and eclipse) can still target Java 7 (and many earlier versions).
But now I have java version 7 and I can't open eclipse on my computer. What should I do?
Use versions that work together. When you for example look at your second screen shot, it says something like "requiredJavaVersion=1.8" or so.
In other words: you can't just come in and run eclipse with any version of java.
The other answer gives you the required details.
And a final note here: in case you tried to start eclipse with that older JVM in order to "allow" to ensure that eclipse won't allow "java 8" stuff in a project: that isn't the right way then. Instead: eclipse allows you to "define" JDKs to be used for your project. So you can easily tell eclipse: "I have a Java7 jdk sitting here, please use that for project X".
You do not need to run eclipse itself with a Java7 JVM in order to use a Java7 JDK for an eclipse project!
There will be a file under the Eclipse installation directory named as eclipse.ini.
It will launch the eclipse for that specific jdf and you can change the path to your jdk7.
Hope it helps.
It depends basically on which version of the eclipse you have.
If you have eclipse 4.6(Neon) or the latest version, then you must need a newer JDK version of Java (>=1.8 which you need to download). Or If you want to roll back to an older version of Eclipse then consider downloading eclipse 4.5(Mars).
Or If you have an eclipse version of 4.5(Mars) or older then see in eclipse.ini
-Dosgi.requiredJavaVersion = 1.8 and change it to -Dosgi.requiredJavaVersion = 1.7 which can be found in the folder containing eclipse.exe file.

How Eclipse work with and without JDK?

I have Eclipse for Java installed on my 64-bit Windows 10. And since than, I was able to do Java development without any configuration.
Previously, the automatically build is selected by default. But when I manually delete the .class files, and want to build again, nothing happens.
When I try to run the program, it was not surprised that the error message says that it cannot find the class files.
Notice that, from the beginning, I didn't configure JDK in Eclipse, and it worked.
I found some source on stack overflow that says, Eclipse has its built-in compiler such that it does not need the javac in JDK.
Can I develop Java programs if I have only JRE installed?
But why after I deleted the .class files, the built-in compiler does not work ?
Regarding the JDK: if you are using Eclipse, then you don't need JDK because eclipse has it's own compiler. However for some plugins like Maven to work JDK will be required.
Regarding building the project: Have you tried cleaning and rebuilding the project?
Clean command is available under Project tab.

The type java.util.Comparator cannot be resolved

The type java.util.Comparator cannot be resolved. It is indirectly referenced from required .class files
I recently installed Java 8. While executing an application, I got above mentioned error can you please help me.
I am using:
Java - jdk1.8.0_51
Tomcat - apache-tomcat-5.5.26
Assuming you are using some IDE, like Eclipse. When you are using jdk 1.8 with IDE, you need to update your IDE to support version 1.8.
It does not matter you are using new jdk's feature or not, but compiler has to load new JRE files in order to compile your project.
If you are using IntelliJ, go to:
File/Settings/Build, Execution, Deployment/Compiler/Java Compiler
and make sure "Use compiler" and "Project bytecode version" have the right configuration.
I had this same error and tried many things to fix it, but finally worked was remarkably simple: It turns that I was simply using an older version of Eclipse that did not support a "Compliance Level" setting of Java that was as high as my JRE. I merely upgraded to a newer version and the problem went away.
From what I understand about "Compliance Level", it's the version of Java that your program is supposed to work on. That much I found out from reading stuff on the net. But what the other solutions did not mention is that your IDE has to be able to be set to a level as high as your JRE. In my case, I was using JRE 1.8, but the highest compliance level my older IDE supported was 1.6.
IMO, this situation should have been flagged as an error by Eclipse. But as it was, I wasted two nights trying to figure this out.
Your project build path could be referring to a jre instead of JDK.
Go to your build path. (In eclipse right click and choose build path).
Go to your libraries and replace the jre with the jdk.
pom.xml version is 1.6?
If this is the way,you would replace jdk1.8 with jdk1.6 ,and environment variable into jdk1.6。
Same strange problem occurred. It turned out that wrong jdk version was in JAVA_HOME
There you are I had the same issue but moment I saw your question i got it fixed. problem is you are not using old version since there is mismatch of referencing with new version. this error will come.
Work around:
1. Change your java version to old.(In my case I had to change to 7)
2. Update each libray and jar file compatible to java 8 that way it will refer java not class file
Here is the image of environment variable in my problem
check if build path is set to run with JDK. It is important point that JKD is software development kit while JRE is a runtime env. Advice who had this problem see the different between JDK, JRE and JVM. https://www.guru99.com/difference-between-jdk-jre-jvm.html

How Intellij runs without any JRE installed?

I've read here that Intellj is written in java,
how then it can run without any JRE installed on the machine?
It cannot. Requirements clarifies that at least JDK 6 must be installed.
I guess some distributions might have it bundled but it is not the case for standard one version 12.
IntelliJ IDEA comes with JRE. Just look inside IDEA installation folder where you can find jre folder.

Categories