tags:

views:

3155

answers:

3

Hello All,

I have written a program in Eclipse IDE which uses BouncyProvider class of BouncyCastle.jar. So to compile my class I added BouncyCastle.jar in my project classpath and it compiles perfectly.

Now I want to export my project as Runnable JAR so when I do that from Eclipse, it by default adds the classes of BouncyCastle.jar also in that runnable jar.

But I want to keep my application jar and BouncyCastle.jar different from each other.

How can I achieve this? Can anybody please help?

+1  A: 

Unfortunately, looks like you can't actually do that. A JAR can't use another JAR that's stored inside itself.

I'd say, unless you have a really strong reason why you can't unpack your BouncyCastle.jar (like maybe licensing problems?)

just let it unpack (which you can do by adding BouncyCastle.jar as an external archive in Eclipse:)

Right-click on your project
Build Path...
Add External Archives...
Add your archive
Export as runnable JAR)

and watch your package names for conflicts.

Here's an open Java bug ID I found describing your situation

One-JAR may help - a open source solution to your situation

Brabster
One would assume the OP wants to have two separate jars, with the application jar referring to the BouncyCastle jar by way of the classpath directive in the manifest.
Michael Myers
+1  A: 

It sounds like you want to use the "Export JAR File" wizard instead of the "Export Runnable JAR File" wizard. When exporting a runnable jar file, Eclipse attempts to pack everything needed to run the application into a single archive. On the other hand, the "Export JAR File" wizard gives you more control over what is packaged in the archive. You can still create a runnable jar file, but you must make sure to include BouncyCastle.jar on the classpath when you execute the jar. Here are step-by-step instructions:

  1. Click "File | Export". The Export dialog pops up.
  2. Expand the "Java" folder and select "JAR file" (not "Runnable JAR file"). Click Next. On the JAR file specification page, choose the classes you want included in the jar file, and specify the name of the JAR file to create. Click Next.
  3. On the JAR Packaging Options page, select options appropriate for you. The defaults are probably fine. Click Next.
  4. On the JAR Manifest Specification, make sure to select the "Main class" for your jar file. This is the class that will be executed when you execute the jar file. If you leave this blank, the jar file will not be runnable. Click Finish to create the jar file.

You should be able to execute the jar file by executing "java -jar myjarfile.jar -classpath BouncyCastle.jar" from a command line.

ThisIsTheDave
A: 

It looks like this has been added in Eclipse 3.5 Milestone 5. See the News for the latest build and bug 219530

Mark