Question

I run into a weird (for me at least) case. When i'm running my project from Eclipse everything is fine. But when I export the project to a jar file it fails with InvocationTargetException. I'm using other external libs and everything runs fine (program runtime is about 5 min) and it creates a docx at the end.

try {
  WordprocessingMLPackage wordMLPackage;
  wordMLPackage = WordprocessingMLPackage.createPackage(); // this is Line 1320
  // more lines here
} catch (Exception e) {
  e.printStackTrace();
}

I'm running in cmd and it prints:

Exception in thread "main" java.lang.reflect.InvocationTargetException

Caused by: java.lang.ExceptionInInitializerError

at com.lesswire.wita.Wita.CreateReport(Wita.java:1320)

How could i make it work in my jar ?

Thanks, roncsak

Était-ce utile?

La solution 2

After all, the main reason of this bug was related Log4jConfigurator as @alexei-kaigorodov guessed. But! log4j was configured but not well for docx4j! I've searched logj.xml files on the net, and tried some.

Here is how its done:

In eclipse, make sure log4j.xml is in a class folder (often referenced this as CLASS PATH). If you don't want to put there, you can create and set one. Open Java Build Path in Eclipse and navigate to the Libraries tab. Then choose "Add Class Folder" and select the newly created folder.

For some reason when I do a Clean Build the log4j.xml is overwritten. Make sure your logj4.xml is right after Clean.

Autres conseils

I think this is a classpath issue for your application. Check the Eclipse classpath (in your Project properties) and compare it with the classpath you have set for when you run your application outside of Eclipse. The most likely culprit is the third party library that contains the com.lesswire.wita package or one of it's dependencies.

The other possibility is the application is using library that depends on newer JRE version, but your installed JRE (java.exe in your OS path enviroment) is older version.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top