aboutsummaryrefslogtreecommitdiff
path: root/src/org/traccar/database
diff options
context:
space:
mode:
authorAnton Tananaev <anton.tananaev@gmail.com>2015-12-24 09:33:21 +1300
committerAnton Tananaev <anton.tananaev@gmail.com>2015-12-24 09:33:21 +1300
commite44d97da1b951f938a0d6ade76eef559d4626f3c (patch)
treeb126cc8c009b5f92f881f7b1ef63fb0379202fde /src/org/traccar/database
parentc1eb91d66a9f70ae10285f0b2d2fe82830fc5876 (diff)
downloadtraccar-server-e44d97da1b951f938a0d6ade76eef559d4626f3c.tar.gz
traccar-server-e44d97da1b951f938a0d6ade76eef559d4626f3c.tar.bz2
traccar-server-e44d97da1b951f938a0d6ade76eef559d4626f3c.zip
Dynamically add driver path to classpath
Diffstat (limited to 'src/org/traccar/database')
-rw-r--r--src/org/traccar/database/DataManager.java26
1 files changed, 11 insertions, 15 deletions
diff --git a/src/org/traccar/database/DataManager.java b/src/org/traccar/database/DataManager.java
index e2e1d9f18..1ea0a3d31 100644
--- a/src/org/traccar/database/DataManager.java
+++ b/src/org/traccar/database/DataManager.java
@@ -17,10 +17,9 @@ package org.traccar.database;
import com.mchange.v2.c3p0.ComboPooledDataSource;
import java.io.File;
+import java.lang.reflect.Method;
import java.net.URL;
import java.net.URLClassLoader;
-import java.sql.Driver;
-import java.sql.DriverManager;
import java.sql.SQLException;
import java.util.Collection;
import java.util.Date;
@@ -37,7 +36,6 @@ import liquibase.exception.LiquibaseException;
import liquibase.resource.FileSystemResourceAccessor;
import liquibase.resource.ResourceAccessor;
import org.traccar.Config;
-import org.traccar.helper.DriverDelegate;
import org.traccar.helper.Log;
import org.traccar.model.Device;
import org.traccar.model.MiscFormatter;
@@ -83,22 +81,19 @@ public class DataManager implements IdentityManager {
} else {
- // Load driver
+ 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());
+ }
+
String driver = config.getString("database.driver");
if (driver != null) {
- String driverFile = config.getString("database.driverFile");
-
- if (driverFile != null) {
- URL url = new URL("jar:file:" + new File(driverFile).getAbsolutePath() + "!/");
- URLClassLoader cl = new URLClassLoader(new URL[]{url});
- Driver d = (Driver) Class.forName(driver, true, cl).newInstance();
- DriverManager.registerDriver(new DriverDelegate(d));
- } else {
- Class.forName(driver);
- }
+ Class.forName(driver);
}
- // Initialize data source
ComboPooledDataSource ds = new ComboPooledDataSource();
ds.setDriverClass(config.getString("database.driver"));
ds.setJdbcUrl(config.getString("database.url"));
@@ -112,6 +107,7 @@ public class DataManager implements IdentityManager {
ds.setMaxPoolSize(maxPoolSize);
}
dataSource = ds;
+
}
}