JDOM: java.lang.NoClassDefFoundError: org/jdom/Content

B

Bernd Oninger

When I run the successfully compiled java source shown at the end I got a runtime error:

Exception in thread "main" java.lang.NoClassDefFoundError: org/jdom/Content

Where is the missing class ?

I copied the newest jdom.jar from newest JDOM release b10 to the folder

jdk\jre\lib\endorsed

Is this not enough ?

Bernd
 
G

GIMME

org.jdom.Content is in jdom.jar.

Note that this class does not exist in some previous versions of jdom.jar
(for example the version which comes with b8 which I just checked).

Personally, I wouldn't store jdom.jar in jdk\jre\lib\endorsed. Make
certain your CLASSPATH is pointing to a valid jdom.jar file.
 
R

Richard

org.jdom.Content is in jdom.jar.

Note that this class does not exist in some previous versions of jdom.jar
(for example the version which comes with b8 which I just checked).

Personally, I wouldn't store jdom.jar in jdk\jre\lib\endorsed. Make
certain your CLASSPATH is pointing to a valid jdom.jar file.

Hello!

I have the same problem as Bernd Oninger, I can compile but not run
the program.

Im trying to make this simple example to work...

---- example1.java ----
import org.jdom.*;

public class example1
{
public static void main(String[] args)
{
Element root = new Element("myRootElement");
Document doc = new Document(root);
root.setText("This is a root element");
System.out.println(doc);
}
}
-----------------------

To compile I use this:
javac example1.java -classpath "jdom.jar"

....it works great since i have the jdom.jar-file in the same directory
(I asume that you can have the jar-file anywhere you want, as long as
the path is correct).

But when I run the program I get this:
java example1 -classpath "jdom.jar"
Exception in thread "main" java.lang.NoClassDefFoundError:
org/jdom/Element
at example1.main(example1.java:7)

....why wont this work???

GIMME, when you are talking about the CLASSPATH do you mean the
enviroment variable (NOTE: Im using windows here, not linux)??? I have
tryed "set CLASSPATH ..." but its still the same problem.


THX in advance
/Richard
 
S

Sudsy

Richard wrote:
<snip>

You know, you really should read the javadocs. They demonstrate quite
clearly that the options have to appear BEFORE the class name on the
command line. Here's an console log from my Linux box showing the
results of changing the order:

$ java example1 -classpath $CLASSPATH:/u/jboss-3.2.2/lib/jdom.jar
Exception in thread "main" java.lang.NoClassDefFoundError: org/jdom/Element
at example1.main(example1.java:7)
$ java -classpath $CLASSPATH:/u/jboss-3.2.2/lib/jdom.jar example1
[Document: No DOCTYPE declaration, Root is [Element: <myRootElement/>]]
$
 
G

GIMME

To compile I use this:
...it works great since i have the jdom.jar-file in the same directory
(I asume that you can have the jar-file anywhere you want, as long as
the path is correct).

Good. Right.
But when I run the program I get this:
Exception in thread "main" java.lang.NoClassDefFoundError:
org/jdom/Element
at example1.main(example1.java:7)

...why wont this work???

You have to have the classpath stuff up front ...

java -classpath $CLASSPATH example1
GIMME, when you are talking about the CLASSPATH do you mean the
enviroment variable (NOTE: Im using windows here, not linux)???

Yes. Although the syntax of separaters differ, back slashes instead
of forward slashes, in each instance you want an environment variable.

I have
tryed "set CLASSPATH ..." but its still the same problem.


Try :

echo %CLASSPATH%


Relying on Window's environmental variables all the time can
lead to some undesirable behavior.

I use a dos batch script to set up my environmental variables
and then call cygwin. Here a sample script for you to study.
If you don't have cygwin installed delete or comment out the last
line.

@echo off

set PROOT=C:\Project\WEBELocal\Vignette\Portal
set JAVA_HOME=C:\Apps\jdk1.3.1_07

set JARS=C:\Project\WEBELocal\Vignette\Portal\portal\WEB-INF\lib
set CLASSES=C:\Project\WEBELocal\Vignette\Portal\portal\WEB-INF\classes

set CLASSPATH=.
set CLASSPATH=%CLASSPATH%;C:\bin
set CLASSPATH=%CLASSPATH%;%CLASSES%
set CLASSPATH=%CLASSPATH%;%JARS%\epicentric.jar
set CLASSPATH=%CLASSPATH%;%JARS%\bsf.jar
set CLASSPATH=%CLASSPATH%;%JARS%\bsfengines.jar
set CLASSPATH=%CLASSPATH%;%JARS%\collections.jar
set CLASSPATH=%CLASSPATH%;%JARS%\cos.jar

set ANT_HOME=%PROOT%\samples\cartool\jakarta-ant-1.5

C:\WINDOWS\system32\COMMAND.COM /E:4096 /c C:\cygwin\cygwin.bat
 

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,733
Messages
2,569,440
Members
44,830
Latest member
ZADIva7383

Latest Threads

Top