简体   繁体   中英

Upgrade a Java 6 Project to Java 7 in Eclipse

I have an old Java 6 Project in Eclipse. To use functionality of Java 7 I would like to switch to Java 7. I am not able to do it :

Goal->No compilation errors in my Java Code . See red underlinded the compilation error when using ZipFile with 2 parameters used for Java 7. The Constructor of ZipFile in Java 6 has one argument. In Java 7 there are 2 arguments: 在此输入图像描述

My Environment in my project: 在此输入图像描述

Compilation Error is:

Exception in thread "main" java.lang.Error: Unresolved compilation problems: 
    The constructor ZipFile(String, Charset) is undefined
    The constructor ZipFile(String, Charset) is undefined

    at ZipCompare.compare(ZipCompare.java:103)
    at ZipCompare.main(ZipCompare.java:77)

在此输入图像描述

在此输入图像描述

在此输入图像描述

When I create a new Project from scratch, there are no compilation errors. I compared all settings from my old project and the new one and did not find any differences so far ?

Any help ?

Here are the exact steps in case anyone in the future needs them:

  1. In the Package Explorer window, right-click your project and select "Properties" from the context menu, or go to File > Properties.

  2. In the Properties dialog window, select "Java Build Path" from the left sidebar menu, then click the Libraries tab on the right-hand side.

  3. Select your 'JRE System Library' and click the "Edit..." button. Assuming you have the latest JRE installed, you should be able to change the "Execution environment" there.

  4. If not, go to "Alternate JRE:" and click the "Installed JREs..." button.

  5. Assuming you don't see the one you want listed, click "Add...", ensure "Standard VM" is selected, click "Next", click "Directory" and navigate to your new JRE root folder (ie, "C:\\Program Files\\Java\\jre1.8.0_20").

  6. Once you click "Finish" and then "OK", you should be able to switch back to "Execution environment" and select the JRE you desire.

  7. Click "Finish" and then select "Java Compiler" from the left sidebar menu. Double check that under JDK Compliance you have "Use compliance from execution environment...." checked.

Now your project should compile and run under the new JDK/JRE.

My messy solution. I don't know if there are sideeffects. So far no:

  1. Rename the old project to XXXXX_OLD
  2. Create new Project XXXXX with initial JAVA7 Environment
  3. Close Eclipse
  4. Copy Content of Folder XXXXX_OLD to XXXXX
  5. Start Eclipse. No Compilation Error anymore for my Constructor ZipFile(1,2)

I would really like to know the right way. I only gave this solution for probably help other peoples with the same issue. Use this Method on your own RISK! Its messy.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM