Pulkit
Pulkit

Reputation: 4094

getting runtime exception while running a jar

I created a jar file which contains a main class and its dependent jar. I wrote my own manifest so that I can also include the dependencies. The problem comes when I try to run the jar file; it gives me the following:

Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/poi/ss/usermodel/Workbook

here is the folder structure

ExcelCopy.jar
|
|-com/utility/ExcelFormat.java
|
|-lib/poi-3.9.jar
|
|-META-INF/Manifest.mf

Manifest.mf content

Manifest-Version: 1.0
Class-Path: lib/poi-3.9jar
Created-By: 1.7.0_25 (Oracle Corporation)
Main-Class: com.utility.ExcelFormat

Upvotes: 0

Views: 688

Answers (2)

Pulkit
Pulkit

Reputation: 4094

Thanx @shuang. I tried simple logic and it worked I extracted the required classes from poi-3.9.jar so now I have a folder call org in which all the required classes are.

ExcelCopy.jar
|
|----com/utility/ExcelFormat.java
|
|----org/apache(long dir structure)
|
|----META-INF/Manifest.mf

and content of Manifest.mf

Manifest-Version: 1.0
Class-Path: org
Main-Class: com.utility.ExcelFormat

Now my jar is running. :D

Upvotes: 0

shuang
shuang

Reputation: 246

You don't need to bundle lib/poi-3.9.jar within your ExcelCopy.jar. Remove it from the JAR, then you will have:

ExcelCopy.jar
|
|-com/utility/ExcelFormat.java
|-META-INF/Manifest.mf

Then you have:

ExcelCopy.jar
lib/poi-3.9jar

Running "java -jar ExcelCopy.jar" shall work.

Upvotes: 2

Related Questions