开发者

PyDev: Jython modules & Java classes in the same project

开发者 https://www.devze.com 2023-01-14 13:56 出处:网络
I come from a Java world and am totally new to Jython. Is it possible to create a project in Eclipse with both Jython and Java classes on the same project?I tried to do so -writing a simple Java clas

I come from a Java world and am totally new to Jython.

Is it possible to create a project in Eclipse with both Jython and Java classes on the same project? I tried to do so -writing a simple Java class and using it in Jython module- and everything went fine during coding. 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;

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:

开发者_开发百科
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

Project

Properties -> PyDev PYTHONPATH -> External Libraries


try adding

import java

at the top


when u run it, u add jars to jython's build path with:

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

0

精彩评论

暂无评论...
验证码 换一张
取 消