Injecting third party JARs into your classpath after upgrading from Java 8 to Java 11

Article ID:5222116291227
1 minute readKnowledge base


After upgrading to Java JDK 11 jobs executing Groovy code which were reliying on installed extensions (JAR files in the lib/ext directory of the Java Runtime Environment) are failing with java.lang.ClassNotFoundException.


import groovy.sql.Sql
def driver = "com.mysql.cj.jdbc.Driver"
def user = "sample_user"
def password = "sample_password"
def url = "jdbc:mysql://"
def db = Sql.newInstance(url, user, password, driver)

It throws a java.lang.ClassNotFoundException: com.mysql.cj.jdbc.Driver exeception.


The lib/ext directory was removed starting in JDK 9, and the presence of this directory will force java or javac executables to exit. Check Java Platform, Standard Edition Oracle JDK 9 Migration Guide: Removed Extension Mechanism for more details about it.


This process is unsupported, and if any issues are caused by doing this we will ask you to revert this change before we can escalate the issue to engineering. The correct solution to solve this problem is to integrate this into a Jenkins plugin.

You now need to add any third-party JAR files to the application’s classpath:

  • The build classpath if there are compile time dependencies

  • The runtime classpath if there are runtime dependencies