binary01
binary01

Reputation: 1898

Ant gives "Unsupported major.minor version 52.0" when run through Jenkins

I've set up a job in Jenkins that runs ant, it gives this error:

First time build. Skipping changelog.
Unpacking https://archive.apache.org/dist/ant/binaries/apache-ant-1.10.3-bin.zip to /var/lib/jenkins/tools/hudson.tasks.Ant_AntInstallation/default-ant on Jenkins
[my_project] $ /var/lib/jenkins/tools/hudson.tasks.Ant_AntInstallation/default-ant/bin/ant dist
Exception in thread "main" java.lang.UnsupportedClassVersionError: org/apache/tools/ant/launch/Launcher : Unsupported major.minor version 52.0
    at java.lang.ClassLoader.defineClass1(Native Method)
    at java.lang.ClassLoader.defineClass(ClassLoader.java:803)
    at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
    at java.net.URLClassLoader.defineClass(URLClassLoader.java:442)
    at java.net.URLClassLoader.access$100(URLClassLoader.java:64)
    at java.net.URLClassLoader$1.run(URLClassLoader.java:354)
    at java.net.URLClassLoader$1.run(URLClassLoader.java:348)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:347)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:425)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:312)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
    at sun.launcher.LauncherHelper.checkAndLoadMain(LauncherHelper.java:482)
Build step 'Invoke Ant' marked build as failure

Why is this happening ?

What can I do to fix it ?

Note, If I ssh in to the build server, go to the jenkins workspace, and manuall run

 /var/lib/jenkins/tools/hudson.tasks.Ant_AntInstallation/default-ant/bin/ant dist

the build succeeds.

Jenkins reports java.runtime.version 1.8.0_131-b11 and on the build machine:

# java -version
openjdk version "1.8.0_131"
OpenJDK Runtime Environment (build 1.8.0_131-b11)
OpenJDK 64-Bit Server VM (build 25.131-b11, mixed mode)

Upvotes: 1

Views: 2413

Answers (1)

binary01
binary01

Reputation: 1898

I found the issue, as hinted by in the comments by @VeselinDavidov

The newest ant (v 1.10 and newer) only supports Java 8, however the $PATH was set to include a place with Java 7 (unknown as to why JDK 7 was the 1. item in the $PATH when ant was run through jenkins, but not when running it manually outside jenkins)

To resolve:

  1. Go to the configuration of the job in Jenkins
  2. Go to the "Build Environment" section
  3. Check the "With ant" checkbox which also expands to more configuration options.
  4. Select the proper "Ant version" and "JDK version"

If the proper "JDK version" is not available/installed, do this first:

  1. Go to "Manage Jenkins" from the jenkins front page
  2. Go to "Global Tool Configuration" and click "JDK Installations"
  3. Define/install the relevant JDK version.
  4. Go back to the job and set up ant with this new JDK version.

Alternatively, if Java 7 is sufficient, install and use ant version 1.9.x, which supports Java 7.

Upvotes: 1

Related Questions