Integration of Java and Python Code in One Eclipse Project

非 Y 不嫁゛ 提交于 2019-12-07 02:17:21

问题


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.


回答1:


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.




回答2:


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.



来源:https://stackoverflow.com/questions/9880736/integration-of-java-and-python-code-in-one-eclipse-project

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!