PyDev: ImportError when trying to invoke a custom Java method using Jython in Eclipse

My question is similar to ImportErrorCmd , but I am using Windows and trying to run this DAMN thing in PyDev Eclipse. I know how to make it work with cmd, but not in Eclipse.

Question

Anyway, here I am trying to get this @ ImportErrorSimpleExample to work (the solution didn't work there), In Eclipse, I created a Java project with this code: (link -> C: \ Users \ compski \ workspace \ test \ src \ test \ Greeter.java)

package test;

public class Greeter {

private String msg;

  public Greeter() {
     msg = "Hello, ";
  }

  public void greet(String name) {
     System.out.println(msg + name);
  }

}

      

In Eclipse also I created a PyDev project with Jython code named me.py: (link -> C: \ Users \ compski \ workspace \ Jython \ Test \ me.py)

from test import Greeter

g = Greeter()
g.greet("yours truly")

      

Attempts to fix "ImportError" but failed:

1) I tried adding my java code to PYTHONPATH (C: \ Users \ compski \ workspace \ test \ src \ test \ Greeter.java and C: \ Users \ compski \ workspace \ test \ src \ test) as in here → Proposed solution 1 . Still not working

2) I have set my Java project to PyDev project (Rightclick Java project -> PyDev -> Install as Pydev project but I don't have any "bin folders". Then I also link to the Java Project containing Greeter. Java for my PyDev project like here -> Proposed solution 2. Still doesn't work

3) 1 guy from a chat on SO told me I need "you need to add directories, jars from which java will look for the classes you give it c: \ foo \ bar \ bazand import zyxxy.Frobnicator then it looks for c: \ foo \ bar \ baz \ xyzzy \ Frobnicator "but I don't think I fully understand what he meant because it sounds like I did it in 1)

4) ...... your answer?

+3


source to share


1 answer


So now that we have the real filenames: given PYTHONPATH

of C:\Users\compski\workspace\test\src\test

, after execution from test import Greeter

, it will try to find Greeter.class

in each record PYTHONPATH

; that is, it tries to find C:\Users\compski\workspace\test\src\test\test\Greeter.class

and C:\Users\compski\workspace\test\src\test\Greeter.java\test\Greeter.class

, none of which exists.

Instead in Eclipse, if I remember correctly, you can add the project to PYTHONPATH

, this may be preferable for testing in the IDE, so just add the project test

as such to PITONPAT. Another option is to add the directory from which it was found test\Greeter.class

; i.e. in Eclipse it should be C:\Users\compski\workspace\test\bin

, i.e. by default Java-natured projects compile files from src

to a (hidden) folder bin

in the project.



Finally, if the error about GreeterClass is not found in test

, note that test

is the built-in python module name (although IIRC Jython does not have a module by that name).

+1


source







All Articles