3

This is my first java software... The software works well on my dev machine, but I get that exception on the other (non-dev) machine (both on Windows 10) : java.lang.NoClassDefFoundError: org/jdom2/JDOMException

I read that there is something related with the JDOM versions, and that the key should be something with the xerces.jar order in the classpath (www.jdom.org)... I tried different approaches, without any result.

I work with NetBeans, and it is not clear for me how to include JDOM. What I did :

  • Under Tools, Libraries, I created a JDOM library, and included in it jdom-2.0.6.jar, and also added then xercesImpl.jar, and also xml-apis.jar, and checked that xerces comes first: JDOM library creation
  • Then, I use Add Library... by right-clicking on the Library folder of my project: Add Library

The software works well on my development PC... but then I this exception when creating my XML object, on another PC (which has no development environment) :

Exception in thread "AWT-EventQueue-0" java.lang.NoClassDefFoundError: org/jdom2/JDOMException

What am I doing wrong ?

baptiste
  • 1,107
  • 2
  • 15
  • 30
Cruxial
  • 41
  • 4
  • Most likely you didn't provide the jdom jar to the other PC, rather you just provided your runnable jar, the one that needs jdom to work. Look up Maven as the answer advises, but also look up how it can build "far jars" that are executable jars that contain all the dependencies they need, without having to hand out tons of files to your users. – kumesana Jan 30 '20 at 14:40
  • NoClassDefFoundErr means that the class is not on your classpath (on the machine where you are executing your program). Do make sure you install JDOM2 rather than the original JDOM. – Michael Kay Jan 30 '20 at 16:39

1 Answers1

3

You said you have no development environment on the other PC, so if you don't have the JARs available then running the program won't work because you don't have the dependencies installed.

I would recommend looking into Maven. It's a package manager(among other things), and can help you with this sort of thing. Here is a link to Maven's main page. The library you're looking for is here. Read the tutorials for how to set up a Maven project and add dependencies to the pom.xml file.

djharten
  • 374
  • 1
  • 12
  • 2
    It's also worth mentioning that just having the jars present isn't enough; it would need to either be included in the classpath environment variable, explicitly set using the `-cp` argument to the java executable, or added as a reference in the jar manifest – Gus Jan 30 '20 at 14:47