Win a copy of Rust Web Development this week in the Other Languages forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
  • Tim Cooke
  • Campbell Ritchie
  • Ron McLeod
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Junilu Lacar
  • Rob Spoor
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Tim Moores
  • Jesse Silverman
  • Stephan van Hulst
  • Carey Brown
  • Al Hobbs
  • Piet Souris
  • Frits Walraven

Creating an executable jar for a complex Java project

Ranch Hand
Posts: 76
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

I am trying to create an executable jar out of a Java project which uses the jExcel API (jxl.jar). The project has been created using Eclipse 3.1 M7. I used the "Export as Jar file" tool in Eclipse to create the said jar file.
But, when i try to run the jar, it says:
"Fatal exception occured. Program will exit."
It is not able to find the "BiffException" class, says the exception trace.

What could be the reason? The program runs perfectly fine from within Eclipse.

In fact, i am facing this problem only when i refer any external jars in my project. If the project just uses the standard Java api, the executable jar runs fine.

Please help.

Ranch Hand
Posts: 624
IntelliJ IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Most likely the problem is that you have the necessary libraries/APIs (i.e. the external jars) defined in Eclipse, but you are not referencing them when running the application externally. Thus when you run from Eclipse that library (and its classes) is included in your classpath, allowing the JVM to find all the required classes. However, when you are running externally, these additional external jars are not in your classpath (since Eclipse is not doing it for you). This is a potential danger when you test using an IDE; you have to figure out classpath issues when getting ready to deploy.

So you either need to:
  • Define all those external jars in your classpath when you run your application (via the -classpath option)
  • As an alternative to the above, you can define the additional jars in your jar's manifest and simply have the additional jars in the same directory. See for more info
  • Create a Super Jar file by un-jar-ing all the external libraries, and then jar everything (including your code) into a single jar. (Be sure to read any license agreements for the external libraries to verify this is ok). You can use the Ant jar task to do this for you. You'll want to leave the keepcompression option to its default value of false. There are some dangers to this including the loss of code signatures that are located in /META-INF/MANIFEST.MF files, the danger of overwriting files common to multiple libraries (such as README, license.txt, and to name a few), loss of digital signature if the third-party jar is signed, and if the third-party JAR contains JARs itself.
  • Package the external JARs in with your JAR (again you can use the Ant jar task, but set keepcompression to true) and then to load classes in JAR files within your JAR file into the class path, you must write custom code to load those classes.
  • Vote for this ( request for enhancement to Java so that the above option will happen automatically without the need for custom classloader code. Granted this would be a rather long term solution and there is debate as to whether this is a good idea since some developers argue that "a jar is suppose to be 'an atomic' entity which can be sealed and distributed." I haven't thought about it enough myself to form an opinion on the issue.
  • Check out the SourceForge One-JAR Project for an additional solution:

  • [ March 17, 2006: Message edited by: Mark Vedder ]
    You showed up just in time for the waffles! And this tiny ad:
    Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
      Bookmark Topic Watch Topic
    • New Topic