java build path problems [duplicate] - java

This question already has answers here:
Warning - Build path specifies execution environment J2SE-1.4
(12 answers)
Closed 6 years ago.
From someone's project, I am getting this error:
Java Build Path Problems (1 item)
Build path specifies execution environment J2SE-1.5. There are no JREs installed in the workplace that are strictly compatible with this environment.
I have the latest JDK (jdk1.6.0_25). From my understanding, I can do one of the following:
Download the J2SE-1.5 environment to match the project.
Edit the project to agree with the latest JDK. How can I do this?

Right click on project, Properties, Java Build Path.
Remove the current JRE library.
Click Add library > JRE System Library > Workspace default JRE.

Here's a good discussion on this:
How to use JDK 1.6 in 1.5 compliance mode
Basically you should
Download and install the 1.5 JDK. (download link)
In Eclipse, Go to Window → Preferences → Java → Installed JREs.
Add the 1.5 JDK to the list.
Select 1.5 as Compiler Compliance Level.

Go for the second option, Edit the project to agree with the latest JDK
Right click "JRE System Library [J2SE 1.5] in your project"
Choose "Properties"
Select "Workspace default JRE (jdk1.6)

From the Package Explorer in Eclipse, you can right click the project, choose Build Path, Configure Build Path to get the build path dialog. From there you can remove the JRE reference for the 1.5 JRE and 'Add Library' to add a reference to your installed JRE.

To configure your JRE in eclipse:
Window > Preferences > Java > Installed JREs...
Click Add
Find the directory of your JDK > Click OK

Try this too in addition to MahmoudS comments.
Change the maven compiler source and target in your pom.xml to the java version which you are using. Say 1.7 for jdk7
<maven.compiler.source>1.7</maven.compiler.source>
<maven.compiler.target>1.7</maven.compiler.target>

Related

I want to use different JDK version on eclipse [duplicate]

I have two JDKs, for Java 6 and 7.
I want to build my project using both. Initially we only built against 1.6.
I see in my project setting I can select 1.5, 1.6 1.7 as the compiler level.
How are these options added to the IDE? I never installed Java 1.5.
Suppose I wanted Java 1.4. How would I get this to appear in the list? I have added two different JREs in my IDE preferences, but these are not what appears in the dropdown.
You manage the list of available compilers in the Window -> Preferences -> Java -> Installed JRE's tab.
In the project build path configuration dialog, under the libraries tab, you can delete the entry for JRE System Library, click on Add Library and choose the installed JRE to compile with. Some compilers can be configured to compile at a back-level compiler version. I think that's why you're seeing the addition version options.
Some additional steps may be needed to set both the project and default workspace JRE correctly, as MayoMan mentioned. Here is the complete sequence in Eclipse Luna:
Right click your project > properties
Select “Java Build Path” on left, then “JRE System Library”, click Edit…
Select "Workspace Default JRE"
Click "Installed JREs"
If you see JRE you want in the list select it (selecting a JDK is OK too)
If not, click Search…, navigate to Computer > Windows C: > Program Files > Java, then click OK
Now you should see all installed JREs, select the one you want
Click OK/Finish a million times
Easy.... not.
To tell eclipse to use JDK, you have to follow the below steps.
Select the Window menu and then Select Preferences. You can see a dialog box.
Then select Java ---> Installed JRE’s
Then click Add and select Standard VM then click Next
In the JRE home, navigate to the folder you’ve installed the JDK (For example, in my system my JDK was in C:\Program Files\Java\jdk1.8.0_181\ )
Now click on Finish.
After completing the above steps, you are done now and eclipse will start using the selected JDK for compilation.
Configuring JDKs
Windows -> Preferences -> Installed JREs, to configured the installed JDKs
Project Properties, Java Compiler, Enable project specific settings (or configure Workspace settings), JDK Compliance
Project Properties, Java Build Path, Libraries, Add Library, JRE system library, Workspace default or Alternate JRE (one of the JREs configured in
Maven
BUT IF you are using maven, provided that you have your latest JRE (Windows/Preferences/Installed JREs) -for example JDK 1.8
You can select the level 1.6, 1.7, 1.8 by configuring the maven-compiler-plugin source and target attributes, like this
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.3</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
And ideally, if you have a parent pom, you can do it for all the modules (Eclipse projects) in the parent pom, in one single place.
Source and Target
If we want to use the Java 8 language features the –source should be set to 1.8. Also, for the compiled classes to be compatible with JVM 1.8, the –target value should be 1.8.
Updating JRE library that is broken in many projects at once (with Maven)
Rather than updating one by one the JRE library, let Maven do it for you.
Selecting the projects and right-clicking for Maven -> Update Project, will set the system library to the path of the installed JDK, in case the paths are broken (because you installed a new JDK or imported from another computer, etc.) and set the JDK compliance according to the maven source and target setting in the pom.
Eclipse's compiler can assure that your java sources conform to a given JDK version even if you don't have that version installed. This feature is useful for ensuring backwards compatibility of your code.
Your code will still be compiled and run by the JDK you've selected.
JDK 1.8 have some more enrich feature which doesn't support to many eclipse .
If you didn't find java compliance level as 1.8 in java compiler ,then go ahead and install the below eclipse 32bit or 64 bit depending on your system supports.
Install jdk 1.8 and then set the JAVA_HOME and CLASSPATH in
environment variable.
Download eclipse-jee-neon-3-win32 and unzip : supports to java 1.8
Or download Oracle Enterprise Pack for Eclipse (12.2.1.5) and unzip
:Supports java 1.8 with 64 bit OS
Right click your project > properties
Select “Java Compiler” on left and set java compliance level to 1.8
[select from the dropdown 1.8]
Try running one java program supports to java 8 like lambda
expression as below and if no compilation error ,means your eclipse
supports to java 1.8, something like this:
interface testI{
void show();
}
/*class A implements testI{
public void show(){
System.out.println("Hello");
}
}*/
public class LambdaDemo1 {
public static void main(String[] args) {
testI test ;
/*test= new A();
test.show();*/
test = () ->System.out.println("Hello,how are you?"); //lambda
test.show();
}
}

Eclipse says jre does not support the current compiler level of 1.8 but it is set at 1.7

I installed Eclipse mars with java JDK8 but was was having lots of problems with it so I uninstalled it changed back to JDK7 and now I'm getting a strange compiler error in a few of my projects. I noticed that when I went into, Windows->Preferences-> Java->Installed JREs, there is an error message at the top saying that "The selected JRE does not support the ...rent compiler compliance level of 1.8" but when I check the compiler compliance level its set to 1.7
Ok so I decided to try starting a new project and when trying to build it a warning came up that my workspace compliance level was at level 1.8...changing the workspace fixed the problem. So new is it possible to change the workspace compliance level or should I just import my projects into a new workspace?
I tried importing into a new workspace,same problem. So I started new project in a new workspace, copyed and pasted the code in a voila it works! Very annoying if I have to do that for every class in every project I want.
Check your compliance settings in:
Preferences > Java > Compiler
Make sure the default is set to 1.7 as it may have defaulted to 1.8 after the initial install/run.
Also check project-specific compliance settings in:
(Project) Properties > Java Compiler
I changed Windows ->Preference->Java->Installed JREs to jdk1.7.0_79 and right clicked the project, Properties ->Java Build Path, made sure that under Libraries tab, it is JRE System Library[JavaSE-1.7]. Clicked Project ->Clean. Right clicked the project again, Properties ->Java Compiler, checked Use compliance from execution environment 'JavaSE-1.7' on the 'Java Build Path'.Then it worked.
If you already changed all settings to 1.7 (both in the eclipse preferences and the project properties) check your project's build path. How? Easy, after you've imported your project, right-button click it and select Build path > Configure Build Path. Then, check if you have your JRE system library correctly set.
If even this is set up ok, I would say that you probably have some code that can only be compiled by jdk 8 and you're trying to use jdk7 compliance level, which eclipse warns you about. An example of this is using lambda functions, which can only be compiled with java 8 as far as I know.
Go to Windows >> Preferences>>Compiler >> Unselect default
compliance settings >> select the compiler compliance level to 1.8
This should reflect in generated .class files compatibility
as 1.8 and source compatibility as 1.8 Step Step
Apply it Step
now click on apply and close
clean and build the project.
I have similar issue with Mars on Pydev environment. Seems that Mars want java jre 1.7.0, so for me was work by copy inside(create if not avaiable) eclipse\jre\ folder and copy the 1.7.0 version of jre inside

How can I change JRE version in Eclipse project?

Hello I have an project in Eclipse and I need change my JRE version in this progect to JRE 1.7 from JRE 1.8.
How can I do it?
In the Preferences go to 'Java > Installed JREs' and add the Java 8 JRE/JDK if it is not already there.
In the Properties for the project look at 'Java Build Path'. On the 'Libraries' tab edit the JRE entry and select Java 8.
You may also want to set the Java Compiler preferences for the project (or the global preferences) to specify Java 8 compliance.
Note: You need to be running Eclipse Luna (4.4) or later for full Java 8 support.
Windows > Preferences > Java > Installed JREs

what broke up in my eclipse?

For some reason, whenever I create a new Java project, I can't compile anything and I get the following errors:
The project cannot be built until build path errors are resolved
Unbound classpath container: 'JRE System Library[OSGi/Minimum-1.2]' in project 'MyProject'
This didn't use to ever happen, and it used to be very easy to create new Java projects.
Open Properties by Right clicking on your project
Select Java Build Path
Under the Libraries, select JRE System Library under the Libraries.
Then click Edit...
select Alternate JRE under System library
If any, select JRE from the drop down and click finish
If none, click installed JREs...
Under installed JRE Types, select Standard VM, and click next.
Set your JRE home and JRE name and click finish.
Under the install JREs select your newly added JRE and click OK
After that, Repeat step 6.
1.Check whether JRE is properly installed in your system and it is added in Eclipse.
You can try re-installing JDK in your system and
Add JRE to Eclipse from Window -> Preferences -> Java -> Installed JREs.

How to change JDK version for an Eclipse project

I need to write a project that's only compatible with Java 1.5. I have Java 1.6 installed. Is there some form of backwards compatibility to get Eclipse to compile with 1.5?
Do I have to install Java 1.5 to get it to show here? Or maybe there is another way?
.
Click on the Add Library button. It brings your screen to point to the Java location.
Select "Directory", button right besides JRE home and point to the installed folder location.
Even though you want to just 1.5 compiler project, you can achieve it by changing compiler settings in Eclipse instead of removing 1.6 JRE and add 1.5 JRE.
GOTO -->JAVA--Compiler---> and change compiler level to `1.5` instead of `1.6`
As davidfmatheson suggested,
Just be careful, especially if you're setting this up for a team of people to work on. If anyone uses anything that is new or changed in 1.6, it will compile, but not run in an environment with JRE 1.5.
Click on the Window tab in Eclipse, go to Preferences and when that window comes up, go to Java → Installed JREs → Execution Environment and choose JavaSE-1.5. You then have to go to Compiler and set the Compiler compliance level.
Right click project -> Properties -> Java Build Path -> select JRE System Library click Edit and select JDK or JRE after then click Java Compiler and select Compiler compliance level to 1.8
If you are using maven build tool then add the below properties to it and doing a maven update will solve the problem
<properties>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>
In the preferences section under Java -> Installed JREs click the Add button and navigate to the 1.5 JDK home folder. Then check that one in the list and it will become the default for all projects:
Eclipse - specific Project change JDK Version -
If you want to change any jdk version of A specific project than you have to click ---> Project --> JRE System Library --> Properties ---> Inside Classpath Container (JRE System Library) change the Execution Environment to which ever version you want e.g. 1.7 or 1.8.
The JDK (JAVA_HOME) used to launch Eclipse is not necessarily the one used to compiled your project.
To see what JRE you can select for your project, check the preferences:
General → Java Installed JRE
By default, if you have not added any JRE, the only one declared will be the one used to launched Eclipse (which can be defined in your eclipse.ini).
You can add any other JRE you want, including one compatible with your project.
After that, you will need to check in your project properties (or in the general preferences) what JRE is used, with what compliance level:
(source: standartux.fr)
See the page Set Up JDK in Eclipse. From the add button you can add a different version of the JDK...
As I was facing this issue minutes ago, in case you are trying to open an existing project in an environment with a newer JDK, make sure you pdate the JDK version in Project Properties -> Project Facets -> Java.

Categories