tags:

views:

300

answers:

2

Hello All,

I have made jar file for my application. One of the class of my application uses BouncyCastleProvider class of BC jar.

I have created one folder "lib" in the same parent folder where my application jar is residing.

I have changed my machine CLASSPATH to point to this new lib folder. But when I run my application it gives me classnotfound exception.

But if I copy this BC jar file to my jre/lib/ext then everything works fine.

Can anybody tell me what I need to do to access BC jar file from my lib directory?

Thanks in Advance, Jenish

A: 

Your JAR file must have its MANIFEST.MF file set to declare the classpath for the JAR.#

Extract from the Sun Tutorial below, in your case you just need to make the Class-Path directive point to your lib directory, presumably

Class-Path: lib/BouncyCastle.jar

We want to load classes in MyUtils.jar into the class path for use in MyJar.jar. These two JAR files are in the same directory.

We first create a text file named Manifest.txt with the following contents:

Class-Path: MyUtils.jar

Warning : The text file must end with a new line or carriage return.

The last line will not be parsed properly if it does not end with a new line or carriage return.

We then create a JAR file named MyJar.jar by entering the following command:

jar cfm MyJar.jar Manifest.txt MyPackage/*.class

This creates the JAR file with a manifest with the following contents:

Manifest-Version: 1.0
Class-Path: MyUtils.jar
Created-By: 1.6.0 (Sun Microsystems Inc.)

The classes in MyUtils.jar are now loaded into the class path when you run MyJar.jar.

Brabster
A: 

Hello Brabster,

I have followed the way you suggested and I was able to run the jar perfectly on WINDOWS but when I try to run same jar on Apple MAC. It gives me exception as below

com.apple.JarLauncher[5595] Exception in thread "main" 2/25/09 2:53:40 PM [0x0-0x215215].com.apple.JarLauncher[5595] java.lang.NoClassDefFoundError: edu/stanford/ejalbert/BrowserLauncher

I have already included path of BrowserLauncher jar in MANIFEST classpath as below

Class-Path: lib\bcprov-jdk15-136.jar lib\BrowserLauncher2-1_3.jar lib\log4j-1.2.13.jar lib\swing-layout-1.0.1.jar

Can anybody please help me out here? Do I need to do some changes for Apple?

Thanks, Jenish

I think your backslashes should be forwardslashes.
Adam Bernier
Sorry, I didn't see your other question
Brabster