• 提示”Cannot use diamond operator with non-generic type”(使用Java 7+特性但编译器设置为Java 6或更低)
• 提示”Lambda expressions are allowed only at source level 1.8 or higher”(使用Java 8+特性但编译器设置为Java 7或更低)
• 提示”Unsupported major.minor version 52.0”(运行时Java版本低于编译时Java版本)
1. 右键点击项目,选择”Properties”
2. 选择”Java Compiler”
3. 在右侧的”Classfile Generation”部分,可以设置各种编译器选项:“Generated .class files compatibility”:设置生成的class文件兼容的Java版本“Source compatibility”:设置源代码兼容的Java版本其他选项如”Add line number attributes to generated class files”等
4. “Generated .class files compatibility”:设置生成的class文件兼容的Java版本
5. “Source compatibility”:设置源代码兼容的Java版本
6. 其他选项如”Add line number attributes to generated class files”等
7. 在”Annotation Processing”部分,可以配置注解处理相关选项
8. 在”Build Path”部分的”Source”选项卡中,可以为特定的源代码目录设置特定的输出目录
右键点击项目,选择”Properties”
选择”Java Compiler”
在右侧的”Classfile Generation”部分,可以设置各种编译器选项:
• “Generated .class files compatibility”:设置生成的class文件兼容的Java版本
• “Source compatibility”:设置源代码兼容的Java版本
• 其他选项如”Add line number attributes to generated class files”等
在”Annotation Processing”部分,可以配置注解处理相关选项
在”Build Path”部分的”Source”选项卡中,可以为特定的源代码目录设置特定的输出目录
示例:
假设我们希望为项目中的测试代码和主代码设置不同的输出目录,并且希望编译器生成额外的调试信息:
1. 右键点击项目,选择”Properties”
2. 选择”Java Build Path” > “Source”
3. 点击”Add Folder”,添加测试代码目录(如”src/test/java”)
4. 选择测试代码目录,点击”Edit”,设置特定的输出目录(如”target/test-classes”)
5. 选择”Java Compiler”
6. 确保”Add line number attributes to generated class files”、”Add source file name to generated class files”和”Add variable attributes to generated class files”都被勾选
7. 点击”Apply and Close”
增量编译设置
MyEclipse支持增量编译,即只重新编译修改过的文件,这可以显著提高大型项目的编译速度。
配置方法:
1. 选择”Window” > “Preferences” > “Java” > “Compiler”
2. 在”Building”部分,可以设置增量编译相关选项:“Rebuild class files modified by others”:当文件被其他程序修改时是否重新编译“Report unused import”:是否报告未使用的导入“Report ‘finally’ blocks that do not complete normally”:是否报告不正常完成的finally块
3. “Rebuild class files modified by others”:当文件被其他程序修改时是否重新编译
4. “Report unused import”:是否报告未使用的导入
5. “Report ‘finally’ blocks that do not complete normally”:是否报告不正常完成的finally块
6. 在”Classfile Generation”部分,可以设置:“Discourage declared non-API use”:是否 discourage 非API使用“Preserve all local variables”:是否保留所有局部变量(用于调试)
7. “Discourage declared non-API use”:是否 discourage 非API使用
8. “Preserve all local variables”:是否保留所有局部变量(用于调试)
选择”Window” > “Preferences” > “Java” > “Compiler”
在”Building”部分,可以设置增量编译相关选项:
• “Rebuild class files modified by others”:当文件被其他程序修改时是否重新编译
• “Report unused import”:是否报告未使用的导入
• “Report ‘finally’ blocks that do not complete normally”:是否报告不正常完成的finally块
在”Classfile Generation”部分,可以设置:
• “Discourage declared non-API use”:是否 discourage 非API使用
• “Preserve all local variables”:是否保留所有局部变量(用于调试)
1. 右键点击项目,选择”Properties”
2. 选择”Java Compiler”
3. 在”Classfile Generation”部分,确保以下选项被勾选:“Add line number attributes to generated class files”“Add source file name to generated class files”“Add variable attributes to generated class files”
4. “Add line number attributes to generated class files”
5. “Add source file name to generated class files”
6. “Add variable attributes to generated class files”
7. 点击”Apply and Close”
• “Add line number attributes to generated class files”
• “Add source file name to generated class files”
• “Add variable attributes to generated class files”