Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PyDev: Jython modules & Java classes in the same project

Tags:

java

jython

pydev

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.

like image 550
BahmanM Avatar asked Aug 29 '10 18:08

BahmanM


People also ask

What is a PyDev module?

A "PyDev Package" is a Python package. This means that it contains a file called __init__.py . For example, if you create a new PyDev Package with name foo , then you will get file foo/__init__.py . You can place other .py files into foo/ , which you can then import.

Can Jython use Python libraries?

Jython does *not* support third-party Python libraries that use extensions written in C. This means that popular Python libraries like numpy, scipy and scikit-learn will not work in Jython (and, for this reason, will not work in Processing.py).

Does PyDev support python3?

Note: this will be the last debugger version supporting Python 2.7. Newer releases will target only Python 3.6 onwards.

How do I run Python in PyDev?

The easiest way of launching a python file from PyDev is opening an editor and using the F9 keybinding.


1 Answers

Add your java-code to the Pythonpath of your jython-project

Project

Properties -> PyDev PYTHONPATH -> External Libraries

like image 79
Blauohr Avatar answered Sep 23 '22 15:09

Blauohr