How to import Java class with Python using Eclipse?

I am trying to write Jython where a Python file imports classes from Java. I am using Eclipse with PyDev.

My Python code looks like this:

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 get an error ImportError: No module named eclipsejavatest

The Python project refers to the Java project. I tried to export a Java project and add .jar to the Jython class path for the Python project.

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

+3
source share
3 answers

Eclipse Pydev. Java Java Jython. java pydev. java , PYTHONPATH, , Pydev. .

Jython, , PyDev - PYTHONPATH, " " " ". .class java; C:\blah blah blah\workspace\javafoldername\bin. ... \javafoldername\src, .java, .

+2

- java pydev python .class

+1

Try:

import eclipsejavatest.eclipseJavaTest as eclipseJavaTest
0
source

Source: https://habr.com/ru/post/1746483/


All Articles