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.
Related
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
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
In Eclipse when i create new Java Project, i see options like:
Now i want to know, what is the safest option to use considering when i export jar file any user will be able to use it. If selecting the shown option, does that mean if someone has JRE 1.6, he will not be able to run that jar file, or is it backward compatible??
As such my project has no specific 1.7 dependencies.
This is very broad question, which JRE to use depends on your requirement. If you have multiple projects, each specific to a JRE, then you can use project specific JRE. If you are happy with eclipse default JRE you can continue. It is purely your decision.
Someone with JRE 1.6 should be able to run on 1.6 as long as compilation level is set to 1.6 (This may flag if your code has any 1.7 features which are not part of 1.6).
If you use features which are specific to JDK 7 (such as the new NIO.2/The path API ) then they most likely won't work on java 6. Furthermore Java 6 has been tested and withstood the test of time as a result most (if not all) bugs have been ironed out. Java 7 is still fairly new and even after it was released there was a pesky bug that showed up couple of days after release which had to the with the loop optimisation. So unless you specifically need JDK7 features I'd suggest you stick with JDK6, on the other hand if your project is not mission-critical then you might experiment with the new JDK7 features given that your user base has JRE 7. Just my 2 cents...
Eclipse is said to have an inbuilt jdk, can we use it outside eclipse for simple javac eg through command prompt?
I may be wrong in assumptions please guide on that too
Eclipse has an inbuilt Incremental Java Compiler not a full JDK as far as I know.
More information can be found in the documentation and the JDT core page
Perhaps you are referring to the built-in compiler in Eclipse. Different ways to use this is documented here
I've set up Eclipse in Ubuntu 10.04. I currently have the OpenJDK JRE installed but don't have the JDK needed to compile.
However, the code written Eclipse still compiles. Is this a standard compiler included in Eclipse? I've searched through the package manager and don't seem to have any of the JDKs installed...
Note: running 'javac' in the terminal doesn't work.
If you download Eclipse from eclipse.org, it will bring everything it needs to work with it.
Eclipse is designed to be a standalone package which only minimally uses the components of the system on which it runs. This helps to provide the same experience everywhere.
On the down side, it makes Eclipse larger and more RAM-hungry, and also makes keeping Eclipse up-to-date a separate chore from keeping the rest of your system current.
You can see what Eclipse is using by going into your project build settings. It may be using its built-in compiler, which lets it easily highlight errors, rapidly do incremental builds, and such.
For what it's worth, the Java compiler included in Eclipse is a derivative of IBM's jikes compiler. It's not really so important what brand it is; what's important is that it is an incremental compiler; it sort of keeps your whole program inside itself and if you change a class (maybe even just a method) it will re-compile just the bit of code you've changed.
If you look at NetBeans, when you save a changed file it will call up an ant task to re-compile (via the JDK) at least the class you changed, maybe more. When your classes start to get bigger, you'll find (or at least I did) that this takes up a lot of time; I'm very happy with Eclipse (and IBM) for doing things the way they do. Without the external compilation step, code changes take place a lot more quickly.
Yes, the compiler has some differences compared to the "standard" compilers by Sun Oracle and OpenJDK. But I've never experienced a problem as a result. Still, for production use I'd recommend formally compiling using ant or maven and the JDK. Just to be on the safe side.
Eclipse, like unfortunately most substantial applications that require a JRE/JDK to run include it in the distribution.
For a good time on Lucid Lynx:
$ locate javac
You'll need to another source to the repository. Run the following commands.
sudo add-apt-repository "deb http://archive.canonical.com/ lucid partner"
sudo apt-get update
sudo apt-get install sun-java6-jdk
There's a package for eclipse called eclipse and the java compiler (javac) is in sun-java6-jdk
Install it with sudo apt-get install sun-java6-jdk or sudo apt-get install eclipse
Eclipse does come with its own compiler, but I wouldn't recommend using it for distribution of source code. I'm not intimately familiar with it, but I've been told that it doesn't perform optimizations as well as other compilers and there are some known bugs in it. I can't dig up anything that supports this, but I do like the idea of building using the same JDK/compiler and running on the same JVM that your users are.
I would suggest obtaining the Sun JDK for Linux. You should be able to get it from the Synaptic Package Manager if you open the universe repositories.