views:

208

answers:

3

Hi, I'm trying to write Jython where the Python file imports classes from Java I'm using Eclipse with PyDev.

My Python code looks like:

from eclipsejavatest import eclipseJavaTest
from eclipsejavatest import JavaClass

class eclipsePyPrint(eclipseJavaTest):
    def eclipsepyMain(self):
        print "python main method"
        eclipseJavaTest.printerCount(4)
        print eclipseJavaTest.gotoPython()
        eclipseJavaTest.printerSentence()

        samplepyClass = JavaClass("Jython plain")
        samplepyClass.setName("jython fancy")
        print samplepyClass.getName()

but I'm getting the error ImportError: No module named eclipsejavatest

The Python project references the Java project. I've tried exporting the Java project and adding the .jar to the Jython Class Path for the Python project.

I'm not sure what to do to get this to work.

A: 

Try :

import eclipsejavatest.eclipseJavaTest as eclipseJavaTest
Blauohr
A: 

Figured it out - I had to right click the java package and set it as a pydev project Then I had to go into the python project and add the .class files

JChao
A: 

I am also using Eclipse with Pydev. I wanted to call Java classes from a Java project in my workspace from a program inside a Jython project folder. I did NOT have to right click on the java package and set it as a pydev project. In my setup the java source folder would not show up when I tried to add it to the PYTHONPATH regardless of whether I configured it as a Pydev folder. I had to add it as an external library.

I right-clicked on the Jython project, selected properties, selected PyDev - PYTHONPATH, selected the External Libraries tab, and then selected the add source folder button. I added the folder with the .class files from the java project; C:\blah blah blah\workspace\javafoldername\bin. At first I tried to use ...\javafoldername\src to add the .java files but that didn't work.

emclaus