JAR files and manifest: Class-Path

Discussion in 'Java' started by Karsten Wutzke, Jan 6, 2004.

  1. Hi!

    I have a base dir, where the application JAR file resides. In this base
    dir, there's also a lib dir, nothing special really. In this lib dir are
    some user look and feel JAR files, which are supposed to be loaded when
    the application is started via the JAR file.

    Is there any way to use the Class-Path entry in the manifest, so that it
    scans that ./lib directory and loads all the JARs in there, *without
    knowing up-front, what these files are*?

    I tried

    Class-Path: ./lib
    Class-Path: ./lib/
    Class-Path: ./lib/*
    Class-Path: ./lib/*.jar

    but none of them work.

    Maybe there's some other way, which I don't know of. I simply don't want
    to explicitly deploy the JAR's (versions, size etc.).

    Anyway, how do I do it?

    Karsten Wutzke, Jan 6, 2004
    1. Advertisements

  2. Manish Hatwalne, Jan 6, 2004
    1. Advertisements

  3. I had a look at this document before. Anyway, lib/ *doesn't* work.

    Any other ideas? I need some kind of regular expression to include *all*
    JAR's in a certain path.


    Karsten Wutzke, Jan 6, 2004
  4. Karsten Wutzke

    Dave Glasser Guest

    Check out my app QueryForm. It does exactly what you are trying to do,
    but it doesn't use the manifest Class-Path mechanism. The homepage is

    It uses a custom classloader to load all of the .jar and .zip files in
    a directory called "drivers" which is below the directory where the
    application jar file is. These jar files can contain JDBC drivers or
    third-party look-and-feels. You load them into the classloader at
    runtime like this:

    ClassLoader loader = ExtensionClassLoader.getSingleton();
    loader.addArchivesInDirectory(new File(pathToLibDirectory));

    (See the code in org/glasser/qform/QForm.java for more details on how
    it discovers the path to the lib (drivers) directory at runtime.)

    Then, when you need a new look and feel, provided you have the class
    name, you can do:

    ClassLoader loader = ExtensionClassLoader.getSingleton();
    Class lafClass = loader.loadClass(lafClassName);
    LookAndFeel laf = (LookAndFeel) lafClass.newInstance();
    UIManager.getDefaults().put("ClassLoader", lafClassgetClassLoader());

    The source for ExtensionClassLoader is in
    org/glasser/util/ExtensionClassLoader.java. It's released under an
    Apache-style license, so you can use it in a closed-source,
    proprietary program if you want.
    Dave Glasser, Jan 7, 2004
  5. I doubt it.
    Can be done in a shell script.

    Code (Text):


    for I in ./lib/*.jar
    echo "java -classpath \"$CP\" MyClass"
    Thomas Schodt, Jan 7, 2004
  6. Karsten Wutzke

    hiwa Guest

    Accoding to the tutorial at Sun's site, answer is:

    Class-Pass: lib/aaa.jar lib/bbb.jar lib/xyz.jar

    Point is: (1)use relative path
    (2)delimiter here is space
    hiwa, Jan 13, 2004
  7. Karsten Wutzke


    Jun 10, 2009
    Likes Received:
    work around

    Maybe it would be useful for someone

    I have the same problem and i solved it so

    app.jar - my application
    lib/ - directory for extensions (jar files)

    suppose app.Main - main class

    to startup application you can invoke

    java -cp "app.jar:lib/*" app.Main

    Last edited: Jun 10, 2009
    Ilya, Jun 10, 2009
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.