2

I'm creating a Java application and will best work if I incorporate Python in it. I'm having jython-standalone-2.7.0.jar lib. My question is, how do I use this lib like create a simple hello world application written in Python and display the output in java? I have Python 3.5 installed. Do I need it too or is there anything else I need? Please help, thanks.

0

1 Answer 1

1

if you're still interested in an answer:

0) Jython isn't supporting Python 3 (so far), only Python 2.7.

1) Create a Python file with a function f.e.:

#hello.py
def printhello():
    print("Hello World from hello.py")

2) Unzip your jython-standalone-2.7.0.jar and add your "hello.py" file into the folder "Lib".

3) Close your jython-standalone-2.7.0.jar again

4) Create your "main file":

#main.py
import hello
print("Hello from main file")
hello.printhello()
print("I'm back in main")

And add it into the same file where your standalone.jar is.

5) In your terminal/cmd execute: java -jar jython-standalone-2.7.0.jar main.py

6) Success (I hope ;-) )

P.S. If you're using Windows, don't use the OS own zip methods, because in my case my jar file was rubbish afterwards.

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

1 Comment

Is there a way to execute the script when the jython-standalone*.jar has been extracted? I am trying write a plugin for an application which deploys jython-standalone in folder format (instead of inside the .jar).

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.