Reputation: 11
I am trying to read and write modifications to an XML file. After much research I selected the JDOM approach for this activity. I'm not doing big files and I just need something quick and simple. I downloaded the JDOM project files from jdom.org/downloads/docs.html. I also downloaded some exmple files that show the read write code using JDOM. Piece of cake Right?
Wrong. I have screwed around for several weeks trying to get my Java JDOM project to work. Using Eclipse on Windows 7 PC. I can not get the import statements to actually import the required JDOM items.
I have my project files in S:\Java\procXML folder. The source files are in the S:\Java\procXML\src\procXML folder.
The JDOM files in my S:\Java\JDOM folder. The JDOM java source files are in the S:\Java\JDOM\core\src\java\org\jdom2 folder.
I have the CLASSPATH set to S:\Java\JDOM\core\src\java.
I get an error message from Eclipse saying the org.jdom2 imports cannot be resolved.
The import section of the procXMLfile is as follows:
package procXML;
import java.io.File;
import java.io.IOException;
import java.util.List;
import org.jdom2.Document;
import org.jdom2.Element;
import org.jdom2.JDOMException;
import org.jdom2.input.SAXBuilder;
public class procXMLfile {
public static void main(String[] args) {
// TODO Auto-generated method stub
SAXBuilder builder = new SAXBuilder();
File xmlFile = new File("c:\\file.xml");
This stuff should be simple. The reason I'm using java is because I need to write some programs for MAC and Android and Java can be compiled for all of those platforms. I'm about ready to get rid of java and go with so other language, so I'm hoping someone can tell me what is wrong.
Upvotes: 1
Views: 2625
Reputation: 1994
You are adding a source folder in your CLASSPATH
.
Java classpath doesn't know how to interpret your source project.
You could compile your code through javac or via Eclipse to get a JAR file.
But if you just want to use JDOM in your project (which seems to be the case here), the simplest way is to add already packaged jar to your CLASSPATH
:
S:\Java\procXML\lib
S:\Java\procXML\lib\jdom-2.0.6.jar
,S:\Java\procXML\lib\lib\jaxen-1.1.6.jar
, S:\Java\procXML\lib\lib\xercesImpl.jar
, S:\Java\procXML\lib\lib\xml-apis.jar
, S:\Java\procXML\lib\lib\xalan\serializer-2.7.2.jar
, S:\Java\procXML\lib\lib\xalan\xalan-2.7.2.jar
Upvotes: 1