I created a default Maven Java project and added the following dependency:
<dependency> <groupId>org.python</groupId> <artifactId>jython</artifactId> <version>2.7.0</version> </dependency> Then I created a package src/main/java/mypkg and added this class:
package mypkg; import javax.script.*; class JythonMinimalTest { public static void main(String[] args) throws Exception { String engineName = "python"; ScriptEngineManager manager = new ScriptEngineManager(); ScriptEngine engine = manager.getEngineByName(engineName); if (engine == null) { System.err.println("ERROR: `" + engineName + "` not available."); System.err.println("Available engines: "); for (ScriptEngineFactory factory: manager.getEngineFactories()) { System.err.println(factory); System.err.println("names:"); for (String name: factory.getNames()) { System.err.println(" " + name); } } System.exit(999); } engine.eval("print('hello, world')"); } } When I run it using exec:java,
mvn exec:java -Dexec.mainClass=mypkg.JythonMinimalTest I get the following mysterious output:
ERROR: `python` not available. Available engines: org.python.jsr223.PyScriptEngineFactory@2b0e6c89 names: python jython jdk.nashorn.api.scripting.NashornScriptEngineFactory@46618cb8 names: nashorn Nashorn js JS JavaScript javascript ECMAScript ecmascript The manager returns null, but then in the next line lists python/jython among the available script engines.
Nashorn worked just fine in exactly the same way. What am I doing wrong with Jython?
<maven.compiler.source>1.8</maven.compiler.source> <maven.compiler.target>1.8</maven.compiler.target>, the java itself is also1.8.0.jython-standaloneas artifactId instead ofjython(see comment by Luis Muñoz)?Option.loadSite=falsehacks, it works as expected right away. Note thatjython-standalone.jartakes 40MB instead of 30MB. This solution is mentioned in {the question linked by Andrew in {the question linked by Luis Muñoz}}: whats-the-difference-between-jython-standalone-2-7-0-jar-and-jython-2-7-0-jar, but it has no accepted answers...