Issue1485

classification
Title: JSR223 ScriptEngineManager cannot find both jython and jruby ScriptEngines when using maven assembly plugin
Type: Severity: normal
Components: Versions: Jython 2.5
process
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.

Files
File name Uploaded Description Edit Remove
jruby-jsr223.tar.gz heuermh, 2009-10-05.21:00:05 JSR223 example maven assembly project
Messages
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*

pom.xml:
<dependencies>
<dependency>
<groupId>org.jruby</groupId>
<artifactId>jruby</artifactId>
<version>1.4.0RC1</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.python</groupId>
<artifactId>jython</artifactId>
<version>2.5.1</version>
<scope>runtime</scope>
</dependency>
</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
"jython-2.5.1.jar;jruby-1.4.0RC1.jar;target/example-1.0-SNAPSHOT.jar"
example.Jsr223Example
ok

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
javax.script.ScriptEngineFactory
42 Wed Sep 16 13:39:46 CDT 2009
META-INF/services/javax.script.ScriptEngineFactory
40 Sat Sep 26 13:48:04 CDT 2009
META-INF/services/javax.script.ScriptEngineFactory

    * - 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:

http://jira.codehaus.org/browse/JRUBY-4057
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,
Johannes
History
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