How can I call java code dynamically?

How can I write Java code that runs as javascript code used with the eval function?

What I would like to achieve would be something like this:

System.execute ("String str = \" test \ "; System.out.println (str);");

which prints the word test. (10x dehman)

Sample code will help a lot.

+1
source share
4 answers

Take a look at BeanShell or Groovy. Both will provide you with reasonable solutions, but these solutions rely on my interpretation of your problem, which may be corrupted.

+4
source

I used the JavaScript engine that came with Java 6 and it works very well. Engine performance is very decent.

Check out the page http://java.sun.com/javase/6/docs/technotes/guides/scripting/programmer_guide/index.html

+1
source

I believe the compiler API is present in current Java SE 6. See javadoc .

See this blog post for more details.

+1
source

For full use, the compiler API is included in the next version of Java.

0
source

All Articles