scripting feature in java 6
i m using jython script enging in java 6. I have put in the appropriate
jars i.e jython.jar and jython-engine.jar i classpath
The programm-- >
import javax.script.*;
publicclass ScriptTest{
publicstaticvoid main(String[] args){
try
{
ScriptEngineManager factory=new ScriptEngineManager();
ScriptEngine engine=factory.getEngineByName("jython");
//ScriptEngine engine=factory.getEngineByName("JavaScript");
Bindings test=new SimpleBindings();
test.put("SERIESNAME","FMDM");
System.out.println(engine.eval("SERIESNAME in ['xyz', 'etc']" , test ));
//System.out.println(engine.eval(" x = 5 + 7 "));
//System.out.println(engine.eval(" return " ));
}
catch(Exception e)
{
e.printStackTrace();
}
}
}
Each time i m executing this i m gettingnull .rather i should get the result returned by the script .
System.out.println(engine.eval("SERIESNAME == ['xyz', 'etc']" , test ));
when i m changing my script engine to java script i m getting true printed on my console....but with jython i m getting null
[
That is probably becausefactory.getEngineByName("jython");
returns null.
In Sun's standard classes, you can only use JavaScript as of now, no Jython.
If you want to make use of more scripting languages (Jython 2.2 among others), have a look at this project:
https://scripting.dev.java.net/?redirect=SSL
factory.getEngineByName("jython");
This statement does not return null.If it was returning null i wud have got null pointer exception .
And also i m able to exceute script like print. The only point here is tat
it does not return the result after executing the script...
i m able to execute the following --
engine.eval("print hi");
that means jython script engine is working..but its not retunring the result of the script
> factory.getEngineByName("jython");
>
> This statement does not return null.If it was
> returning null i wud have got null pointer exception
> .
That's what I thought when you said "Each time i m executing this i m getting null".
> And also i m able to exceute script like print. The only point here is tat
> it does not return the result after executing the script...
>
> i m able to execute the following --
>
> engine.eval("print hi");
>
> that means jython script engine is working..but its
> not retunring the result of the script
Well, I am pretty sure Java 6 is only bundled with the Mozilla Rhino based JavaScript script engine, no other script engine. It was just a guess of my side that actory.getEngineByName("jython") could return null, but it is definatelly not returning a Jython engine. Look at the API to see what it does return (probably the default JS implementation).
if u have gone thru my first posting i had mentioned the following--
i m using jython script enging in java 6. I have put in the appropriate
jars i.e jython.jar and jython-engine.jar in classpath
By using the above jars u can use jython engine just like javascript engine...
factory.getEngineByName("jython") will either return jython engine or null .it wont return a default JS engine.
> if u have gone thru my first posting i had mentioned
> the following--
Yes, sorry about that, I tend to skip pieces of text from threads I can hardly read. Those horrible abbreviations like u (you) and thru (through) and i m (I'm or I am) make you post hard to read (for me).
I just saw a (for me) unclear message saying something about null and the use of another engine than JavaScript, and assumed the most obvious, which was incorrect. I should've deciphered your post, or not have responded to it. I shall do the last from now on.
Good luck.