Question

I am using Eclipse with JDK 1.7. My previous projects are developed in java 7 and JDK 1.7. Now, I want to build a new project under JDK 1.6 in Eclipse. Is it possible to do that so that some projects are based on JDK 1.7 and some others are based on JDK 1.6 without conflicts?

If this can be done, please let me know how to do it step by step.

Update: My default JDK is 1.7. I created a new project that is based on jdk1.7 by default. And then I go to the property of this project, and then java compiler, then change the compliance settings as the image shows below. But there is some error occurred. What could be the reason causes this error?

enter image description here

enter image description here

The following is the "problem" view

enter image description here

After some research, I have solved this problem. please see the reference about how to fix the facet version.

Was it helpful?

Solution

You can set overall workspace properties to use one version of Java and set individual project properties to use another.

  • To set overall workspace properties, click on Window > Preferences, then navigate to Java > Compiler.
  • To set project properties, right-click on the project and select Properties. Navigate to Java Compiler and check "Enable project specific settings"

You can choose from among the installed JREs for either setting. To tell Eclipse about a newly installed JRE, you can open the workspace preferences and navigate to Java > Installed JREs and then click the "Add" button.

OTHER TIPS

You can change the JDK used by project under Project properties(alt+enter)-> Installed JREs. Also Debug Configuration is your friend. You can set what JDK to use when launching/running an app/program in Eclipse.

This can be done for an Eclipse Run Configuration. You may define multiple such configurations, each of which will reference a "main class" in one of your projects.

  1. In Window -> Preferences -> Java -> Installed JREs define a location for each JRE/JDK.

  2. For a given Eclipse project:

    • right click on the project, select Properties -> Java Compiler, override and set compiliance level settings.

    • Check Use compliance from ..., visit the Java Build Path and be sure you have a JRE Library set that matches the desired compliance level.

  3. For a given Eclipse Run Configuration: Run -> Run Configurations... -> Java Application, select an old or create a new configuration, select the JRE tab and specify the Runtime JRE.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top