Closed bino013 closed 7 years ago
You seem to have set everything up correctly, so I guess it depends what your actual classpath is like during deployment. For some reason the Postgres driver isn't there when Duke tries to load it. I'm not sure where you're running this, but you may have to extend the classpath to explicitly include the Postgres driver.
/Library/Java/JavaVirtualMachines/jdk1.8.0_45.jdk/Contents/Home/bin/java "-javaagent:/Applications/IntelliJ IDEA.app/Contents/lib/idea_rt.jar=63947:/Applications/IntelliJ IDEA.app/Contents/bin" -Dfile.encoding=UTF-8 -classpath "/Library/Java/JavaVirtualMachines/jdk1.8.0_45.jdk/Contents/Home/jre/lib/charsets.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_45.jdk/Contents/Home/jre/lib/deploy.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_45.jdk/Contents/Home/jre/lib/ext/cldrdata.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_45.jdk/Contents/Home/jre/lib/ext/dnsns.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_45.jdk/Contents/Home/jre/lib/ext/jfxrt.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_45.jdk/Contents/Home/jre/lib/ext/localedata.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_45.jdk/Contents/Home/jre/lib/ext/nashorn.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_45.jdk/Contents/Home/jre/lib/ext/sunec.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_45.jdk/Contents/Home/jre/lib/ext/sunjce_provider.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_45.jdk/Contents/Home/jre/lib/ext/sunpkcs11.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_45.jdk/Contents/Home/jre/lib/ext/zipfs.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_45.jdk/Contents/Home/jre/lib/javaws.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_45.jdk/Contents/Home/jre/lib/jce.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_45.jdk/Contents/Home/jre/lib/jfr.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_45.jdk/Contents/Home/jre/lib/jfxswt.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_45.jdk/Contents/Home/jre/lib/jsse.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_45.jdk/Contents/Home/jre/lib/management-agent.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_45.jdk/Contents/Home/jre/lib/plugin.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_45.jdk/Contents/Home/jre/lib/resources.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_45.jdk/Contents/Home/jre/lib/rt.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_45.jdk/Contents/Home/lib/ant-javafx.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_45.jdk/Contents/Home/lib/dt.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_45.jdk/Contents/Home/lib/javafx-mx.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_45.jdk/Contents/Home/lib/jconsole.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_45.jdk/Contents/Home/lib/packager.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_45.jdk/Contents/Home/lib/sa-jdi.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_45.jdk/Contents/Home/lib/tools.jar:/Users/arcaleon/Documents/Work Codes/sample-duke-project/target/classes:/Users/arcaleon/.m2/repository/no/priv/garshol/duke/duke/1.2/duke-1.2.jar:/Users/arcaleon/.m2/repository/org/apache/lucene/lucene-core/4.0.0/lucene-core-4.0.0.jar:/Users/arcaleon/.m2/repository/org/apache/lucene/lucene-analyzers-common/4.0.0/lucene-analyzers-common-4.0.0.jar:/Users/arcaleon/.m2/repository/org/apache/lucene/lucene-spatial/4.0.0/lucene-spatial-4.0.0.jar:/Users/arcaleon/.m2/repository/com/spatial4j/spatial4j/0.3/spatial4j-0.3.jar:/Users/arcaleon/.m2/repository/org/apache/lucene/lucene-queries/4.0.0/lucene-queries-4.0.0.jar:/Users/arcaleon/.m2/repository/org/mapdb/mapdb/0.9.9/mapdb-0.9.9.jar:/Users/arcaleon/.m2/repository/org/postgresql/postgresql/9.4.1212/postgresql-9.4.1212.jar" DukeRunner
Base on the classpath that intellij uses when running the program and it seems that postresql jar is included. I'm just wondering if you have tried using the duke in maven project which uses postgres as its jdbc?
That command should work, assuming /Users/arcaleon/.m2/repository/org/postgresql/postgresql/9.4.1212/postgresql-9.4.1212.jar
is actually there.
I do the same thing with MySQL all the time, and it works just fine. So the problem isn't Duke.
I think Duke has a problem with Postgres.
I tried printing out if Class.forName("org.postgresql.Driver"); on my main class, and it did not throw any ClassNotFoundException. See that Class.forName() method is the same method that causes the ClassNotFoundException.
pass: class org.postgresql.Driver
Exception in thread "main" java.lang.RuntimeException: java.lang.ClassNotFoundException: org.postgresql.Driver
at no.priv.garshol.duke.utils.ObjectUtils.instantiate(ObjectUtils.java:145)
at no.priv.garshol.duke.utils.JDBCUtils.open(JDBCUtils.java:47)
at no.priv.garshol.duke.datasources.JDBCDataSource.getRecords(JDBCDataSource.java:82)
at no.priv.garshol.duke.Processor.deduplicate(Processor.java:198)
at no.priv.garshol.duke.Processor.deduplicate(Processor.java:174)
at DukeRunner.main(DukeRunner.java:27)
Caused by: java.lang.ClassNotFoundException: org.postgresql.Driver
at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:264)
at no.priv.garshol.duke.utils.ObjectUtils.instantiate(ObjectUtils.java:142)
... 5 more
public class DukeRunner {
static {
try {
Class<?> aClass = Class.forName("org.postgresql.Driver");
System.out.println("pass: " + aClass);
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
}
private static final String DUKE_CONFIG_XML_FILENAME = "classpath:DukeConfig.xml";
public static void main(String[] args) throws IOException, SAXException {
Configuration config = ConfigLoader.load(DUKE_CONFIG_XML_FILENAME);
Processor processor = new Processor(config);
processor.addMatchListener(new PrintMatchListener(true, true,
true, false, config.getProperties(), true));
processor.deduplicate();
processor.close();
}
}
Why are you closing the ticket? Did you figure out the solution? What was it?
Hi,
My mistake. Upon checking the value of driver-class on the DukeConfig, I have unconsciously put an excess space right after org.postgresql.Driver.
Thanks for the help anyways.
Thanks for explaining. Duke now trims spaces in class names so that we can avoid a repeat of this.
Hi,
I'm encountering java.lang.ClassNotFoundException when I'm trying to use postgres as my jdbc driver.
StackTrace:
POM: