Solved

CLASSPATH Issues

Posted on 2003-10-23
8
322 Views
Last Modified: 2013-11-23
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
0
Comment
Question by:shoeman22
  • 5
  • 3
8 Comments
 
LVL 3

Expert Comment

by:savalou
ID: 9608570
Should probably be:

import javax.xml.parsers.*;
import javax.xml.sax.*;
0
 
LVL 3

Accepted Solution

by:
savalou earned 50 total points
ID: 9608583
Sorry,

import org.xml.sax.*;
0
 

Author Comment

by:shoeman22
ID: 9609382
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?
0
 
LVL 3

Expert Comment

by:savalou
ID: 9610026
ummm...is Attribute a dom4j class?  I'm guessing then you need an

import org.dom4j.Attribute;

0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

Author Comment

by:shoeman22
ID: 9610209
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
0
 
LVL 3

Expert Comment

by:savalou
ID: 9610358
>> 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!
0
 

Author Comment

by:shoeman22
ID: 9610688
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
0
 
LVL 3

Expert Comment

by:savalou
ID: 9611118
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!
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues unde…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.

912 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

26 Experts available now in Live!

Get 1:1 Help Now