Re: Loading .java Files

<[email protected]> Sun, 26 Jun 2011 16:22:32 +0200
Newsgroups gmane.comp.java.beanshell.user
Message-ID <7B6FD34D970546C3B1C8BB6EDC80BDB8@msrvcn04>
> That is a worthwhile goal but I believe your making a 
> fundamental mistake
> assuming that beanshell is java.
> It is not. 

Of cause not.

> It is similar to java but it is not identical to java.
> Using a Java IDE is useful but if it thinks your editing 
> beanshell code it
> will give you false information.

Hm, this I do not understand.

> If you want to edit and dynamically compile and load pure 
> java I suggest
> using the Javac classes for this instead of beanshell.  Then 
> you load the
> bytecode with a classloader and it becomes java directly.

It's a webapp running in a servlet container. Would be quite complicated
compared to bsh with all these compiling and classloader issues...

> By "interfaces" I mean the Beanshell method of magically 
> converting bsh
> scripts into interfaces as described here:
> 
> http://www.beanshell.org/manual/embeddedmode.html#Calling_Bean
> Shell_From_Jav
> a
> 
> In the section "Getting Interfaces from the Interpreter".
> You do not need to implement classes that implement interfaces. 
> Rather you implement a bsh script who's global methods just 
> happen to match
> those of a Java interface.
> 
> For example:
> In java:
> 
> interface Foo {
>    void bar();
> };
> 
> 
> interpreter.eval("bar() { }");  // executes the bash code 
> "bar() {}"  and
> places it into the interpreter
> 
> Foo foo = (Foo) interpreter.getInterface( Foo.calss );
> foo.bar();	// calls the bsh method "bar"

Cool feature! But it seem that this does not work, when the bsh-.script is
in a class

Runnable r =(Runnable)interpreter.getInterface(Runnable.class);
r.run();

Caused by: Method run() not found in bsh scripted object: global : at Line:
-1 : in file: <Called from Java Code> : <Compiled Java Code>

	at bsh.This.invokeMethod(Unknown Source)
	at bsh.This.invokeMethod(Unknown Source)
	at bsh.XThis$Handler.invokeImpl(Unknown Source)
	at bsh.XThis$Handler.invoke(Unknown Source)
	... 113 more


In the moment I help me out be removing "... class ... {" and the last "}"
from the script before I load it into the interpreter. Not that elegant ;)

Thank you!


P.S. Is bsh still under development?


------------------------------------------------------------------------------
All of the data generated in your IT infrastructure is seriously valuable.
Why? It contains a definitive record of application performance, security 
threats, fraudulent activity, and more. Splunk takes this data and makes 
sense of it. IT sense. And common sense.
http://p.sf.net/sfu/splunk-d2d-c2