I have jre7 installed on my pc.
In Eclipse Kepler I created a project with compiler compliance level 1.5.
The source compatibility setting is 1.5 too. But this setting not works.
I can wirte code which using methods that were declared in 1.6 or later. For example:
String s = "aaa";
boolean b = s.isEmpty();
The method isEmpty() in java.lang.String is since 1.6.
Of course, when running the generated class file with a real jre 1.5 enviroment, i got a NoSuchMethodError exception.
Here is my source and settings:
How can I fix this? Or is it an Eclipse bug?
The settings are releated to the -source and -target flags for the javac compiler which enables backwards compatibility (for an explanation, see for example this SO question and answer).
This is mostly a technical option and not a feature, i.e. these settings in Eclipse were never intended to free you of the burden of knowing what is and is not available in an old JRE. But Eclipse does provide you the option to make it so and even shows you a warning message at the bottom of the Java Compiler options screen on how to make it so (and yes, that does involve downloading and installing the old (target) version of the JRE - there is no way around that).
Whether or not a method from Java 6 is available depends on the JRE library that you are using.
Go to "Java Build Path", into the "Libraries" tab, remove the "JRE System Library" of Java 7. Then, click "Add library..." and go though the dialogs for adding a Java 5 JRE Library. (Of course, a Java 5 JRE has to be installed for that...).
(Note: There is also a message about this in the right screenshot, at the bottom...)
Related
I have now a little experience in Java, so I wanted to take the next step to an IDE, so I installed the Eclipse IDE. (If it matters, I am using mac.)
But this does not seem to work right, as soon as I create a new class, the error occurs:
The project was not built due to "release 6 is not found in the
system". Fix the problem, then try refreshing this project and
building it since it may be inconsistent HelloWorld
I already tried to change some of the properties in the class or selecting different settings, right now I use the execution environment JRE: J2SE-1.5.
Thank you for taking your time!
Well it is basically telling you that you don't have the right version of Java JDK installed. THIS page seems to imply the current version of eclipse needs 1.8 - not the 1.6 you're talking about. I am unsure though how you could have specified one that isn't installed. Maybe you only have the JRE (java runtime environment). You will definitely need the JDK (java development kit) because that is what has the java compiler in it.
It's been a long time since I used eclipse but when you created the project you should have been prompted to specify the java version. Now try right clicking on the project and choose Build Path... Configure Build Path. On the Java Compiler tab (left side) you should be able to change the configured Java to whatever you have installed.
I got this error when the selected version under Preferences > Java > Compiler > Compiler compliance level was higher than the selected version under Preferences > Java > JREs > Installed JREs. There was a small (very small) warning at the top of the JREs page warning me that there was an incompatibility with the compiler compliance level.
The options for compiler compliance level includes all versions up to the version that Eclipse itself is using, even if you don't have a specific JDK with that version, so you can get warnings for JDK releases that you definitely don't have.
I updated the compiler compliance level to be the correct version for my project and that got rid of the problem.
I'm new to java programming and I haven't used any java IDE,
I intalled Java JDK 8 on my computer and been doing some coding through Notepad++ and compiling it via cmd commands.
Since now that i'm comfortable coding manually, I wanna try to use IDE and decided to get the latest "Eclipse IDE for Java Developers". what I got is actually a .zip file no installation or something which is odd.
My question is does the eclipse uses the JDK I installed on my computer or it has it's own? if so how would I know which version of java does my eclipse run?
and if does use the JDK on my computer, if I want to update the JDK intalled on my computer do I have to uninstall the old one or I can just overwrite it with the new JDK build??
Thanks,
CC
Eclipse uses externally installed JDKs to run itself (it's written in Java, after all) and to provide the core libraries for the code you write (such as the java.* packages). By default, Eclipse will use its own compiler, ECJ, that has deep integrations with the IDE to provide features such as detailed error reporting and sometimes even partial compilation of invalid classes.
It's possible to override the compiler via some plugin (for example, you can explicitly specify a compiler in a POM via m2eclipse, though the default there still uses ECJ), but that's uncommon if you're still compiling Java code.
Eclipse has support for using multiple JDKs, for example for different versions (maybe you have backwards compatibility with 1.6) or different vendors. Depending on how your OS is set up, if your main JAVA_HOME is set through a symlink, you may not need to update Eclipse at all if you perform a minor upgrade. In the case of a major upgrade, though, you will probably need to go to "Installed JREs" and add or modify an entry.
1.the jdk you installed in your computor is global situation. it can effect anywhere if you have configured the environment variables.
2.configured the environment variables,run cmd like this,the java version will be show,enter image description here
3.generally, one JDK , one computor is enough.if you want to update jdk, just download new jdk and override the old jdk .
For some time I tried to understand, but I still don't get exactly what "compiler compliance level" for a project in Eclipse means. I looked all over this site and Google and couldn't find an answer I could understand.
Let's say I want my program to be able to run on JRE 6.
I can do: Project > Preferences > Java Build Path > Libraries, and set the JRE library I use to JRE 6.
Why isn't this enough?
I never understood why I also need to set the compiler compliance setting to JRE 6.
I'd like to understand the difference between using JRE 6 in a project, and setting the project's compiler compliance setting to JRE 6.
What exactly does compiler compliance level mean?
The compiler compliance setting tells the compiler to pretend it's a different version of Java.
The Java 8 compiler will produce class files in the Java 8 version of the class file format, and accept Java 8 source files. JRE 6 can't load this version, because it was created after JRE 6 was.
If you set the compliance level to "JRE 6", it will instead compile Java 6 source files into Java 6 class files.
It's like saving a Word document as "Word 97-2003 format" - so that Word 97-2003 can read your document. You're saving the class files in Java 6 format so that Java 6 can read them.
It tells you what version of the JDK you are adhering to; specifically, which JRE are you targeting with your build.
It is the MINIMUM JRE needed to run your code
The Java compiler can compile code that will run on prior versions of the JVM. Even if you have JDK 6 installed, you could be writing code targeted for people that use JDK 5. The Compiler Compliance level tells Eclipse to use appropriate settings when compiling your project to ensure you code will work on the target JVM you specify. By default, if I recall, Eclipse picks Java 5 Compliance. If you want to use code features specific to Java 6 or Java 7, you will have to change the compliance level.
The simplest way to describe the "Java compiler compliance" setting is that it determines which Java Virtual Machine instructions may be used in the "compiled" Java code ... and which library class versions are to be used. Each release of the JVM (and its libraries) may introduce new instructions (the VM) or adjust the class libraries that are delivered along with the JVM.
You should set the setting to the lowest level of JVM that you expect your product to be run on.
I wanted to start learning java but Eclipse is giving me some trouble.
First of all I'm a beginner with Java with little to no knowledge about it. I want to use 'JavaSe-1.7'. I have no clear reason to use it besides using the latest version. After downloading Eclipse (Eclipse IDE for Java Developers) I created a new Java project and selected 'use an execution eviorment JRE : JavaSE-1.7'. This directly popped the notification saying 'The default compiler compliance level for the current workspace is 1.6. The new project will use a project specific compiler compliance level of 1.7.'. I finished creating the project and started following some tutorials.
However I noticed directly I have 2 errors which dont explain anything or have a source. I ignored it and started typing and tried to import 'java.io.console' however it said 'The import java.io cannot be resolved' and I have no idea what is the cause of it neither how to fix this.
Would like some instructions into the right direction.
Thanks in advance
Check your Eclipse preferences: Java -> Installed JREs. The one that you're using should be marked and it should be a JDK not just a JRE.
Also check your project's build path: Right click on the project -> Properties -> Java Build Path
Check in the "libraries" folder whether the JRE System Library is present and if not add it using "Add library"->"JRE System Library" and then select the correct one (from an installed JDK).
You may not have your JDK/JRE set up correctly.
Check the following:
Did you install a JDK or just the JSE? The JDK is needed to compile .java files to .class files. Without it, you can only run java programs, not develop them. If not, download and install it from Oracle website.
Check in Eclipse, if you have the JRE installed there as well. You just need to specify the path to the installation. You can reach this screen via the "Window->Prefrences" menu. see this screenshot:
The message you receive about project specific compiler compliance level is not a problem, it just means that your workspace is set up to comply to java 1.6 but your project will comply to java 1.7 standards. Also, Java 7 in general is no problem whatsoever.
Paths may differ, especially if you're not running a *nix OS. Just point the location to where you installed your JDK.
I am trying to config my eclipse (Helios) use jdk 7 to compile my code. I didn't install jdk 7 on my Windows XP. But I include all of the jdk contents with my project. It seems the solution provided in this post doesn't work. Compile java code needs JDK. the JRE is enough for running the compiled code. I think we need a way to configure the JDK to be used not just JRE. I tested with a JDK 7 new feature, String in switch, I can compile it in my batch file compile system but cannot use eclipse to compile it.
any idea?
This is what I did to make Eclipse 3.x works with Java 7.
install Java 7 in another machine and then copy the JDK folder into my java application 3rdparty directory (so my machine still use Java 6);
download the Eclipse 3.7.1 from here: eclipse 3.7.1
configure Eclipse by following steps in this post (select 1.7 in Compiler compliance level under the Java Compiler entry);
At least I can use String in Switch now in Eclipse.
Good luck.
Compile java code needs JDK. the JRE is enough for running the
compiled code.
that is right
"But I include all of the jdk contents with my project"
Including those will not change eclipse's compiler behavior. Including files under project build path just makes those classes available for your application development/run-time (or as good as setting CLASSPATH)
Do these :
1 - Install required version of JDK
2 - Choose following menu - Window > Preferences > Java > Compiler - and you will see a drop down to choose the version you want to use.
3 - Read this and this as well.
Good luck for being DBA after 5 yrs. Please consider working on your English as well (no offense please)