importing a Java class

  • Graham Seed

    Graham Seed - 2011-06-09


    I'm working my way thro the Jython book at:

    and in Listing 2-27 it states:

    # Import and use a Java ArrayList
    >>> import java.util.ArrayList as ArrayList

    This works in the command-line window but does not work in Eclipse and complains with "Unresolved import".

    I'm confused by this as I'm using the Jython interpreter and assumed it has access to the Java api, as illustrated by how the command-line works.



  • Graham Seed

    Graham Seed - 2011-06-10

    It appears this is a peculiar feature/bug of PyDev and discussed elsewhere:

    The following import:

    import java.util.ArrayList as ArrayList

    raises the error "Unresolved import", flagged in the left hand margin

    However, if the code is run it actually works - which is very confusing as the IDE is telling you there are errors and yet the code will run. This does not instill me with confidence with respect to future error messages.

    Adding #@UnresolvedImport at the end of the import statement:

    import java.util.ArrayList as ArrayList #@UnresolvedImport

    stops the left-hand-margin error message.

    Furthermore, I notice that there is no field/method popup listing in the editor when adding defining an object of a Java class.

  • Fabio Zadrozny

    Fabio Zadrozny - 2011-06-10

    Actually, probably the real case is that the Java rt.jar is not added to your Jython interpreter configuration… this should be auto-detected by PyDev, but maybe there was a problem there in that step - can you see if 'rt.jar' is in the System libs?

    See: for an example on how it should look like…



  • Graham Seed

    Graham Seed - 2011-06-10


    Thanks for your reply.

    I have all of the jars listed under System libs shown in your screenshot except:

    QTJava, sunmscapi and sunpkcs11

    So, yes the rt.jar is included.

    PS. I am using Jython2.5.2


  • Aaron

    Aaron - 2011-07-26

    I'm having the same problem. I can run my jython scripts fine, but the eclipse code analyzer can't seem to resolve any of the Java imports.  I looks like my PYTHONPATH has all the Java .jar files . I could just suppress the errors, although I would like to be able to view Java docs like I can when I using eclipse for Java.

    Anyone have any ideas of what I can check next.



Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:

No, thanks