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

Created on 2009-10-05.21:00:07 by heuermh, last changed 2018-03-07.19:42:34 by jeff.allen.

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,
msg10628 (view) Author: Jim Baker (zyasoft) Date: 2016-01-11.04:41:41
Revisit in 2.7.2, possibly related to other changes we will be having in terms in build packaging (#2182)
msg11763 (view) Author: Jeff Allen (jeff.allen) Date: 2018-03-07.19:42:34
Tagging as gradle-related because of Jim's comment, so it gets brought in.
Date User Action Args
2018-03-07 19:42:34jeff.allensetkeywords: + gradle
nosy: + jeff.allen
messages: + msg11763
milestone: Jython 2.7.2 ->
2016-01-11 04:41:41zyasoftsetversions: + Jython 2.7, - Jython 2.5
messages: + msg10628
milestone: Jython 2.7.2
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