Tuomas Toivonen
Tuomas Toivonen

Reputation: 23492

JAR manifest Class-Path, use folder instead of jar

I have the following directory structure

--conf
|   |
|   --foo.properties
|
--lib
   |
   --application.jar

In my application.jar's MANIFEST.mf file I have the following entry: Class-Path: ../conf/

In the class inside jar (called by the main method of jar) I try to load the foo.properties file as classpath resource using following code

URL properties = this.getClass().getClassLoader().getResource("foo.properties");

However, the resource couldn't be found from the classpath. Why isn't the Class-Path attribute working in the jar manifest? Have I misunderstood how it affects the application classloader classpath?

I'm running the application with following command

java -jar application.jar

Upvotes: 0

Views: 2460

Answers (1)

Indra Basak
Indra Basak

Reputation: 7394

It should work. Not sure, whether your MANIFEST.mf is formatted properly. I generated mine with Maven and it works. This is how my MANIFEST.mf looks like,

Manifest-Version: 1.0
Archiver-Version: Plexus Archiver
Built-By: john.doe
Class-Path: ../conf/
Created-By: Apache Maven 3.3.9
Build-Jdk: 1.8.0_92
Main-Class: com.basaki.misc.clazzpath.FindResource

You can find a complete example here.

Upvotes: 1

Related Questions