I have an Eclipse workspace with several Java projects and one Jython project., and
I want to use some of my Java classes from Jython.
I added a "reference" to the Java project from the Jython project's properties dialog, but this does not make the java classes available. The import statement is
from com.troux.bpserver.standalone import DBConnectionInfoOracle, BlueprintServicesClient
At execution I get "ImportError: no module named troux"
What else do I have to do to get Jython to see my classes?
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Aside from setting it as a reference, you also have to:
1. make the java project a pydev project (right click project > pydev > set as pydev project)
2. Configure that project pythonpath to add the .class files: project properties > pydev - pythonpath > add the source folder(s) that contains your .class files (this would be the folder just one level before your 'com' namespace).
Cheers,
Fabio
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I got around this by building the Java project into a jar and adding the jar to the global PYTHONPATH. Can a jar be added to an individual jython project?
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
That's also a solution (but if you're going to be developing that same project, it can be a bit troublesome, as you have to update your jar whenever you change your java code).
Eclipse Ganymede SR1 (3.4.2)
Pydev 2725
I have an Eclipse workspace with several Java projects and one Jython project., and
I want to use some of my Java classes from Jython.
I added a "reference" to the Java project from the Jython project's properties dialog, but this does not make the java classes available. The import statement is
from com.troux.bpserver.standalone import DBConnectionInfoOracle, BlueprintServicesClient
At execution I get "ImportError: no module named troux"
What else do I have to do to get Jython to see my classes?
Aside from setting it as a reference, you also have to:
1. make the java project a pydev project (right click project > pydev > set as pydev project)
2. Configure that project pythonpath to add the .class files: project properties > pydev - pythonpath > add the source folder(s) that contains your .class files (this would be the folder just one level before your 'com' namespace).
Cheers,
Fabio
I got around this by building the Java project into a jar and adding the jar to the global PYTHONPATH. Can a jar be added to an individual jython project?
That's also a solution (but if you're going to be developing that same project, it can be a bit troublesome, as you have to update your jar whenever you change your java code).
In the project properties: pydev > pythonpath, you can add a jar to just one project (see http://fabioz.com/pydev/manual_101_project_conf2.html )
Cheers,
Fabio
I changed to your first suggestion and it works great. Thanks.