what is tools.jar replacement ? - eclipse

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

Related

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

How to debug JDK source

I have one very tricky issue that I am not able to sort out right away. I have to debug JDK source to see whether I can move further. The standard JDK library does not come with Debug symbol included.
Can anyone tell me where I can download the JDK debug version? I am using eclipse and debug remotely, JDK 1.5 or 1.6 are both fine for my case. If not, I probably have to follow a googled guide to re-compile the rt.jar.
To be more clear, I want a JDK distribution with debug enabled. Where can I download it?
I'd recommend you just to compile the classes you need with debug information and put your version of *class files of JDK to bootstrap classpath. Configure your IDE with attached sources (src.zip). This should work.
I hope you do not really need whole JDK, just selected classes.

Eclipse running in JRE but a JDK is required

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.

Check project for use of code introduced in Java 7

On my development machine, I have JDK 1.7 installed, but we are packaging software for use with Java 1.5 and 1.6. It's easy to set the -source and -target options so that the syntax is forced to be a particular version, and the output class is interpretable by a particular VM. But there are other version-isms that are biting me, like the 2-argument constructor AssertionError(String, Throwable) and various other subtle changes.
The one solution I know of is to install every different JDK (1.5, 1.6, 1.7) so that Eclipse can exactly match the execution environment for me. Is there any other way to detect these problems? Bonus points if it's an Eclipse or Maven tool.
How about the Codehaus anmial-sniffer maven plugin? I haven't had reason to try it yet, but thought it looked interesting.
does this tool help? It's command line, I have seen people using it to detect java7 being used.

How install multiple JDK on Windows?

I want to install JDK 1.5 and 1.6 on XP, is it possible? how to do it
Also, I am using Eclipse how to setup using different JDK for different projects?
thanks.
You may install different JDKs easily: just specify different folders.
You can setup the installed JDKs in Eclipse Window/Preferences/Installed JREs
You can pick the JDK and Java version for every single project in Project/Properties/Java Compiler
I have solved this by creating batch files for different Java versions.
I have installed the Java versions I need to have
Whenever, I need to use Java I run the appropriate batch file and set the environment variables to work with that Java version.
Java 8.bat
#echo off
echo Setting JAVA_HOME
set JAVA_HOME=C:\Program Files\Java\jdk1.8.0_121
echo setting PATH
set PATH=%JAVA_HOME%\bin;%PATH%
echo Display java version
java -version
Java 10.bat
#echo off
echo Setting JAVA_HOME
set JAVA_HOME=C:\Program Files\Java\jdk-10.0.2
echo setting PATH
set PATH=%JAVA_HOME%\bin;%PATH%
echo Display java version
java -version
Why? There is an option (can't remember where exactly - right-click on your project) that allows you to set the target JDK level. I use this when developing GWT applications.
Try using sdkman. Even though the installing on Windows is a bit 'tricky' but there are several options.
https://sdkman.io/install
There was a big mess with different incompatible JDK and JRE from 90s when Java was created and still this problem exists.
The main rule is when you type in console:
java -version
and
javac -version
the result should be the same then you sure both JRE and JDK (JSDK) are compatible, so when you compile you can rut it without any problems.
JAVA_HOME and PATH are essential for many console applications
and some GUI tools might use those variables as well but often is possible to alter default settings in GUI application instead of messing with environment variables. Also CLASSPATH still sometimes are used as well, however better use ANT as compiler than javac directly.
You can install multiple JDK and JRE but each one should to have its own separate folder, the default should be usually ok.
Worth mentioning that every JDK have JRE included and it instal in separate folder and as separate APP in Windows Control Panel -> Applications to be more confusing, so basically developer will never have to download and install JRE. Do not use Java update application which might cause problems after update some apps might not work, just do it manually.