Created attachment 29896 [details] Example for testing When an application uses JSR223 and is executed from ant, it's not possible obtain ScriptEngine for "JavaScript". Same application, from command line, works perfectly. This error is obtain: ScriptEngineManager providers.next(): javax.script.ScriptEngineFactory: Provider com.sun.script.javascript.RhinoScriptEngineFactory not found I attach an eclipse project with this very simple example: Class: package testing; import javax.script.ScriptEngine; import javax.script.ScriptEngineManager; public class TestingGetEngineJavascript { public static void main(String[] args) { new TestingGetEngineJavascript().test(); } public void test() { ScriptEngineManager manager = new ScriptEngineManager(); ScriptEngine engine = manager.getEngineByName("JavaScript"); if(engine == null) { throw new RuntimeException("Upps!!!!!!! Not ScriptEngine found for JavaScript"); } else { System.out.println("ScriptEngine found for JavaScript"); } } } Ant: <project name="test" default="test" basedir="."> <target name="test"> <java classpath="dist/testAntJSR223.jar" classname="testing.TestingGetEngineJavascript"> </java> </target> </project>
There are a "temporal" workaround: use fork="true" But I think that it's a bug.
You should always use fork="true" for user programs. fork="false" is only appropriate for running things that you expect to interact with the live Ant internal data structures. Whether it is a (fixable) bug that ScriptEngineFactory behaves this way for JS inside Ant, I am not sure.
This JSR223 application is an utility to process files. At the moment, I execute this directly as an application, but my idea is build an ANT Plugin (Now I'm busy, but in a short time I must to do). In other cases, when I built a ANT Plugin, I didn't have to modified my code. I suppose that I could force execution of the plugin as a fork. Is this supposition correct?