2

I'm trying to use Jython to integrate a small Python script into a Java program I have. I can't seem to get the python/jython engine using the javax.script package.

I took the code from here with a small addition to produce this:

andrew@asimov:~$ echo $CLASSPATH
/opt/jython/jython.jar:.
andrew@asimov:~$ java Engines
The following 2 scripting engines were found

Engine name: jython
    Version: 2.7.0
    Language: python
    Engine supports the following extensions:
            py
    Engine has the following short names:
            python
            jython
=========================
Engine name: Rhino
    Version: Rhino 1.7 release 4 2013 08 27
    Language: ECMAScript
    Engine supports the following extensions:
            js
    Engine has the following short names:
            js
            rhino
            JavaScript
            javascript
            ECMAScript
            ecmascript
=========================
python engine is null: true
js engine is null: false
andrew@asimov:~$

The code I added is:

String[] engineNames = new String[] {
        "python", "js"
};

for (String engineName : engineNames) {
    ScriptEngine engine = manager.getEngineByName(engineName);
    System.out.printf("%s engine is null: %s\n", engineName, (engine == null));
}

Why am I getting a null python engine?

I ran across this bug, which seemed to suggest that there is (or was) a jython-engine.jar out there, but I'm hanged if I could find it.

3
  • Try "py" instead of "python". Commented Oct 7, 2015 at 17:01
  • @ElliottFrisch same result if I use "py" as the name. I also tried manager.getEngineByExtension("py") to no avail. Commented Oct 7, 2015 at 17:04
  • What version of java are you using? Commented Oct 7, 2015 at 17:06

1 Answer 1

5

Per this question, using jython-standalone.jar rather than jython.jar returns a non-null engine:

andrew@asimov:~$ export CLASSPATH=jython-standalone-2.7.0.jar:.
andrew@asimov:~$ java Engines | tail -11
Engine name: jython
    Version: 2.7.0
    Language: python
    Engine supports the following extensions:
            py
    Engine has the following short names:
            python
            jython
=========================
python engine is null: false
javascript engine is null: false
andrew@asimov:~$

(In my pom.xml, I used <artifactId>jython-standalone</artifactId>)

Curious, but at least I can move on.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.