eval static scope of System.load (For JNI used)

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

eval static scope of System.load (For JNI used)

yccheok
 Hello all,
 
 I have a class library, which made access to JNI method. I try to write a simple beanshell script to acess the compiled class, no problem for that.
 
 E:\jnitest>type test.bsh
 import mypackage.*;
 
 new hello().sayhi();
 
 E:\jnitest>type mypackage\hello.java
 package mypackage;
 
 public class hello
 {
     public native static void sayhi();
 
     static {
         System.load("C:/WINDOWS/system32/nativelib.dll");
     }
 }
 
 E:\jnitest>javac mypackage\hello.java
 
 E:\jnitest>java bsh.Interpreter test.bsh
 hello from c++
 
 Now, instead of compiled class, I would like the beanshell to eval the class in source form. Since most of the time, we are required to change the software requirement on the fly at customer place.
 
 E:\jnitest>del mypackage\hello.class
 
 E:\jnitest>java bsh.Interpreter test.bsh
 Loading class from source file: /mypackage/hello.java
 Parse error at line 7, column 5.  Encountered: static
 Class not found in source file: mypackage.hello
 Evaluation Error: Sourced file: test.bsh : Unknown class: hello : at Line: 3 : i
 n file: test.bsh : new hello ( )
 
 It seems that beanshell fail to eval static{} statement from JAVA source file.
 
 I try a workaround. By having System.load statement inside BSH script.
 
 E:\jnitest>edit test.bsh
 
 E:\jnitest>edit mypackage\hello.java
 
 E:\jnitest>type test.bsh
 import mypackage.*;
 
 System.load("c:/WINDOWS/system32/nativelib.dll");
 
 new hello().sayhi();
 
 E:\jnitest>type mypackage\hello.java
 package mypackage;
 
 public class hello
 {
     public native static void sayhi();
 
     //static {
     //    System.load("C:/WINDOWS/system32/nativelib.dll");
     //}
 }
 
 E:\jnitest>java bsh.Interpreter test.bsh
 Loading class from source file: /mypackage/hello.java
 Class not found in source file: mypackage.hello
 Script threw exception: Sourced file: test.bsh : Method Invocation sayhi : at Li
 ne: 5 : in file: test.bsh : .sayhi ( )
 
 Target exception: java.lang.NullPointerException
 
 java.lang.NullPointerException
         at bsh.BshMethod.invokeImpl(Unknown Source)
         at bsh.BshMethod.invoke(Unknown Source)
         at bsh.BshMethod.invoke(Unknown Source)
         at bsh.This.invokeMethod(Unknown Source)
         at mypackage.hello.sayhi(BeanShell Generated via ASM (www.objectweb.org)
 )
         at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
         at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
         at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
         at java.lang.reflect.Method.invoke(Unknown Source)
         at bsh.Reflect.invokeMethod(Unknown Source)
         at bsh.Reflect.invokeObjectMethod(Unknown Source)
         at bsh.BSHPrimarySuffix.doName(Unknown Source)
         at bsh.BSHPrimarySuffix.doSuffix(Unknown Source)
         at bsh.BSHPrimaryExpression.eval(Unknown Source)
         at bsh.BSHPrimaryExpression.eval(Unknown Source)
         at bsh.Interpreter.eval(Unknown Source)
         at bsh.Interpreter.source(Unknown Source)
         at bsh.Interpreter.main(Unknown Source)
 
 Again. nope :(
 
 May I know what is the best practice to integrate source code form Java file (with JNI, static System.load statement) together with beanshell script?
 
 Thank you very much!


-------------------------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
_______________________________________________
Beanshell-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/beanshell-users