[graalvm-users] JDBC driver, classloaders

Andreas Mueller am at iit.de
Fri Mar 27 06:35:03 PDT 2020


Hi,

I’m running into a problem while dynamically loading a Postgres JDBC driver in GraalVM 20.0.0:

No suitable driver found for jdbc:postgresql://…

The jar file of the driver is loaded and wrapped in its own class loader which is only accessible from that script:

ScriptEngineManager manager = new ScriptEngineManager();
Thread.currentThread().setContextClassLoader(createClassLoader()); // <— here
ScriptEngine engine = null;
if (ISGRAAL)
    engine = GraalSetup.engine();
else
    engine = manager.getEngineByName((String) entity.getProperty("script-language").getValue());
if (engine == null)
    throw new Exception("Engine for script-language '" + entity.getProperty("script-language").getValue() + "' not found!");
ScriptContext newContext = new SimpleScriptContext();
streamContext.engineScope = engine.createBindings();
streamContext.engineScope.put("stream", streamContext.stream);
streamContext.engineScope.put("parameters", new Parameters((EntityList) entity.getEntity("parameters")));
streamContext.engineScope.put("time", new TimeSupport());
streamContext.engineScope.put("os", new OsSupport());
streamContext.engineScope.put("repository", repositorySupport);
streamContext.engineScope.put("transform", new ContentTransformer());
streamContext.engineScope.put("typeconvert", new TypeConverter());
newContext.setBindings(streamContext.engineScope, ScriptContext.ENGINE_SCOPE);

engine.eval(loadScript((String) entity.getProperty("script-file").getValue()), newContext);
Thread.currentThread().setContextClassLoader(null); // <— set to null according to Nashorn docs

This works fine in Nashorn.

Any hints?

Thanks,
Andreas

-- 
Andreas Mueller
IIT Software GmbH
https://urldefense.com/v3/__http://www.swiftmq.com__;!!GqivPVa7Brio!Ms2XkShgysH4XgRTk7KWA2cYKkEkn-BGaOdnj-hIFeZlRXR07RK2UNIL8soXerc-iB0sFw$  <https://urldefense.com/v3/__http://www.swiftmq.com__;!!GqivPVa7Brio!Ms2XkShgysH4XgRTk7KWA2cYKkEkn-BGaOdnj-hIFeZlRXR07RK2UNIL8soXerc-iB0sFw$ > 


-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://oss.oracle.com/pipermail/graalvm-users/attachments/20200327/20977f9a/attachment.html 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: swiftmq_logo_positiv.png
Type: image/png
Size: 10241 bytes
Desc: not available
Url : http://oss.oracle.com/pipermail/graalvm-users/attachments/20200327/20977f9a/attachment.png 


More information about the GraalVM-Users mailing list