Last active
July 11, 2016 10:18
-
-
Save peschwa/3737153e73cd04718ebb0d6aa5184ffd to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ ./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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | |
} | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ 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