简体   繁体   English

在Eclipse中将Java类集成到PyDev项目(Jython)中

[英]Integrating a Java Class into a PyDev Project (Jython) in Eclipse

I have a Java class that i would like to import into my Jython script. 我有一个Java类,我想导入到我的Jython脚本中。 Unfortunately, eclipse won't let me create a Java class inside my Jython project.In the window, where you create and name your Java class, I get a message at the top (alongside a red cross) saying, "Source folder is not a Java project" when I type the name of the would be class. 不幸的是,eclipse不允许我在Jython项目中创建Java类。在创建和命名Java类的窗口中,我在顶部(带有红叉)显示一条消息,说:“ Source文件夹不是Java项目”,当我输入的名称时将是class。 How do I rectify this? 我该如何纠正? I need the Java Class to call C code using the JNI (declaring the native method,loading and then calling it). 我需要Java类使用JNI调用C代码(声明本机方法,加载然后调用它)。 Thank You !!!!!!! 谢谢 !!!!!!!

What you can do is to create second module which would be java project. 您可以做的是创建第二个模块,该模块将是java项目。 Anyhow, logically it should be that way. 无论如何,从逻辑上讲应该是这样。 Please check out other similar question - PyDev: Jython modules & Java classes in the same project . 请检查其他类似问题-PyDev:同一项目中的Jython模块和Java类

Other links that might help - http://pydev.org/manual_101_project_conf2.html 其他可能有用的链接-http://pydev.org/manual_101_project_conf2.html

So what nefo_x suggested is correct. 所以nefo_x建议的是正确的。 You need to create a new Java project that will contain your Java class. 您需要创建一个包含Java类的新Java项目。 Then import the Java package as you would a python module. 然后像导入python模块一样导入Java包。 But there are a few things to watch out for in eclipse to make it work. 但是,在日食中需要注意一些事项以使其起作用。 I list the whole process below: 我在下面列出了整个过程:

  1. Your Java class (or classes) should not be in the default package. 您的Java类(或多个类)不应位于默认软件包中。 You need to create a new package and make/put your java class files there. 您需要创建一个新程序包,然后在其中制作/放置您的Java类文件。

  2. Export the package as a jar file to some place on your computer. 将程序包作为jar文件导出到计算机上的某个位置。

  3. Add the jar file (located at some place on your computer) to your python path. 将jar文件(位于计算机上的某个位置)添加到python路径。

  4. Import the package by writing "import PackageName". 通过编写“导入PackageName”来导入软件包。

The problem for me was that I had my java class in the default package. 对我来说,问题是我的Java类位于默认程序包中。 That does not work due to some naming issues. 由于某些命名问题,这不起作用。 Anyhow, hope that this helps. 无论如何,希望这会有所帮助。

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

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