Eclipse running in JRE but a JDK is required - eclipse

I always get the above mentioned error when i restart eclipse.I have gone through other posts in stackoverflow and understood how to resolve the problem( i.e by changing configurations in windows>prefernces and editing eclipse.ini file).
But the basic question is what is the meaning of that error?Someone please explain and also provide link to resource on how eclipse works internally with those preferences set.
Thanks in advance..

The JRE runs Java applications. The JDK can also compile Java source code, which is what your Eclipse is trying to do.

Basically Apache Maven requires a Java compiler (javac) which is not part of a Java runtime environment. (JRE) So it asks to use Java Development Kit (JDK) instead because JDKs are including a Java compiler. Nearest explanation for this can be found in below link.
http://wiki.eclipse.org/M2E_FAQ for question "Unable to locate the Javac Compiler Error". How to force Apache Maven to use the Eclipse Java Development Tools (JDT) as its default compiler can be found here.

Related

what is tools.jar replacement ?

I have been receiving the following error on eclipse when i try to build an ant project
com.sun.tools.javac.Main is not on the classpath.
Perhaps JAVA_HOME does not point to the JDK.
It is currently set to "C:\Program Files\Java\jre-10.0.2"
but my JAVA_HOME variable is set to
C:\Program Files\Java\jdk-10
this is the result of the command
echo %JAVA_HOME%
i really tried a lot to solve this problem ,but i don't know much about eclipse,
Edit: i searched some more on the internet and found out that the tools.jar has been removed from the JDK since JDK 9 [link]https://www.reddit.com/r/javahelp/comments/765mwr/installed_jdk_9_and_my_toolsjar_is_missing/
the question now is why is eclipse asking for the tools.jar ,and what is tools.jar replacement ?
I would really appreciate any help
thank you very much
In Java 9 and later, the components that were previously in tools.jar have been turned onto modules. For the javac compiler, you need to use the java.compiler module. This is not a simple drop-in replacement.
If you run into problems with a 3rd-party application (such as Ant) that depends on tools.jar, you need to upgrade the application to a newer version that is Java 9+ compatible.
According to my reading of the Apache Ant site, that means you need Ant 1.10.x. Check the site's download page to see what is currently recommended.
If you are using openJDK11 you can probably use lib/jrt-fs.jar as a replacement of tools.jar

What is the purpose of Java JDK to Eclipse?

I've just installed Eclipse, after i installed the java JDK.
The Getting Started guide (in Eclipse) says i should reference my JDK installation in Window>Preferences>Java>Installed JREs, but that a JRE would also work.
Select the Java > Installed JREs preference page to display the installed Java Runtime Environments. Confirm that a JRE has been detected. By default, the JRE used to run the workbench will be used to build and run Java programs. It should appear with a checkmark in the list of installed JREs. We recommend that you use a Java SDK instead of a JRE. An SDK is designed for development and contains the source code for the Java library, easing debugging.
There was already a JRE set up there (not a JDK), so i did nothing and tried to compile a Hello World (just to see what would happen). To my surprise, it compiled!
I searched a little bit and it looks like this works because Eclipse has a built-in Java Compiler. I tried debugging using the same eclipse set up, and it was also successful.
So, what is the difference between setting a JDK and JRE there? Why is it important to download the JDK, since in my default configuration Eclipse doesn't seem to use it?
Probably the main difference is you get the source to all of the Java runtime libraries (with the JDK) which can be a big help. I always use the JDKs for that reason.
Also if you are debugging, this will allow you to meaningfully step into Java runtime libraries.
There are a number of tools that come with the JDK that don't come with the JRE - JConsole (http://java.sun.com/developer/technicalArticles/J2SE/jconsole.html) springs to mind. This for example can help you understand & monitor the memory usage of your application and so on. Either way if you head into unfamiliar territory, I highly recommend you follow the Eclipse suggestion and use the JDK!
JDK is equipped with different helpful tools, as DotMasta mentioned. Eclipse's "version" of JDK is called JDT. Apart from range of shipped tools, there are also differences between javac and Eclipse built-in compiler ecj, so check here to see the comparison. One of the most important differences is that javac is strict, i.e. with ecj you can create a class file even in case of errors in code, which is perfectly suitable for testing phase, but not for launch :)
JDK contains software development tools which are used to compile and run the Java program.
Plenty of classes and methods in standard jdk library
Javac java compiler
Diffrences and why you will need this?
JDK includes the JVM, standard class libraries, and several other tools that a developer needs in order to create a Java program.
JRE includes the JVM, as the JRE provides some standard libraries and the JVM which can be used to execute a Java program.
You can even look there: http://en.wikipedia.org/wiki/Java_Development_Kit

Eclipse Ant JDK issue

I have given atask to buld the ant file.
The interestuing path is there is no JDK installed, only JVM is installed.
It seems to me that Eclipse is using internally JDK.
Now, when I run the ant file it's throwing me an exception Unable to find a javac compiler; so how Can I fix this ?
I found this in the current Eclipse help: Using the ant javac adapter
The Eclipse compiler can be used inside an Ant buildfile using the javac adapter. In order to use the Eclipse compiler, you simply need to define the build.compiler property in your buildfile.
This might also work in Eclipse 3.4. Ganymede help files aren't online.
Edited to add the ant compiler property definition:
<property name="build.compiler"
value="org.eclipse.jdt.core.JDTCompilerAdapter"/>
Eclipse JDT (Java developement tool) is able to run on top of a JRE only as you said because it embed its own Java compiler. I think you can use this compiler to compile code outside Eclipse but I am not able yet to find ressources on the web explaining how to do this.
Moreover I am not sure you will be able to tell Ant (here I speak about Ant running outside Eclipse, because Eclipse also has its own internal Ant runner) to use this compiler instead of using the javac compiler find in default location.

How do i find out the JDK version Eclipse is using?

I see JRE all over the place, but i can not be sure which JDK is compiling my code. How do i find out?
You can still check/set which JDK version you want to compile to. If you go to Window->Preferences, then click "Java" from the menu on the left and then "Compiler". The first setting allows you to see which JDK version is being complied with.
I know this doesn't directly answer your question since JDK isn't actually compiling it, but hopefully it helps!
Actually Eclipse has its own compiler. You can develop java apps using only the JRE and Eclipse
You don't find JDK explicitly mentioned anywhere because way to point to a JDK is under the name of 'Installed JRE'. That is Window > Preferences > Java > Installed JREs. This is useful when using m2e plugin.
secondly apart from having it's own built in compiler, it is recommended to you install one of your own to support development of Java programs. Except below from eclipse wiki page :
If you intend to use Eclipse for Java development, then you should install a JDK

My Eclipse can compile but I can't find a JDK!

I've installed Eclipse on a Windows machine some time ago. A couple of days back I was doing some Java coding and I noticed I don't have a JDK, but still Eclipse could compile & run the Java classes. Does it have a compiler included?
Yes Eclipse contains it's own incremental compiler.
An incremental Java compiler.
Implemented as an Eclipse builder, it
is based on technology evolved from
VisualAge for Java compiler. In
particular, it allows to run and debug
code which still contains unresolved
errors.
For some history take a look here:
http://onjava.com/pub/a/onjava/2006/06/28/whats-new-in-eclipse-3-2-java-development-tools.html
Yes. And here's some more characters.