Link to home
Start Free TrialLog in
Avatar of shoeman22
shoeman22

asked on

CLASSPATH Issues

Hello
I'm fairly new to Java, and as a result I'm having major problems getting my packages to be recognized when I compile the programs.

I'm trying to install a sax parser (I downloaded it from a link from the http://www.saxproject.org website)

The file is sax2r2.jar
and is located at C:\j2sdk1.4.2_02\sax2r2.jar

When I installed xerces, it said to do a jar -xf <file> to install it, so I did the same with this sax file
c:\j2sdk1.4.2_02> jar -xf sax2r2.jar

Which creates the following directory:
C:\j2sdk1.4.2_02\sax2.0.1\

Which in turn has sax.jar
C:\j2sdk1.4.2_02\sax2.0.1\sax.jar

and to subfolders apidoc and src

within C:\j2sdk1.4.2_02\sax2.0.1\src\ there is a subfolder org
C:\j2sdk1.4.2_02\sax2.0.1\src\org\xml\sax

Here is my CLASSPATH variable specified in the User section of the Environment Variables section of the System configuration option in Windows XP Professional (Up to date with all patches/service packs if that matters).

Here is my CLASSPATH variable
.;c:\j2sdk1.4.2_02\dom4j-1.4\dom4j.jar;C:\j2sdk1.4.2_02\xerces-2_5_0\xml-apis.jar;C:\j2sdk1.4.2_02\xerces-2_5_0\xercesImpl.jar;C:\j2sdk1.4.2_02\xerces-2_5_0\xercesSamples.jar;C:\j2sdk1.4.2_02\sax2.0.1\sax.jar;C:\j2sdk1.4.2_02\sax2.0.1\src\

Here is my PATH variable
C:\jwsdp-1.2\jwsdp-shared\bin;C:\Program Files\Microsoft Visual Studio\Common\Tools\WinNT;C:\Program Files\Microsoft Visual Studio\Common\MSDev98\Bin;C:\Program Files\Microsoft Visual Studio\Common\Tools;C:\Program Files\Microsoft Visual Studio\VC98\bin;C:\j2sdk1.4.2_02\bin;


when I'm attempting to javac my program, c:\VectorProject\Parse.java:
--------------------------------------------------------------------------------------------------------------------------------------------
/*
 * Parse.java
 *
 * Created on October 20, 2003, 1:04 PM
 */

/**
 *
 * @author  Shoeman22
 */
import java.net.URL;
import java.util.*;
//import org.w3c.dom.Document;
import javax.naming.*;
import javax.xml.parsers;
import org.xml.*;
import java.io.*;

import org.dom4j.Document;
import org.dom4j.DocumentException;
import org.dom4j.io.SAXReader;

public class Parse {
    String url;
    Vector myVector;
    Document document;
    /** Creates a new instance of Parse */
    public Parse(String u) {
        url = u;
        myVector = new Vector();
        document = this.returnXML();
    }
   
    private Document returnXML() throws DocumentException {
        SAXReader reader = new SAXReader();
        Document document = reader.read(url);
        return document;
    }
   
    public void process() {
        List list = document.selectNodes( "//svg/line" );

        for (Iterator iter = list.iterator(); iter.hasNext(); ) {
            Attribute attribute = (Attribute) iter.next();
            String url = attribute.getValue();
        }

    }
}
-------------------------------------------------------------------------------------------------------------
when I run, from the command prompt, c:\VectorProject > javac Parse.java
I get the following errors:
-------------------------------------------------------------------------------------------------------------
Parse.java:15 package javax.xml does not exist
import javax.xml.parsers;
                        ^
Parse.java:16: package org.xml does not exist
import org.xml.sax;
                     ^
Parse.java:44: cannot resolve symbol
symbol : class Attribute
location: class Parse
                  Attribute attribute = <Attribute> iter.next();
                  ^

Parse.java:44: cannot resolve symbol
symbol : class Attribute
location: class Parse
                    Attribute attribute = <Attribute> iter.next();
                    ^

4 errors
---------------------------------------------------------------------
I assume this is a real easy fix, but I've been tearing my hair out trying to get this to work for the past couple of days, so any assistance would be greatly appreciated.

If you could just specify what exactly I should have for my CLASSPATH and PATH variables I'd really appreciate it.  I did do a search here prior to posting this and saw a thread stating the the CLASSPATH is basically a root directory for your import statements to append to...hence why I assumed my CLASSPATH entry: C:\j2sdk1.4.2_02\sax2.0.1\sax.jar;C:\j2sdk1.4.2_02\sax2.0.1\src\ would work correctly.

Thanks for the help,
Shoeman22
Avatar of savalou
savalou

Should probably be:

import javax.xml.parsers.*;
import javax.xml.sax.*;
ASKER CERTIFIED SOLUTION
Avatar of savalou
savalou

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of shoeman22

ASKER

savalou
Thank you, that cleared up the first 2 errors involving the importing, but I'm still getting the bottom 2 errors resulting from the Attribute class not being found...

What else do I need to import/install in order to eliminate the Attribute symbol not resolved error?
ummm...is Attribute a dom4j class?  I'm guessing then you need an

import org.dom4j.Attribute;

I did this and it worked.

so I changed my import list to:
import java.net.URL;
import java.util.*;
//import org.w3c.dom.Document;
//import javax.naming.*;
//import javax.xml.parsers.*;
//import org.xml.sax.*;
import java.io.*;
//import org.dom4j.Document;
//import org.dom4j.DocumentException;
//import org.dom4j.io.SAXReader;
import org.dom4j.io.*;
import org.dom4j.*;

Thanks for the help...one other thing...when I compiled the program, it gave me 26 warnings regarding deprecation relating to dom4j and sax, but it still compiled...is that a something to be concerned about?

Thanks
>> when I compiled the program, it gave me 26 warnings regarding deprecation relating to dom4j and sax, but it still compiled...is that a something to be concerned about?

Not for the moment, if everything works...some deprecated Java SDK methods throw an IllegalArgumentException or something if try to use them (java.util.Date does/did that a lot).  You should probably look at the javadoc of the deprecated methods to find out why they are deprecated and what to do about it.

But, nah, live dangerously!
Good to know,
Thank you very much for your help savalou!
I already accepted your answer, but while I've got your attention...

Do you know how to make Netbeans recognize my imports as valid packages?

Also, I just went to java.sun.com and found NetBeans...are there better programs for development, or is Netbeans the preferred?

Thanks again,
Shoeman22
Well, you've got my attention as long as this thing keeps e-mailing me...

Personally, I use NetBeans myself and I like it.  I've also had colleagues tell me Eclipse is good, I've never tried it much.  These two are free, so what's not to like?  

I don't know what you mean by "make Netbeans recognize my imports as valid packages".  If you mean that it complains about
import org.xml.sax.*;
when you try to compile your code, that's because you have to mount sax.jar in the FileSystem (right-click on filesystem, click on mount, ...).  

Alright?  Any more questions, buddy, and you'll have to pay me mucho dinero!