2

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

Community
  • 1
  • 1
roncsak
  • 618
  • 1
  • 8
  • 21
  • 1
    there must be one more "Caused by:" log message which tells the real problem. – Alexei Kaigorodov Sep 21 '12 at 08:45
  • Yes, there is. StackOverflow dont let me paste all that for some reason. There is a ExceptionInInitializerError (for org.docx4j.openpackaging.parts) and a NullPointerException (for org.docx4j.utils.Log4jConfigurator). It my be the last one. I donno. – roncsak Sep 21 '12 at 09:07
  • 1
    So the error is in Log4jConfigurator - you have to configure it properly. – Alexei Kaigorodov Sep 21 '12 at 09:50
  • It is configured properly when running from eclipse, it wont work when executing the jar. – roncsak Sep 21 '12 at 11:55

3 Answers3

0

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.

Luhar
  • 1,859
  • 2
  • 16
  • 23
  • Dear Luhar, thanks the response! `com.lesswire.wita` is my package and it contains the lines above. I think if it would a classpath problem that it could not use other external libs as well. However, i checked again in Project Properties -> Java Build Path -> Libraries and its fine. – roncsak Sep 21 '12 at 09:02
  • Ok, with reference to the other comments above, can you check if the log4j jar is on your class path when you run the application outside of Eclipse. – Luhar Sep 21 '12 at 14:09
  • Hi, I am facing same issue, I have updated manifest file and classpath, but it didnt work. Can you help?? – Dheeraj Kumar Aug 09 '16 at 08:03
0

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.

roncsak
  • 618
  • 1
  • 8
  • 21
  • Hi, I am facing same issue. getting InvocationTargetError while running my jar from application. I am new to Eclipse and I can't find log4j.xml file anywhere. http://stackoverflow.com/questions/38829942/invocationtargetexception-at-classloaders-callstaticfunction-java-eclipse. It would be very kind of you to look at it. Thanks – Dheeraj Kumar Aug 08 '16 at 13:19
0

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.

null
  • 8,669
  • 16
  • 68
  • 98