简体   繁体   English

在一个Eclipse项目中集成Java和Python代码

[英]Integration of Java and Python Code in One Eclipse Project

I am writing a compiler in Python using Eclipse with PyDev. 我正在使用Eclipse和PyDev在Python中编写一个编译器。 I've come to a stage where I needed to write some code in Java. 我来到了一个需要用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. 如果有一种方法可以将这些组合到一个项目中,我就会徘徊,因为目前我有两个独立的项目,每当我需要更改Java代码时,我必须手动将.class文件复制到Python项目中。

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. 谢谢。

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 (ie: bin folder) as a source folder in the PyDev configuration (and reference that project from your Python project). 您可以将事物保存在单独的项目中,而无需将.class文件复制到Python项目,前提是您将该项目作为PyDev项目并将包含.class文件的位置(即:bin文件夹)添加为源文件夹。 PyDev配置(以及Python项目中的项目引用)。

Take a look at "Project reference for Jython users" (in the end of http://pydev.org/manual_101_project_conf2.html ). 看看“Jython用户的项目参考”( 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 (ie: where the .class files exist). 我想你也可以做你在问题中提到的:创建一个java项目,将它设置为PyDev项目(右键单击该项目> pydev>设置为pydev项目)并配置PyDev项目属性将PYTHONPATH设置为该位置你有Python文件并在bin文件夹中添加另一个条目(即:存在.class文件的地方)。 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. 我认为Jython在这里是理想的,因为Python代码本质上被转换为Java字节码并在Java虚拟机上运行,​​使得两者之间的通信变得容易。 Also, pydev itself integrates well with Jython. 此外,pydev本身与Jython很好地集成。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM