Alex
Alex

Reputation: 7491

How to make a resource file available in a jar?

I have a jar and resource files are in the jar root directory. Inside the code I have:

Kernel.class.getResourceAsStream(resource);

I start the application as

java -cp myjar.jar com.mycompany.MyClass

However, the resource is not found.

Upvotes: 1

Views: 102

Answers (2)

Alex
Alex

Reputation: 7491

I needed to precede the resource name by slash "/". Then finding the resource in the jar root directory works fine

Upvotes: 0

You need your current directory in your classpath.

Linux:

java -cp myjar.jar:. com.mycompany.MyClass

Windows:

java -cp myjar.jar;. com.mycompany.MyClass

Upvotes: 1

Related Questions