From 892d1bad5c4dd1e07fe59c5c60e3b94617b0e725 Mon Sep 17 00:00:00 2001 From: Anton Tananaev Date: Fri, 2 Nov 2018 14:17:45 +1300 Subject: Handle new Java class loader (fix #4130) --- src/org/traccar/database/DataManager.java | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) (limited to 'src/org') diff --git a/src/org/traccar/database/DataManager.java b/src/org/traccar/database/DataManager.java index c3a53f4b6..3d88b842d 100644 --- a/src/org/traccar/database/DataManager.java +++ b/src/org/traccar/database/DataManager.java @@ -103,10 +103,17 @@ public class DataManager { String driverFile = config.getString("database.driverFile"); if (driverFile != null) { - URLClassLoader classLoader = (URLClassLoader) ClassLoader.getSystemClassLoader(); - Method method = URLClassLoader.class.getDeclaredMethod("addURL", URL.class); - method.setAccessible(true); - method.invoke(classLoader, new File(driverFile).toURI().toURL()); + ClassLoader classLoader = ClassLoader.getSystemClassLoader(); + try { + Method method = classLoader.getClass().getDeclaredMethod("addURL", URL.class); + method.setAccessible(true); + method.invoke(classLoader, new File(driverFile).toURI().toURL()); + } catch (NoSuchMethodException e) { + Method method = classLoader.getClass() + .getDeclaredMethod("appendToClassPathForInstrumentation", String.class); + method.setAccessible(true); + method.invoke(classLoader, driverFile); + } } String driver = config.getString("database.driver"); -- cgit v1.2.3