Help coderanch get a
new server
by contributing to the fundraiser
  • 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 ...
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
  • Mikalai Zaikin

jar file classpath

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

I rarely make JAR files, but I currently need one. Anyways, I have forgotten a lot of things about their creation. The one thing I did figure out is that I need a manifest file with a classpath in it.

I need to point to some jar files that are located in C:/Program Files/ 2.3/program/classes/

When I add this to my jar file's class path it doesn't seem to work. I am assuming it has something to do with the spaces. I tried putting "" around the whole thing as you would on the DOS prompt, but still no luck.

Every time I get a NoClassDefFoundError at runtime on the JAR.

Could someone refresh my memory and show me how to add C:/Program Files/ 2.3/program/classes/ to my JAR file's CLASSPATH?

And before you ask I can't copy the JARs I need else where, they only run out of that particular folder, which is the source of many problems.


Posts: 3648
Android Mac OS X Firefox Browser Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Jon, if you are using JDK6 and if your class files are located in C:/Program Files/ 2.3/program/classes/
then try this:
jar cvfe <jarfilename>.jar <mainclass> -C "C:/Program Files/ 2.3/program/classes/" .

If not create manifest file with the following lines:
Main-Class: <classname>
Class-Path: "C:/Program Files/ 2.3/program/classes/"

then do
jar cvfm <jarfilename>.jar <manifestfilename> -C "C:/Program Files/ 2.3/program/classes/"

The only thing I'm not sure of is if you need to specify individual jar files in the manifest's class path since you can't use .../*.jar while leaving as is just adds all files in that dir to your jar file.

Jar command description

Usage: jar {ctxui}[vfm0Me] [jar-file] [manifest-file] [entry-point] [-C dir] files ...
-c create new archive
-t list table of contents for archive
-x extract named (or all) files from archive
-u update existing archive
-v generate verbose output on standard output
-f specify archive file name
-m include manifest information from specified manifest file
-e specify application entry point for stand-alone application
bundled into an executable jar file
-0 store only; use no ZIP compression
-M do not create a manifest file for the entries
-i generate index information for the specified jar files
-C change to the specified directory and include the following file
If any file is a directory then it is processed recursively.
The manifest file name, the archive file name and the entry point name are
specified in the same order as the 'm', 'f' and 'e' flags.

Example 1: to archive two class files into an archive called classes.jar:
jar cvf classes.jar Foo.class Bar.class
Example 2: use an existing manifest file 'mymanifest' and archive all the
files in the foo/ directory into 'classes.jar':
jar cvfm classes.jar mymanifest -C foo/ .

Hopes this help
Jon Parise
Ranch Hand
Posts: 81
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'd like to use a manifest file for this since I am redistributing this JAR.

Currently, I have a JAR file that netbeans created. The only problem is that Netbeans wants to copy the files locally as I mentioned in another thread. I have found about a dozen other posts with peopel having the same netbeans issue.

Anyways, what I am now trying is this:

1) Extract the jar file with WinRAR/WinZip
2) Fix the incorrect classpath netbeans provided
3) zip the folder back into a zip file
4) Change the extension to .jar

This works, except it still can't find my jar files..

What I need to know is if within the manifest file I should put C:\Program Files or "C:\Program Files" or something else. Right now neither seems to work.

Here is the manifest(and yes it ends in a newline)

What makes this incredibly annoying is that it runs just fine in Netbeans, referencing the JARs like it should. However when it makes the JAR it sets the classpath incorrectly...
The world's cheapest jedi mind trick: "Aw c'mon, why not read this tiny ad?"
We need your help - Coderanch server fundraiser
    Bookmark Topic Watch Topic
  • New Topic