简体   繁体   English

Jenkins将不使用Java 7编译器

[英]Jenkins will not use Java 7 compiler

I'm working with a team on a maven project, and I set up a build job for it in Jenkins. 我正在与一个团队合作进行maven项目,并在Jenkins中为其建立了构建工作。

Recently, someone on the team added code that switches on a String. 最近,团队中的某人添加了在String上切换的代码。 This caused the build to fail in Jenkins with the following error: 这导致构建在Jenkins中失败,并出现以下错误:

error: strings in switch are not supported in -source 1.5

So of course I realized Jenkins needs to be using Java 7, not Java 5. 因此,我当然意识到Jenkins需要使用Java 7,而不是Java 5。

First, I remoted into the server, opened a cmd, and did where java and java -version . 首先,我远程进入服务器,打开一个cmd,然后where javajava -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 . 一切都指向相同的Java 7 jdk目录: C:\\Java\\jdk1.7.0_21

Then I checked Jenkins to see if it was configured to use the correct JDK. 然后,我检查了Jenkins,以查看它是否配置为使用正确的JDK。 It is: 它是: 詹金斯JDK

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. 实际上,这是设置Jenkins服务器使用的唯一Java,并且是服务器中安装的唯一Java。

As a last resort, I installed the JDK parameter plugin into Jenkins. 作为最后的选择,我将JDK参数插件安装到Jenkins中。 I then set the project to use the Java 7 parameter: 然后,我将项目设置为使用Java 7参数:

参数JDK

But still, I get the same error. 但是,我仍然遇到相同的错误。

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 ? 最重要的是,我该如何解决它并使Jenkins使用-source 1.7而不是-source 1.5

Check your pom.xml and what java version (for the source) is specified there. 检查您的pom.xml以及在其中指定的Java版本(用于源代码)。 That could be where the source 1.5 is coming from. 那可能就是source 1.5source 1.5

<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>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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