ClassDefNotFound error with xpath.evaluate...

D

drakaan

Well, I managed to get stuck just before I actually see any results
from a foray into using xpath with java.

I have some code (fairly straightforward):

56: String expression = "/systems/system";
57: InputSource inputSource = new InputSource("/folder/" + fileName);
58: XPath xpath = XPathFactory.newInstance().newXPath();
59: NodeList nodes = (NodeList) xpath.evaluate(expression,
inputSource, XPathConstants.NODESET);

That throws the following errors when run within the Eclipse IDE,
regardless of which folder/filename or expression I throw at it:

Exception in thread "main" java.lang.NoClassDefFoundError:
gnu.xml.pipeline.DomConsumer
at gnu.xml.pipeline.DomConsumer$Handler.<init>(libgcj.so.7rh)
at gnu.xml.pipeline.DomConsumer.<init>(libgcj.so.7rh)
at gnu.xml.dom.Consumer.<init>(libgcj.so.7rh)
at gnu.xml.dom.JAXPFactory$JAXPBuilder.<init>(libgcj.so.7rh)
at gnu.xml.dom.JAXPFactory.newDocumentBuilder(libgcj.so.7rh)
at gnu.xml.xpath.Expr.evaluate(libgcj.so.7rh)
at gnu.xml.xpath.XPathImpl.evaluate(libgcj.so.7rh)
at updateParser.SysmonParser.parseXml(Parser.java:59)

I have the following imports:

import java.util.Date;
import javax.xml.xpath.*;
import org.xml.sax.*;
import java.io.File;
import java.io.IOException;
import org.w3c.dom.*;
import org.jrobin.core.*;

My xml looks like:

<?xml version="1.0"?>

<systems>

<system id="12345678" address="xx.xx.xx.xx" osclass="windows"
uptime="1D 2H 51M">
</system>
</systems>

I'm very new to java, but not to xml data manipulation. The java
examples that I found seemed pretty straightforward (although they
often failed to mention what imports are required). My first thought
is still that I'm missing a library reference or something (I'm on
Fedora Core 6, Eclipse 3.2.0, and my workspace default is the
java-1.4.2-gcj-1.4.2.0 JRE).

Any insight as to how I might narrow down the cause of that
classDefNotFound error? It's driving me absolutely nuts.

Help. Please.
 
J

Joshua Cranmer

Exception in thread "main" java.lang.NoClassDefFoundError:
gnu.xml.pipeline.DomConsumer
at gnu.xml.pipeline.DomConsumer$Handler.<init>(libgcj.so.7rh)
at gnu.xml.pipeline.DomConsumer.<init>(libgcj.so.7rh)
at gnu.xml.dom.Consumer.<init>(libgcj.so.7rh)
at gnu.xml.dom.JAXPFactory$JAXPBuilder.<init>(libgcj.so.7rh)
at gnu.xml.dom.JAXPFactory.newDocumentBuilder(libgcj.so.7rh)
at gnu.xml.xpath.Expr.evaluate(libgcj.so.7rh)
at gnu.xml.xpath.XPathImpl.evaluate(libgcj.so.7rh)
at updateParser.SysmonParser.parseXml(Parser.java:59)
A NoClassDefFoundError signifies that the VM cannot find the class file;
my recommendation would be to check the classpath.
 
B

Bozo Bits

A NoClassDefFoundError signifies that the VM cannot find the class file;
my recommendation would be to check the classpath.

Given that you are using GCJ, have you tried building and running
using a current Sun JDK? The NoClassDefFoundError in this context is
clearly a runtime error and so checking the classpath is probably the
first thing to do. If you had a bad import you should get a compile
time error instead.

bozo bits
 
D

drakaan

Given that you are using GCJ, have you tried building and running
using a current Sun JDK? The NoClassDefFoundError in this context is
clearly a runtime error and so checking the classpath is probably the
first thing to do. If you had a bad import you should get a compile
time error instead.

bozo bits


....okay...keeping in mind that I'm pretty new to Java, I have three
questions:

First, does "Sun JDK" mean the same thing as "Java SDK" (which is what
sun refers to on java.sun.com)?

Second, is javax.xml.* the sun equivalent of gnu.xml.* ?

Third, (and this may be more of a Linux question than a Java
question), since I haven't specified gnu.xml.xpath.* as an import, is
there some kind of translation going on behind the scenes to use gnu.*
in place of javax.* ?

Looking at the packages and classes in the gcj jre library in Eclipse,
I see both javax packages and gnu packages and classes (including the
"not found" one...and this is in my default workspace runtime
library).

I'm downloading java_ee_sdk-5_02-linux.bin as I write this. I'll try
making that my default library and cross my fingers.
 
D

drakaan

Given that you are using GCJ, have you tried building and running
using a current Sun JDK? The NoClassDefFoundError in this context is
clearly a runtime error and so checking the classpath is probably the
first thing to do. If you had a bad import you should get a compile
time error instead.

bozo bits


Okay...downloaded the 5.0.2 SDK and used that JRE in Eclipse, and the
classdefnotfound error went away. I guess I should find a GNU java
developer to ask about the original problem (it'd be nice for things
to work by default, right?) with the GNU JRE.

Thanks for the help...now I just have to find out where a
nullpointerexception is coming from...if I get stuck again, I'll make
sure to ask here. Thanks again.
 
O

Oliver Wong

...okay...keeping in mind that I'm pretty new to Java, I have three
questions:

First, does "Sun JDK" mean the same thing as "Java SDK" (which is what
sun refers to on java.sun.com)?

More or less, yes. "Sun JDK" is to put emphasis on the fact that
BozoBits was recommending you use Sun's implementation of the JDK in
particular, as opposed to GNU's implementation. The term "Java SDK" loses
this emphasis, as Sun's JDK and Gnu's JDK are both Java SDKs.
Second, is javax.xml.* the sun equivalent of gnu.xml.* ?

Maybe. And more like the other way around. Sun invented Java, so
they're more or less the defacto standard around which all other Java
implementations are compared. GNU didn't like the fact that Java wasn't
open source, so they tried to make an open source alternative. Whether or
not they did a "good" job (in the sense that you can replace all
occurrences of gnu.xml.* with javax.xml.* and not uncover any bugs)
depends entirely on GNU.
Third, (and this may be more of a Linux question than a Java
question), since I haven't specified gnu.xml.xpath.* as an import, is
there some kind of translation going on behind the scenes to use gnu.*
in place of javax.* ?

I don't know. I'm not familiar with the GNU class path.
Looking at the packages and classes in the gcj jre library in Eclipse,
I see both javax packages and gnu packages and classes (including the
"not found" one...and this is in my default workspace runtime
library).

I'm downloading java_ee_sdk-5_02-linux.bin as I write this. I'll try
making that my default library and cross my fingers.

If you're not sure whether or not you need EE, you probably don't need
EE (EE stands for Enterprise Edition). It might make your life simpler to
get SE (Standard Edition) instead. Certainly, you don't need EE to do XML
manipulation. You'll need EE if you're working with Tomcat, JSP, servlets,
or other web-app/web-service type stuff.

- Oliver
 
O

Oliver Wong

D

drakaan

Usually when you get an exception, you'll also get a stack trace which
should show the exact line number within each method in the call stack
where the exception was generated.

There's an example stack trace, and a guide on how to interpret it, athttp://moinmoin.riters.com/JINX/index.cgi/Suggestions_20for_20Asking_...

orhttp://tinyurl.com/3btw72

- Oliver


Right you are about "usually". Being too diligent in exception
handling leaves you with less information than that.

I had a 'catch (Exception ex)' as the last in a series of catch
statements, which catches the nullpointerexception, and I was just
doing 'System.out.println(ex)', which strips the useful bits like line
number, etc, so all I got was the exception type with no context.

I'm back to doing actual programming thanks to you guys. Much
appreciated.
 
O

Oliver Wong

Right you are about "usually". Being too diligent in exception
handling leaves you with less information than that.

I had a 'catch (Exception ex)' as the last in a series of catch
statements, which catches the nullpointerexception, and I was just
doing 'System.out.println(ex)', which strips the useful bits like line
number, etc, so all I got was the exception type with no context.

The Exception class has a method printStackTrace(), so you can replace
your "System.out.println(ex);" line with "ex.printStackTrace();" to get
more useful information. Unless you're writing server software which has
to be up "no matter what", I usually recommend just letting the exception
propagate all the way up, as the stack trace will automatically be printed
out once it reaches all the way to the top of the callstack without being
handled.

It also gives the calling method more flexibility in trying to catch
and deal with the exceptions themselves.

- Oliver
 
D

drakaan

The Exception class has a method printStackTrace(), so you can replace
your "System.out.println(ex);" line with "ex.printStackTrace();" to get
more useful information. Unless you're writing server software which has
to be up "no matter what", I usually recommend just letting the exception
propagate all the way up, as the stack trace will automatically be printed
out once it reaches all the way to the top of the callstack without being
handled.

It also gives the calling method more flexibility in trying to catch
and deal with the exceptions themselves.

- Oliver


I am, in fact, writing server software (a *nix daemon that processes
files in a directory as they get placed there by another daemon), but
I hadn't encountered printStackTrace yet. I'll definitely make use of
that instead of the println lines I'm currently catching exceptions
with. It'll save me adding debug print statements all over the place
when I'm trying to figure out which line in a block is throwing an
exception :).

I really appreciate the pointers.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,994
Messages
2,570,223
Members
46,812
Latest member
GracielaWa

Latest Threads

Top