Re: Loading .java Files

"David Lee" <[email protected]> Sun, 26 Jun 2011 09:00:15 -0400
Newsgroups gmane.comp.java.beanshell.user
Message-ID <[email protected]>
> Ok you are using "eval".  The terminology ".java" confused me.
> You are loading  a "beanshell" file  not a "java" file.  
> Although they are
> often similar.

The only reason why I want to use .java-Files is that I can edit them in my
IDE with full IDE-support (autocomplete, syntax check etc).
------------------------------------

That is a worthwhile goal but I believe your making a fundamental mistake
assuming that beanshell is java.
It is 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.


===========
What do you mean with "top level"?
===========

In java all methods must be in a class like

class Foo {
   void bar() {} ;
};

In Beanshell methods need not (and usually DO not ) reside in a class. I.e. 

bar() {};


Java and Beanshell are quite different languages in this respect.

By "top level" I mean these methods which are not in classes. They are put
into the "global namespace" which is the namespace used by the
BSHMethod.invoke() method.


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.


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_BeanShell_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"







----------------------------------------
David A. Lee
[email protected]
http://www.xmlsh.org




------------------------------------------------------------------------------
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