Java - Jars, XML and Xerces


I'm trying to execute an application which calls xerces.jar.
Everything compiles and works as expected in my IDE (Visual Age Java).
I have exported my classes as jars.

When I try to execute the command:-

     java -jar -cp classpath myjar.jar classname

I receive the following error:-

Exception in thread "main" java.lang.NoClassDefFoundError: org/xml/sax/helpers/DefaultHandler
        at Method)
        at Source)
        at java.lang.ClassLoader.loadClass(Unknown Source)
        at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
        at java.lang.ClassLoader.loadClass(Unknown Source)

I have checked that the xerces directory and jar file are in the classpath but can't get this to work.
I have tried replacing xerces.jar with another version of xerces...same problem.
As an FYI, am working on an HP-UX with Java 2 v1.3

Is this a simple classpath problem, an issue with my jar file or a xerces problem ?

Any help or pointers, greatly appreciated.

Who is Participating?
objectsConnect With a Mentor Commented:
When you use the -jar option the jar file is the source of all classes, and all other classpath settings are ignored.
ie. your classpath is not used.

You need to specify your external jars in your jar's manifest (use the Class-Path attribute) instead.
 I think it is a simple classpath problem.

  I do not know if this is going to help but try putting your Xerces.jar file under the /lib/ext folder. If this does not work try to unpack the Xerces.jar into your class path.

  Hope it helps.
try this:
java -jar -classpath myjar.jar;%CLASSPATH% classname

Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

contextAuthor Commented:
I also thought that this was a classpath problem.
However, I have tried playing with the classpath to no avail.

One thing to note, when I unpack my jars, it works.
Guess this is telling me that this isn't a problem with xerces.

I'm assuming that when using multiple jars, as long as the complete path of the jar (incl. jar name) is in the classpath, there shouldn't be any problems, right?
ops - sorry:
try this:
java -jar -cp $CLASSPATH myjar.jar classname

>I'm assuming that when using multiple jars, as long as the complete path of the jar (incl. jar name)
>is in the classpath, there shouldn't be any problems, right?

  Yes this is right. But it's strange that it does not work while the classes are in the jar. The only thing I can think of is that there is a conflict with the class loaders. I am running out of ideas here. Try to use the . in your classpath, i.e. java -jar -classpath %CLASSPATH%;.

  And, did you try putting your jar file under the /lib/ext folder?
ADMINISTRATION WILL BE CONTACTING YOU SHORTLY.  Moderators Computer101 or Netminder will return to finalize these if still open in seven days.  Please post closing recommendations before that time.

Question(s) below appears to have been abandoned. Your options are:
1. Accept a Comment As Answer (use the button next to the Expert's name).
2. Close the question if the information was not useful to you, but may help others. You must tell the participants why you wish to do this, and allow for Expert response.  This choice will include a refund to you, and will move this question to our PAQ (Previously Asked Question) database.  If you found information outside this question thread, please add it.
3. Ask Community Support to help split points between participating experts, or just comment here with details and we'll respond with the process.
4. Delete the question (if it has no potential value for others).
   --> Post comments for expert of your intention to delete and why
   --> YOU CANNOT DELETE A QUESTION with comments; special handling by a Moderator is required.

For special handling needs, please post a zero point question in the link below and include the URL (question QID/link) that it regards with details.
Please click this link for Help Desk, Guidelines/Member Agreement and the Question/Answer process.

Click you Member Profile to view your question history and keep them updated as the collaboration effort continues, to maintain your open and locked questions.  If you are a  KnowledgePro user, use the Power Search option to find them.  Anytime you have questions which are LOCKED with a Proposed Answer which does not serve your needs, please reject it and add comments as to why.  In addition, when you do grade the question, if the grade is less than an A, please add a comment as to why.  This helps all involved, as well as future persons who may access this item for help.

To view your open questions, please click the following link(s) and keep them all current with updates.

------------>  EXPERTS:  Please leave your closing recommendations if this item remains inactive another seven (7) days.  If you are interested in the cleanup effort, please click this link 
POINTS FOR EXPERTS awaiting comments are listed here ->

Moderators will finalize this question if in @7 days you have not responded.  They will either move this to the PAQ (Previously Asked Questions) at zero points, delete it or awarding expert(s) when recommendations are made, or an independent determination can be made.  Expert input is always appreciated to determine the fair outcome.
Thank you everyone.
Moderator @ Experts Exchange
Zero response, finalized.
Moondancer - EE Moderator
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.