3

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.

3
  • where is the eclipsejavatest module? is it in the same directory as this script? If not you can configure it to be using the project properties -> PYTHON PATH Commented May 21, 2010 at 0:00
  • I tried adding eclipseJavaTest/src to the Python Path, but when I run it, I still get the same error and when I open the properties again, it says it's eclipsePythonTest/src Commented May 21, 2010 at 3:55
  • Did you finally get this to work? I am stuck at this for quite some time! Commented Jun 13, 2015 at 10:02

3 Answers 3

2

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.

Sign up to request clarification or add additional context in comments.

Comments

1

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

1 Comment

Just so you know you have to right click the Java Project not the java package to be able to set it as a pydev project and then in pythonpath you have to add the directory in which the .class files are located as (usually in a bin folder)
0

Try :

import eclipsejavatest.eclipseJavaTest as eclipseJavaTest

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.