Skip to content

Instantly share code, notes, and snippets.

@peschwa
Last active July 11, 2016 10:18
Show Gist options
  • Save peschwa/3737153e73cd04718ebb0d6aa5184ffd to your computer and use it in GitHub Desktop.
Save peschwa/3737153e73cd04718ebb0d6aa5184ffd to your computer and use it in GitHub Desktop.
$ ./perl6-j -e'use lib q[java#/home/psch/rakudo/javatests/]; use Foo:from<Java>'
path: file:/home/psch/rakudo/javatests/
name: Foo
urls in urlcl: file:/home/psch/rakudo/javatests/
===SORRY!===
java.lang.RuntimeException: java.lang.ClassNotFoundException: Foo
public SixModelObject typeForName(String name, String path) {
Class<?> klass = null;
path = "file:" + path;
if (!path.endsWith("jar") && !path.endsWith("class"))
path = path + "/";
System.err.println("path: " + path + "\nname: " + name);
try {
URLClassLoader urlcl = new URLClassLoader(new URL[] { new URL(path) },
ClassLoader.getSystemClassLoader());
for (URL url : urlcl.getURLs())
System.err.println("urls in urlcl: " + url);
klass = urlcl.loadClass(name);
}
catch( MalformedURLException mue ) {
throw ExceptionHandling.dieInternal(gc.getCurrentThreadContext(), mue);
}
catch( ClassNotFoundException cnfe ) {
throw ExceptionHandling.dieInternal(gc.getCurrentThreadContext(), cnfe);
}
return getSTableForClass(klass).WHAT;
}
$ cat Bar.java
public class Bar {
public static void main(String... args) {
Class<?> cl = null;
try {
java.net.URLClassLoader urlcl = new java.net.URLClassLoader(
new java.net.URL[] { new java.net.URL("file:/home/psch/rakudo/javatests/") });
cl = urlcl.loadClass("Foo");
}
catch (Throwable t) {
System.out.println("blerg: " + t);
}
System.out.println("found: " + cl);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment