问题描述
我正在与一个团队一起进行maven项目,并在Jenkins中为其建立了构建工作.
I'm working with a team on a maven project, and I set up a build job for it in Jenkins.
最近,团队中的某人添加了在字符串上切换的代码.这导致在Jenkins中构建失败,并出现以下错误:
Recently, someone on the team added code that switches on a String. This caused the build to fail in Jenkins with the following error:
error: strings in switch are not supported in -source 1.5
因此,我当然意识到Jenkins需要使用Java 7,而不是Java 5.
So of course I realized Jenkins needs to be using Java 7, not Java 5.
首先,我远程进入服务器,打开一个cmd,然后执行where java
和java -version
.我检查了我的环境变量和路径.一切都指向相同的Java 7 jdk目录:C:\Java\jdk1.7.0_21
.
First, I remoted into the server, opened a cmd, and did where java
and java -version
. I checked my environment variables and my path. Everything is pointing to the same Java 7 jdk directory: C:\Java\jdk1.7.0_21
.
然后,我检查了Jenkins,以查看它是否配置为使用正确的JDK.它是:
Then I checked Jenkins to see if it was configured to use the correct JDK. It is:
实际上,这是Jenkins服务器设置为使用的唯一Java,并且是服务器中安装的唯一Java.
In fact, that's the only Java that the Jenkins server is set up to use, and it's the only Java installed in the Server.
作为最后的选择,我将JDK参数插件安装到Jenkins中.然后,我将项目设置为使用Java 7参数:
As a last resort, I installed the JDK parameter plugin into Jenkins. I then set the project to use the Java 7 parameter:
但是,我仍然遇到相同的错误.
But still, I get the same error.
我错过了什么吗?是什么原因造成的?最重要的是,我该如何解决它并使Jenkins使用-source 1.7
而不是-source 1.5
?
Am I missing something? What could be causing this? Most importantly, how can I solve it and get Jenkins to use -source 1.7
instead of -source 1.5
?
推荐答案
检查pom.xml以及在那里指定的Java版本(用于源代码).可能是source 1.5
的来源.
Check your pom.xml and what java version (for the source) is specified there. That could be where the source 1.5
is coming from.
<properties>
<jee.level>1.4</jee.level>
<jdk.level>1.5</jdk.level>
</properties>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>${jdk.level}</source>
<target>${jdk.level}</target>
</configuration>
</plugin>
这篇关于Jenkins将不使用Java 7编译器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!