1

I have a complicated setup where I need to be able to compile different projects with different JDKs. 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).

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

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

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.

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!

EDIT: I added Maven to the title, because I suspect that might be where the actual fix needs to be.

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

sixbitproxywax
  • 160
  • 1
  • 10
  • can you share the [dependency:tree](https://maven.apache.org/plugins/maven-dependency-plugin/tree-mojo.html) goal results? – Yuri G. Jun 29 '15 at 05:52

1 Answers1

0

The cleanest way to resolve this seemed to be to simply install the tools.jar in our Nexus instance and add a regular dependency on com.sun:tools.

sixbitproxywax
  • 160
  • 1
  • 10