Title: JSR223 ScriptEngineManager cannot find both jython and jruby ScriptEngines when using maven assembly plugin
Type: Severity: normal
Components: Versions: Jython 2.5
Status: open Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: fwierzbicki, heuermh, j13r, zyasoft
Priority: low Keywords:

Created on 2009-10-05.21:00:07 by heuermh, last changed 2013-02-25.19:04:52 by fwierzbicki.

File name Uploaded Description Edit Remove
jruby-jsr223.tar.gz heuermh, 2009-10-05.21:00:05 JSR223 example maven assembly project
msg5218 (view) Author: Michael Heuer (heuermh) Date: 2009-10-05.21:00:05
See attached example maven project.

If both jruby and jython are enabled using runtime dependencies*


then the jar-with-dependencies assembly jar will fail to register both
ScriptEngine implementations

$ mvn assembly:assembly
$ java -jar target/example-1.0-SNAPSHOT-jar-with-dependencies.jar
could not find jruby engine

whereas creating an explicit classpath works fine

$ java -classpath

It appears the JSR223 mechanism cannot handle multiple copies of its
metadata in example-1.0-SNAPSHOT-jar-with-dependencies.jar.

$ jar tvf target/example-1.0-SNAPSHOT-jar-with-dependencies.jar | grep
42 Wed Sep 16 13:39:46 CDT 2009
40 Sat Sep 26 13:48:04 CDT 2009

    * - please note a jython-2.5.1.jar artifact is not yet available on
maven central repo, will have to be installed manually

This issue has also been posted to the JRuby issue tracker at:
msg6005 (view) Author: Jim Baker (zyasoft) Date: 2010-08-22.22:45:51
Seems like a problem with JSR223 itself, reading the JRuby bug. Keeping it open so we can track.
msg6605 (view) Author: Johannes Buchner (j13r) Date: 2011-08-17.01:42:28
It actually does work. Let me explain.
Both the jruby and the jython dependencies put a javax.script.ScriptEngineFactory file in the META-INF directory. Jar/Zip allows multiple files with the same name (they are just named records, one after another). But when java reads the jar, it only reads the first (or last) of those records/files. So it will only read one of the ScriptEngineFactories.

What is needed is that the ScriptEngineFactory is merged. You can do it manually by putting this file (with both lines) into your project. Possibly, you have to check the final jar that only your ScriptEngineFactory is there. 

With maven, you can tell it to not forbid this file from the dependencies (so your file is used only). A proper solution would be a mojo that merges the javax.script.ScriptEngineFactory entries.
An even better solution would be if the JSR223 read files from a directory in the jar (e.g. META-INF/services/javax.script.ScriptEngineFactory/*)

Hope this helps,
Date User Action Args
2013-02-25 19:04:52fwierzbickisetnosy: + fwierzbicki
versions: + Jython 2.5, - 2.5.1
2011-08-17 01:42:29j13rsetnosy: + j13r
messages: + msg6605
2010-08-22 22:45:51zyasoftsetpriority: low
nosy: + zyasoft
messages: + msg6005
2009-10-05 21:00:07heuermhcreate