[Pljava-dev] Classloader/Classpath problem with Ressource Files

From: vorarlberger at gmail(dot)com (Christian Kindler)
To:
Subject: [Pljava-dev] Classloader/Classpath problem with Ressource Files
Date: 2011-07-06 18:15:42
Message-ID: CALtUeZYcvO-F02DibNCdggJdPy5eot1wcy+USej4cvcua8mkrw@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pljava-dev

Hi

I want to use html-unit from pg using pljava. But the problem is, that
pljava reports a file not found error when somebody try to access classpath
trough classloader.

see my pgadim console:

SELECT test.getDoTest();

FEHLER: 06 Jul 11 19:49:09
com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine$1 Exception while
initializing JavaScript for the page
org.postgresql.pljava.internal.ServerException: 06 Jul 11 19:49:09
com.gargoylesoftware.htmlunit.javascript.configuration.JavaScriptConfiguration
Error when loading JavascriptConfiguration.xml
java.lang.NullPointerException
at
com.gargoylesoftware.htmlunit.javascript.configuration.JavaScriptConfiguration.getConfigurationFileAsReader(JavaScriptConfiguration.java:260)

if you look at the file
http://htmlunit.svn.sourceforge.net/viewvc/htmlunit/trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/configuration/JavaScriptConfiguration.java?revision=6204&view=markup

you can see
final Class< ? > clazz = JavaScriptConfiguration.class;
final String name = clazz.getPackage().getName().replace('.', '/') + '/' +
"JavaScriptConfiguration.xml";
InputStream inputStream =
clazz.getClassLoader().getResourceAsStream(name);

But the file is in the jar as expected, so it must be a class loader path
problem.

Interestingly when I check the classpath ...

select sqlj.get_ClassPath('test');

"apachemime4j:commonscodec:commonscollections:commonsio:commonslang:commonslogging:cssparser:htmlunit:htmlunitcore:httpclient:httpcore:httpmime:nekohtml:sac:serializer:xalan:xercesImpl:xmlapis:hui"

ok, but when I do
import java.io.File;
import java.io.FileInputStream;
import java.io.InputStream;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Enumeration;
import java.util.List;
import java.util.jar.JarEntry;
import java.util.jar.JarFile;
import java.net.URL;
import java.net.URLClassLoader;
import java.util.Collections;

public class FileUtils {

public static String getClasspath (int variante) {

//Get the System Classloader
final Class< ? > clazz = FileUtils.class;
ClassLoader sysClassLoader;
switch(variante) {
case 1: sysClassLoader = clazz.getClassLoader(); break;
case 2: sysClassLoader =
Thread.currentThread().getContextClassLoader(); break;
case 3: sysClassLoader = ClassLoader.getSystemClassLoader();
break;
default: return "NULL";
}

//sysClassLoader.g
//Get the URLs
URL[] urls = ((URLClassLoader)sysClassLoader).getURLs();
String cp = "";
for(int i=0; i< urls.length; i++)
{
cp += urls[i].getFile();
cp += ";";
}

return cp;
}
}

and select test.getCP(1); I get a casting exception
FEHLER: java.lang.ClassCastException: org.postgresql.pljava.sqlj.Loader
cannot be cast to java.net.URLClassLoader

********** Error **********

or select test.getCP(2); something completly different ..
"/C:/Program%20Files/PostgreSQL/9.0/data/Program%20FilesPostgreSQL9.0pljavapljava.jar;/C:/Program%20Files/PostgreSQL/9.0/data/;/C:/Program%20Files%20(x86)/Java/jre6/lib/ext/QTJava.zip;/C:/Program%20Files/PostgreSQL/9.0/pljava/pljava.jar;/C:/Program%20Files/PostgreSQL/9.0/pljava/deploy.jar;/C:/Program%20Files%20(x86)/PostgreSQL/pgJDBC/postgresql-8.4-702.jdbc4.jar;"

Any Ideas how to solve this?

Thx and cheers
Chris

PS As a dirty workaround I could add every jar into my environment classpath
... I think ...
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.pgfoundry.org/pipermail/pljava-dev/attachments/20110706/25f056da/attachment.html>

Responses

Browse pljava-dev by date

  From Date Subject
Next Message Christian Kindler 2011-07-07 05:17:52 [Pljava-dev] Where can I increase the connection / network timeout settings?
Previous Message sumo 2011-07-01 23:39:59 [Pljava-dev] Internal datatype