In my case I’m trying to import a Java class on Jython. In my project I’m using the Eclipse IDE with a plugin of Model-Driven Development. I was trying import the class at Eclipse but I’m getting the same follow error, but I set my java project as a Pydev project and create a bin folder that own the .class files, what I think that is the right thing to do. So, I start trying import it by my hand at terminal with the interactive Jython and I get the same follow error, by the way, I’m using this resource:
import sys
sys.path.append('/home/hudson/eclipse-projects/new/New/bin.jar')
Whats funny is that when I tried with another .class file, from a different project, I can get it easy.
The error:
>>> sys.path.append(' /home/hudson/eclipse-projects/new/New/bin/org/yakindu/sct/runtime/java/newtest/newtest.jar')
>>> import NewTestCycleBasedStatemachine
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named NewTestCycleBasedStatemachine
I’ve been trying to import the .jar from different directories, just for testing, but still can’t get it.
First of all, I need the solution for the Eclipse, because its a must for the plugin that I need.
So, What could it be?
After I set my Java project as a PyDev project what are the steps specifically? I need to pre-compile my project, compress my project to .jar and add this folder?
I tried import like this
from NewTest import CycleWindow
and get this:
sys-package-mgr: processing modified jar, ‘/home/hudson/eclipse-projects/new/New.jar’
sys-package-mgr: skipping bad jar, ‘/home/hudson/eclipse-projects/new/New.jar’
Traceback (most recent call last):
File “/home/hudson/eclipse-projects/new/Test/src/MainClass.py”, line 1, in
from NewTest import CycleWindow
ImportError: No module named NewTest
I’ve been tried import modifying the pythonpath and etc. For example I can import a SWT Class at my Jython Class but cant import my project. I’m doing the same thing for both:
/home/hudson/Downloads/swt.3.7.2-gtk-linux-x86(1)/swt.jar
/home/hudson/eclipse-projects/new/New/bin.jar
I am beating my head against the wall!
Instead of adding things to sys.path by hand, you should be able to configure the project (right-click project > properties > PyDev PYTHONPATH) to add the jars/folders you want.
See: http://pydev.org/manual_101_project_conf2.html
If this doesn’t solve it, please add more information on how you’re setting the PyDev configuration, how your java classes are structured and how you mounted your java build path (screenshots appreciated for those).