ScriptModule - bugfixes
By chuk on Jul 20, 2006
Sven Reimers has found a major bug in the NetBeans scripting module. The script engines were not initialize when you open a script console; so when you entered any command, the script engine will choke. I've fixed the problem. Thanks Sven.
While was using the jython script engine to test the console and I found a few problems with jython
The jython engine does not honour the classloader in the ScriptEngineManager. The ScriptEngineManager allows you to associate a classloader when you are instantiating it. The idea is to be able to load and create script engines dynamically. I can get a reference to Jython's script engine but when I tried to execute a statement, print(“hello world”), I got a class not found exception on PyRunnable. I was pretty sure that PyRunnable was in the URLClassloader's path that I passed to ScriptEngineManager. Another Sun colleague, Sundar has told me the workaround but I completely forgot about it. It is not enough to have the jython's Jars in the classloader, you have to explicitly set the classloader to the current thread's context classloader.
I could not redirect jython's output to the console. There is a method in the ScriptContext call setWriter that allows you to redirect the engine's output to wherever you like. Again, jython is not honouring this. So the output is displayed to System.out. For those who are using the console, I suggest you write a globals.py file; stick this under console directory. In globals.py redirect all output to Console.println(). Console is an exported object. See the help for more details
The jython engine comes with a set of Python libraries. You can find this under jython_home/lib/python. I do not know Python to test out the environment, so if you are testing, please let me know how this is resolved. I know that you have to set python.path. But currently this is not set, so what is the default?