I am writing a compiler in Python using Eclipse with PyDev. I've come to a stage where I needed to write some code in Java. I'm wandering if there is a way of combining these into a single project, because at the moment I have two separate projects, and whenever I need to change the Java code, I have to manually copy the .class file into the Python project.
If this is not possible, what would you suggest is the most elegant way of structuring the files of these projects, and how should I set up my build process?
Thanks.
First of all, there is no predefined eclipse build for python. You can simply install the "Java developer" one and then manually add python support via the eclipse marketplace, for example by installing the pydev plugin. Show activity on this post. You can go ahead with Eclipse IDE for Java EE Developers.
Python is an object-oriented scripting language, which automatically makes it a good pair for Java. But when combined with a Python interpreter written entirely in Java, like Jython, you could do things like write entire applets in Python.
You can use Java Runtime. exec() to run python script, As an example first create a python script file using shebang and then set it executable. Hope this helps and if not then its recommended to join our Java training class and learn about Java in detail.
Running Python from within Eclipse py, and Eclipse will recognize it as Python code. Type in some Python code (for instance: print 2+2 ), then right-click on the Python file you've created and select Run As >> Python run . You should see the output of your Python code in the console at the bottom of the Eclipse window.
You can keep things in separate projects without having to copy the .class files to the Python project provided that you make that project a PyDev project and add the place that contains the .class files (i.e.: bin folder) as a source folder in the PyDev configuration (and reference that project from your Python project).
Take a look at "Project reference for Jython users" (in the end of http://pydev.org/manual_101_project_conf2.html).
I think you could also do what you asked in your question: create a java project, set it as a PyDev project too (right click that project > pydev > set as pydev project) and configure the PyDev project properties setting the PYTHONPATH to the place where you have your Python files and add another entry to the bin
folder (i.e.: where the .class files exist). Not sure if it'd be better to keep those as 2 separated projects though.
I think Jython would be ideal here, as the Python code essentially gets translated to Java bytecode and run on the Java virtual machine, making it easy to communicate between the two. Also, pydev itself integrates well with Jython.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With