简体   繁体   English

PyDev:同一项目中的Jython模块和Java类

[英]PyDev: Jython modules & Java classes in the same project

I come from a Java world and am totally new to Jython. 我来自Java世界,对Jython完全陌生。

Is it possible to create a project in Eclipse with both Jython and Java classes on the same project? 是否可以在Eclipse中使用Jython和Java类在同一项目中创建一个项目? I tried to do so -writing a simple Java class and using it in Jython module- and everything went fine during coding. 我试图这样做(编写一个简单的Java类并在Jython模块中使用它),并且在编码过程中一切正常。 But when I try to run the project I get: 但是当我尝试运行项目时,我得到:

Traceback (most recent call last):
File "/home/bahman/Work/Jython/TestJython/src/com/bahmanm/Main.py", line 1, in <module>
from com.bahmanm import Greeter
ImportError: cannot import name Greeter

The Java class is: package com.bahmanm; Java类是:包com.bahmanm;

public class Greeter {

 private String msg;

 public Greeter() {
  msg = "Hello, ";
 }

 public void greet(String name) {
  System.out.println(msg + name);
 }

}

And the Jython module is quite simple: Jython模块非常简单:

from com.bahmanm import Greeter
g = Greeter()
g.greet("Bahman")

I'd appreciate any ideas/hints. 我将不胜感激任何想法/提示。

Add your java-code to the Pythonpath of your jython-project 将Java代码添加到jython-project的Pythonpath中

Project 项目

Properties -> PyDev PYTHONPATH -> External Libraries 属性-> PyDev PYTHONPATH->外部库

try adding 尝试添加

import java 导入java

at the top 在顶部

when u run it, u add jars to jython's build path with: 当您运行它时,您可以使用以下命令将罐子添加到jython的构建路径中:

jython -Dpython.path=[jarname] [pyfilename] jython -Dpython.path = [jarname] [pyfilename]

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

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