Java application runs in eclipse but not when exported to a jar file
posted 3 years ago
I have never had this issue before and I was wondering if anyone else has had the same issue. I have a small java application that uses the JExcel API http://jexcelapi.sourceforge.net/ to automate some Excel Sheet Reports. The application works fine when run from the Eclipse IDE using the "Run as Java Application" selection from the "File" menu, but when I export it to a Runnable Jar file the application is not working. The application will run, but when I select the file to convert it doesn't create the new file.
Has anyone had this same issue with an application running in Eclipse but not when exported to a jar, and if so how did you overcome it?
The first thing to do is figure out why it fails. There will be an error message somewhere. Try running the application from the command line to see if the error message gets printed out there. That should help you figure out why the application fails.
You can make all kinds of guesses as to why it might fail. The first guess would be that there is a dependent JAR file which Eclipse adds to the classpath when it runs that you did not add to the classpath for the application - or the dependent JAR is in the wrong location relative to where your application is located. This is the most likely reason for a failure, but there could be others.
Hopefully you can catch the exception to figure out what is going wrong - identify which JAR file you are missing, and can access your application's manifest to figure out why it isn't in the classpath.