我导入了一个Maven项目,它使用Java 1.5,即使我有1.6配置为我的Eclipse默认首选项->Java->安装的jre。
当我将Maven项目更改为使用1.6 JRE时,它仍然有从项目使用Java 1.5时遗留下来的构建错误(我在前面描述了这些构建错误:我使用m2eclipse构建错误,但在命令行上没有使用maven2—是我的m2eclipse配置错误吗?)
我将删除该项目,然后再试一次,但我想确保这次它从一开始就使用Java 1.6,看看这是否消除了构建问题。
我如何确保项目在导入时使用Java 1.6 ?
如果你使用Tycho和Maven来构建bundle,还有一个可能的原因是你在manifest文件(manifest.mf)中定义了错误的执行环境(Bundle-RequiredExecutionEnvironment)。例如:
Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: Engine Plug-in
Bundle-SymbolicName: com.foo.bar
Bundle-Version: 4.6.5.qualifier
Bundle-Activator: com.foo.bar.Activator
Bundle-Vendor: Foobar Technologies Ltd.
Require-Bundle: org.eclipse.core.runtime,
org.jdom;bundle-version="1.0.0",
org.apache.commons.codec;bundle-version="1.3.0",
bcprov-ext;bundle-version="1.47.0"
Bundle-RequiredExecutionEnvironment: JavaSE-1.5
Export-Package: ...
...
Import-Package: ...
...
对我来说,其他一切都还好。编译器插件(正常的maven和tycho)被正确地设置了,由于清单,仍然生成了旧的遵从级别。我想我也有同样的经历。
如果你使用Tycho和Maven来构建bundle,还有一个可能的原因是你在manifest文件(manifest.mf)中定义了错误的执行环境(Bundle-RequiredExecutionEnvironment)。例如:
Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: Engine Plug-in
Bundle-SymbolicName: com.foo.bar
Bundle-Version: 4.6.5.qualifier
Bundle-Activator: com.foo.bar.Activator
Bundle-Vendor: Foobar Technologies Ltd.
Require-Bundle: org.eclipse.core.runtime,
org.jdom;bundle-version="1.0.0",
org.apache.commons.codec;bundle-version="1.3.0",
bcprov-ext;bundle-version="1.47.0"
Bundle-RequiredExecutionEnvironment: JavaSE-1.5
Export-Package: ...
...
Import-Package: ...
...
对我来说,其他一切都还好。编译器插件(正常的maven和tycho)被正确地设置了,由于清单,仍然生成了旧的遵从级别。我想我也有同样的经历。
如果您希望确保Eclipse中新创建的项目或导入的项目使用java 1.5以外的其他默认java版本,您可以在maven-compiler-plugin中更改配置。
Go to the folder .m2/repository/org/apache/maven/plugins/maven-compiler-plugin/3.1
Open maven-compiler-plugin-3.1.jar with a zip program.
Go to META-INF/maven and open the plugin.xml
In the following lines:
<source implementation="java.lang.String" default-value="1.5">${maven.compiler.source}</source>
<target implementation="java.lang.String" default-value="1.5">${maven.compiler.target}</target>
change the default-value to 1.6 or 1.8 or whatever you like.
Save the file and make sure it is written back to the zip file.
从现在开始,所有新的Maven项目都使用您指定的java版本。
信息来自以下博客文章:https://sandocean.wordpress.com/2019/03/22/directly-generating-maven-projects-in-eclipse-with-java-version-newer-than-1-5/