Skip to content

Instantly share code, notes, and snippets.

@peschwa
Last active August 29, 2015 14:03
Show Gist options
  • Save peschwa/0158083bc4e5613a6390 to your computer and use it in GitHub Desktop.
Save peschwa/0158083bc4e5613a6390 to your computer and use it in GitHub Desktop.
diff --git a/src/vm/jvm/runtime/org/perl6/nqp/runtime/BootJavaInterop.java b/src/vm/jvm/runtime/org/perl6/nqp/runtime/BootJavaInterop.java
index d89e285..5ad323e 100644
--- a/src/vm/jvm/runtime/org/perl6/nqp/runtime/BootJavaInterop.java
+++ b/src/vm/jvm/runtime/org/perl6/nqp/runtime/BootJavaInterop.java
@@ -97,7 +97,31 @@ public class BootJavaInterop {
try {
return getSTableForClass(Class.forName(name)).WHAT;
} catch (ClassNotFoundException e) {
- throw ExceptionHandling.dieInternal(gc.getCurrentThreadContext(), e);
+ try {
+ String cpStr = System.getProperty("java.class.path");
+ String[] cps = cpStr.split("[;:]");
+ File cf = null;
+ for(int i = 0; i < cps.length; i++) {
+ cf = new File(cps[i] + "/" + name + ".class");
+ if(cf.exists())
+ break;
+ cf = null;
+ }
+ if(cf != null) {
+ try {
+ URL url = new URL("file://" + cf.getAbsolutePath()
+ .substring(0, cf.getAbsolutePath().lastIndexOf(cf.separatorChar) + 1));
+ URLClassLoader cl = new URLClassLoader(new URL[] { url });
+ return getSTableForClass(cl.loadClass(name)).WHAT;
+ } catch (MalformedURLException mue) {
+ throw mue;
+ }
+ } else {
+ throw e;
+ }
+ } catch (ClassNotFoundException|MalformedURLException ine) {
+ throw ExceptionHandling.dieInternal(gc.getCurrentThreadContext(), ine);
+ }
}
}
public SixModelObject typeForNameFromJAR(String name, String JAR) {
# Unfortunately, this relies on CLASSPATH *not* being supplied as argument to the java executable, i.e. perl6-j has to look as follows:
#!/bin/sh
CLASSPATH="$CLASSPATH:/home/psch/rakudo/rakudo/install/languages/perl6/runtime:/home/psch/rakudo/rakudo/install/languages/perl6/lib:/home/psch/rakudo/rakudo/install/languages/nqp/lib"
exec java -Xms100m -Xbootclasspath/a:/home/psch/rakudo/rakudo/install/languages/nqp/runtime/asm-4.1.jar:/home/psch/rakudo/rakudo/install/languages/nqp/runtime/asm-tree-4.1.jar:/home/psch/rakudo/rakudo/install/languages/nqp/runtime/jline-1.0.jar:/home/psch/rakudo/rakudo/install/languages/nqp/runtime/jna.jar:/home/psch/rakudo/rakudo/install/languages/nqp/runtime/nqp-runtime.jar:/home/psch/rakudo/rakudo/install/languages/nqp/lib/nqp.jar:/home/psch/rakudo/rakudo/install/languages/perl6/runtime/rakudo-runtime.jar:/home/psch/rakudo/rakudo/install/languages/perl6/runtime/perl6.jar -Dperl6.prefix=/home/psch/rakudo/rakudo/install -Dperl6.execname="$0" perl6 "$@"
# This obviously isn't very platform-independent.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment