简体   繁体   English

Jenkins或Maven在类路径上放置了错误的tools.jar

[英]Jenkins or Maven Places The Wrong tools.jar On Class Path

I have a complicated setup where I need to be able to compile different projects with different JDKs. 我有一个复杂的设置,在这里我需要能够使用不同的JDK编译不同的项目。 So, currently I have a docker image which has Oracle JDK 5 and Oracle JDK 6 installed manually and Open JDK 8 installed via apt-get (so that it is the default java in the image). 因此,当前我有一个泊坞窗映像,该映像具有手动安装的Oracle JDK 5和Oracle JDK 6,并通过apt-get安装了Open JDK 8(因此它是映像中的默认Java)。

In one of my projects, I am setting the project JDK to be the Oracle JDK 6 and Jenkins properly uses this JDK to compile the project. 在我的一个项目中,我将项目JDK设置为Oracle JDK 6,并且Jenkins正确地使用此JDK来编译项目。 However, in the class path argument passed to the compiler, Jenkins is adding the JDK 8 tools.jar and not the JDK 6 tools.jar. 但是,在传递给编译器的类路径参数中,Jenkins添加了JDK 8 tools.jar而不是 JDK 6 tools.jar。

In the code, unfortunately, we are are making a call to com.sun.tools.javac.Main and the import statement for this class is trying to import from the JDK 8 tools.jar. 不幸的是,在代码中,我们正在调用com.sun.tools.javac.Main,该类的import语句正试图从JDK 8 tools.jar导入。 Accordingly, the compilation fails, stating that: 因此,编译失败,并指出:

class file has wrong version 52.0, should be 50.0

So, how can I get Jenkins to use the proper tools.jar? 那么,如何让Jenkins使用适当的tools.jar?

I was thinking that I could perhaps force the JDK 6 tools.jar to be the first item on the class path, so that the JDK 8 classes will be ignored, but I am not 100% sure that would work (or if it's possible in Jenkins), and it seems like a terrible way to do this. 我当时以为可以强制将JDK 6 tools.jar放在类路径上的第一项,这样JDK 8类将被忽略,但是我不确定100%会起作用(或者是否可以詹金斯(Jenkins)),这似乎是一种糟糕的方法。

Note: I can not really change any system properties to always use JDK 6, becaue some projects will need to be compiled with JDK 8 with the proper tools.jar! 注意:我不能真正更改任何系统属性以始终使用JDK 6,因为某些项目需要使用适当的tools.jar用JDK 8进行编译!

EDIT: I added Maven to the title, because I suspect that might be where the actual fix needs to be. 编辑:我将Maven添加到标题,因为我怀疑这可能是实际修复需要的地方。

EDIT 2: I started investigating the Maven angle and I have found that someone has actually added a dependency to one of our POM files, but has done so in a way that leads to the wrong tools.jar being used...I think... 编辑2:我开始研究Maven的角度,我发现有人实际上已经向我们的POM文件之一添加了依赖项,但是这样做的方式导致使用错误的tools.jar ...我认为。 ..

解决此问题的最干净方法似乎是简单地在我们的Nexus实例中安装tools.jar并在com.sun:tools上添加常规依赖项。

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

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