Menu

References to Java projects in Jython?

2009-04-13
2013-03-15
  • James Garrison

    James Garrison - 2009-04-13

    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?

     
    • Fabio Zadrozny

      Fabio Zadrozny - 2009-04-13

      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

       
    • James Garrison

      James Garrison - 2009-04-13

      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?

       
      • Fabio Zadrozny

        Fabio Zadrozny - 2009-04-13

        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

         
    • James Garrison

      James Garrison - 2009-04-14

      I changed to your first suggestion and it works great.  Thanks.