0

I'm currently working on a project involve Java and Python. Long story short, I followed some post on ways to access Python file from Java by packaging the file into a jython jar and import into the Java project.

Instead of using "java -jar jython.jar run.py" to call the run.py, anybody know if there is way to call the file from Eclipse (assuming I already add the jython.jar into to my build path?

Thank you so much!

Community
  • 1
  • 1
William
  • 39
  • 2
  • 8

1 Answers1

0

Drag this image in the entry bar in your browser. The PythonInterpreter executes test.py.

Jython

Malik Brahimi
  • 16,341
  • 7
  • 39
  • 70
  • How is this William? I've tried you walk you through completely. – Malik Brahimi Jan 24 '15 at 00:36
  • Hello Malik, really appreciate you spend time on explaining this. I know how to add jar to build path and use jython jar. My real question is, I have package a python file in the jar, say print hello world, it's not part of the jython.jar. Through command line I can do this "java -jar jython.jar print.py" and it will call the python. Now I want to know how to do this in Eclipse...Thanks for your effort. – William Jan 24 '15 at 19:20
  • I believe so but why would you package `script.py` in `jython.jar`? You can export your whole Eclipse project to a jar as is. – Malik Brahimi Jan 26 '15 at 20:53
  • Yes, but in your case, if you export your project to a jar, you won't be able to call test.py anymore because test.py will be in a zip file, your src/test.py won't work. – William Jan 26 '15 at 22:09
  • I think it will work `src/test.py` will just be contained within the JAR. – Malik Brahimi Jan 26 '15 at 22:10
  • I just tested and it is not working. That's exactly where my question come from. Let's say if python code can directly called by a Java in a jar (both files are in the same jar) then I would'n even need to package it anywhere. – William Jan 26 '15 at 22:12
  • Then place the python file out of the project and use a relative path. – Malik Brahimi Jan 26 '15 at 22:14
  • The python script contains the algorithm of the engine, I'm trying to discover a way to hide the code while be able to call the function. – William Jan 26 '15 at 22:20
  • Then place the python file out of the project and use a relative path. Make the python file a hidden file so that no one has to see it. – Malik Brahimi Jan 26 '15 at 22:23
  • Sure, then see you around I guess. – Malik Brahimi Jan 26 '15 at 22:30