java import error, org.jdom

18,511

Solution 1

I opened the jar file at the link you gave using 7zip. It looks like you will need to use the import statements: (Note the addition of the '2') "import org.jdom2.Document;"

Solution 2

It depends from the library version!!

If you downloaded the version 1 you MUST write:

import org.jdom.*

If you downloaded the version 2 you MUST write:

import org.jdom2.*

Solution 3

You should import jdom-1.1.3 which is stable and work for me.

Share:
18,511
Naturia Rock
Author by

Naturia Rock

Updated on June 14, 2022

Comments

  • Naturia Rock
    Naturia Rock almost 2 years

    ive been trying to do an import in my java project but i keep getting the following error.

    The import org.jdom cannot be resolved
    

    i have created a lib folder under my project and have put the jar files from http://www.jdom.org/downloads/index.html

    into there. there were a total of 8 different jar files which i added. then i added them in my build path. those 8 files are now in my referenced libraries. however that error keeps coming up. ive tried refreshing and cleaning my project but no luck.

    am i supposed to do something different since its a org.jdom?

    my import statements are...

    import org.jdom.Document;
    import org.jdom.Element;
    import org.jdom.JDOMException;
    import org.jdom.input.SAXBuilder;
    import org.jdom.output.Format;
    import org.jdom.output.XMLOutputter;
    

    thank you

    • devang
      devang almost 12 years
      Could you list your exact import statement, piece of code for which the import fails.
    • Naturia Rock
      Naturia Rock almost 12 years
      i edited it with the exact import statements
    • devang
      devang almost 12 years
      Since you have added the necessary libraries in your build path, you can check whether these classes are present in any of those jars by expanding them within Eclipse. Did you check this?
    • akf
      akf almost 12 years
      go to the package explorer, select your project, r-click, select refresh
    • Peter
      Peter almost 12 years
      Looks like the path inside the jar file is org.jdom2.xxxx
  • Naturia Rock
    Naturia Rock almost 12 years
    may i ask how you figured out that? what gave it away that...you were supposed to add a '2'? thanks!
  • Peter
    Peter almost 12 years
    A jar file is just a 'special' zip file which contains a directory structure containing class files that mirrors the package names. Inside the file, the first directory was "org" which contained another directory called "jdom2" which contained a number of .class files that matched the ones you were trying to import".
  • Peter
    Peter almost 12 years
    Another way, if you're using eclipse as your IDE, would be to type "import org." and then wait for the drop down list to give you a list of the available package names. In this case it would have shown jdom2 as an option and you could then type "import org.jdom2." and see what was inside this package.
  • Naturia Rock
    Naturia Rock almost 12 years
    this is kinda stupid but i dont see the directories you listed. when i unzipped the package, i see a bunch of jar files and a folder called lib. and inside lib, is a bunch of other class files. thats it. could it be the way im unarchiving the zip?
  • Peter
    Peter almost 12 years
    Ah, I looked inside the jdom-2.0.2.jar. That's the jar file that you would have included in your project. The other jars are just supporting jars: java doc, source code, unit tests. The lib directory contains the jars that are needed by jdom to do what it needs to do and also need to be imported into your project.