I asked this question on the bsf-user mailing list but it doesnt seem
to be very active. The bsf-user archieve at
http://mail-archives.eu.apache.org/mod_mbox/jakarta-bsf-usr/ is also
not available. I'm working on an opensource project
http://code.google.com/p/wulumuqi/ that integrates BSF. Any help
getting BSF to use URLClassLoaders will be much appreciated.

thanks,
Sonny

---------- Forwarded message ----------
From: Sonny To <[EMAIL PROTECTED]>
Date: Oct 16, 2006 3:47 PM
Subject: BSFManager.setClassLoader doesn't seem to work
To: [email protected]


Hi,

I am trying to use URLClassLoader with BSFManager so that it loads
classes from my webserver.  The following code does not seem to work:

package net.omnivention.bsf;

import java.net.URL;
import java.net.URLClassLoader;

import org.apache.bsf.BSFManager;
import org.python.core.PySystemState;

public class WuluClassLoaderTest {

       public static void main(String[] args) throws Exception {
               BSFManager.registerScriptingEngine("ruby",
"org.jruby.javasupport.bsf.JRubyEngine", new String[] { "rb" });
               BSFManager manager = new BSFManager();
               manager.loadScriptingEngine("ruby");
               manager.loadScriptingEngine("jython");
               URLClassLoader clzLoader = new URLClassLoader(new URL[]{ new
URL("http://linuxjedi.omnivention.net/~son/";) });

               Class<?> clz =
clzLoader.loadClass("cn.com.blackdragonmedia.Address");
               System.out.println("clz="+clz);
               manager.setClassLoader(clzLoader);
               System.out.println(manager.getClassLoader());

               PySystemState.add_package("cn.com.blackdragonmedia");
               manager.exec("jython", "abc", 0, 0, "from
cn.com.blackdragonmedia
import Address");
               manager.exec("ruby", "abc", 0, 0, "include_class
cn.com.blackdragonmedia.Address'");
       }
}
URLClassLoader is loading the class when using
clzLoader.loadClass("cn.com.blackdragonmedia.Address")
but not when I run the python script and ruby script to import the class

for python, I get
Exception in thread "main" org.apache.bsf.BSFException: exception from Jython:
Traceback (innermost last):
 File "<string>", line 1, in ?
ImportError: cannot import name Address

       at org.apache.bsf.engines.jython.JythonEngine.exec(JythonEngine.java:146)
       at org.apache.bsf.BSFManager$6.run(BSFManager.java:493)
       at java.security.AccessController.doPrivileged(Native Method)
       at org.apache.bsf.BSFManager.exec(BSFManager.java:491)
       at 
net.omnivention.bsf.WuluClassLoaderTest.main(WuluClassLoaderTest.java:24)

for ruby, I get

Exception in thread "main" org.apache.bsf.BSFException: Exception
       at org.jruby.javasupport.bsf.JRubyEngine.exec(JRubyEngine.java:110)
       at org.apache.bsf.BSFManager$6.run(BSFManager.java:493)
       at java.security.AccessController.doPrivileged(Native Method)
       at org.apache.bsf.BSFManager.exec(BSFManager.java:491)
       at 
net.omnivention.bsf.WuluClassLoaderTest.main(WuluClassLoaderTest.java:25)

Any idea how to BSF to use URLClassLoader?

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to