4

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.

Community
  • 1
  • 1
Joey
  • 2,732
  • 11
  • 43
  • 63
  • 1. Declare different JRE/JDK in eclipse 2. Add them to your project settings ! – AllTooSir Jul 29 '13 at 15:59
  • Can you add the "Problems" view, and then post the error being shown on your project ? – Cristian Meneses Jul 29 '13 at 16:42
  • @CristianMeneses I have added the problem view, it said java compiler level does not match the version of the installed java project facet. I do not really know what that means and how to fix it. please help. – Joey Jul 29 '13 at 16:53
  • @CristianMeneses Oh i have figured it out. thanks for pointing me to check the problem view. This really helps me out. – Joey Jul 29 '13 at 17:02

3 Answers3

3

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.

Ted Hopp
  • 232,168
  • 48
  • 399
  • 521
  • Actually I have tried this. There is some error. My default jdk is 1.7. I created a project based on 1.7 (default), then I do the same things as you described. but there is some error and I cannot find out what those errors are. – Joey Jul 29 '13 at 16:15
  • @user1387727 - Did you figure out the cause of the error(s)? Were they compilation errors or was Eclipse complaining about something else? Looking at the _Error Log_ view and/or the _Problems_ view (under _Window_ > _Show View_) might be helpful. – Ted Hopp Jul 29 '13 at 17:10
0

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.

Richard Sitze
  • 8,262
  • 3
  • 36
  • 48
0

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.

rocketboy
  • 9,573
  • 2
  • 34
  • 36