This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Java in General and the fly likes import in Windows environment Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "import in Windows environment" Watch "import in Windows environment" New topic
Author

import in Windows environment

Les Hayden
Greenhorn

Joined: Jun 19, 2002
Posts: 28
I'm trying to play with the Java XML APIs and I'm having trouble getting the import to work.
I've entered the following:
import org.w3c.dom.*;
public class XMLTest {
private Document document;

/** Creates a new instance of ReplaceText */
public XMLTest() {
}
public static void main(String[] args) {
}

}
and get the following error:
ReplaceText.java [1:1] package org.w3c.dom does not exist
import org.w3c.dom.*;
^
I have placed a reference to the location of the dom.jar file on my class path which according to the install instructions is all I have to do.
I'm obviously missing something basic here
Les


Les Hayden
Michael Morris
Ranch Hand

Joined: Jan 30, 2002
Posts: 3451
Hi Les,
Why don't you show us how your CLASSPATH is set and maybe we can determine the problem. You can also put the jar file in the extension directory of the JRE. That path is <SDK_Directory>\jre\lib\ext\ where <SDK_Directory> is the directory where the Java SDK is installed. For example on my machine it is C:\j2sdk1.4.1\jre\lib\ext\.
Michael Morris


Any intelligent fool can make things bigger, more complex, and more violent. It takes a touch of genius - and a lot of courage - to move in the opposite direction. - Ernst F. Schumacher
Dirk Schreckmann
Sheriff

Joined: Dec 10, 2001
Posts: 7023
I think that directory is only supposed to be used by official Java extensions from Sun. Figuring out how the whole classpath thing works isn't a huge ordeal, but once you figure it out life is easy.


[How To Ask Good Questions] [JavaRanch FAQ Wiki] [JavaRanch Radio]
Dirk Schreckmann
Sheriff

Joined: Dec 10, 2001
Posts: 7023
Also, how are you compiling? From the command line with javac or through an IDE?
Les Hayden
Greenhorn

Joined: Jun 19, 2002
Posts: 28
Thanks for looking at this.
The path on my computer is:

(edited using the little paper and pen icon - you too can do this to your own posts)
[ March 21, 2003: Message edited by: Cindy Glass ]
Les Hayden
Greenhorn

Joined: Jun 19, 2002
Posts: 28
And that is the CLASSPATH, not the PATH.
Thanks again.
Dirk Schreckmann
Sheriff

Joined: Dec 10, 2001
Posts: 7023
Les,
Please edit your post to break apart that big long line in the code tag.
Dirk Schreckmann
Sheriff

Joined: Dec 10, 2001
Posts: 7023
Originally posted by Dirk Schreckmann:
Also, how are you compiling? From the command line with javac or through an IDE?
Les Hayden
Greenhorn

Joined: Jun 19, 2002
Posts: 28
Sorry,
I put the relavent files on separate lines.
.;C:\SQLLIB\java\db2java.zip;C:\SQLLIB\java\runtime.zip;C:\SQLLIB\bin;
C:\jaxp\dom.jar;
c:\jaxp\jaxp-api.jar;
c:\jaxp\sax.jar;
c:\jaxp\xalan.jar;
c:\jaxp\xercesImpl.jar;
c:\jaxp\xsltc.jar;
C:\Program Files\Altova\xmlspy\XMLSpyInterface.jar
I'm using Forte(Sun One Studio).
Thanks again for your time.
Dirk Schreckmann
Sheriff

Joined: Dec 10, 2001
Posts: 7023
I'm not familiar with Forte, it might do something obnoxious like ignore your system CLASSPATH setting and just use its own. What happens when you try to compile the same code from the command line with javac? If it works, then it's a Forte issue and I'd recommend moseying on over to the IDEs forum.
And of course, I'd double check that the dom.jar file is where the CLASSPATH says it is and that it does indeed contain the org.w3c.dom package.
So, how do things turn out?
Les Hayden
Greenhorn

Joined: Jun 19, 2002
Posts: 28
The odd thuding sound you hear is my head being drummed against the wall. Indeed, javac happily compiles the program.
I should have thought of that myself.
I know better, really I do :roll:
Under the subject of RTFD:
The Class Path property editor sets the path to the sources that the IDE uses. By default the IDE uses its internal class path, which includes all mounted filesystems and various directories in the IDE's installation and user directories . The IDE ignores your CLASSPATH environment variable. You can set the specific class path that the IDE uses with the Class Path property editor. This setting overrides the IDE's internal class path.
[ March 24, 2003: Message edited by: Les Hayden ]
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: import in Windows environment
 
Similar Threads
XPath Problem
XPath Problem
Appending data to existing XML file
DOM Parsing - Please help
Xinclude, read 2 xml files