Search code examples
javalinuxclasspathlinux-mintjdom-2

Error with Jdom 2.0.5 and java during my compilation


I try to compil with jdom, my directory look like that :

jdom-2.0.5.jar, ParseurXml.java, XMLEnt.xml

i've already try to export my classpath, but It still not woking at all.

My ParseurXML.java contain only tree import, and write that in my stderr :

ParseurXml.java:2: error: package org.jdom does not exist import org.jdom.; ^ ParseurXml.java:3: error: package org.jdom.input does not exist import org.jdom.input.; ^ ParseurXml.java:4: error: package org.jdom.output does not exist import org.jdom.output.*; ^ ParseurXml.java:12: error: package org.jdom does not exist static org.jdom.Document document;

I compile like that: javac -classpath jdom-2.0.5.jar ParseurXml.java


Solution

  • So long as you're in the same directory as these files when calling javac, its' nearly always a good idea to include the current directory in the classpath

    On linux you can use this

    javac -classpath .:./jdom-2.0.5.jar ParseurXml.java
    

    So the above specifies the current directory at the start of the classpath (i.e. the leading . character)

    Then the following : character is a separator

    Then the following ./jdom-2.0.5.jar says to look for your jdom jar file in the current directory.