PeeWee2201
PeeWee2201

Reputation: 1524

Get parent in the same jar of a classpath resource

I have in the resources of my Maven project an index.html file in the res/html folder. I am running Jetty as an embedded webserver. I want to tell him that the base resource for static content is the res/ folder.

So, I tried:

ResourceHandler rh = new ResourceHandler();
rh.setResourceBase(getClass().getResource("/res").toURI().toString());

It worked until I included another jar on my classpath which also have a res/ folder. Jetty started to look for static content in thisotherjar.jar!res/

I would like to avoid having to give literally the path of the jar that contains my res folder. I am looking for something more generic. I tried to start with the classpath of the file index.html and then go up the the res folder using URI.resolve("..") but the same problem happens.

Any ideas to solve this nicely?

Thanks!

Upvotes: 0

Views: 708

Answers (1)

David
David

Reputation: 5519

You should use a name that is less prone to collisions, exactly like for the Java packages. You do not name a package res because if everyone did that there would be conflicts every time we incorporate two libs.

Instead of the res directory give it a name that is specific to you such as com/mycompany/myproject/res.

Upvotes: 1

Related Questions