Setting JDK in Eclipse

前端 未结 6 1361
旧时难觅i
旧时难觅i 2020-11-22 16:37

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

6条回答
  •  误落风尘
    2020-11-22 16:51

    Configuring JDKs

    1. Windows -> Preferences -> Installed JREs, to configured the installed JDKs
    2. Project Properties, Java Compiler, Enable project specific settings (or configure Workspace settings), JDK Compliance
    3. 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

                
                    maven-compiler-plugin
                    3.3
                    
                        1.8
                        1.8
                    
                
    

    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.

提交回复
热议问题