VManoj
VManoj

Reputation: 75

How to access the resource files that are kept under resources folder

How to get the absolute path of the files(cacerts.pem,client.pem,client-key.pem) that are kept under the folders as below in the image

This is in the eclipse and gradle environmententer image description here

Upvotes: 0

Views: 879

Answers (2)

NXT Dev
NXT Dev

Reputation: 91

Using Spring:

Resource resource = new ClassPathResource("file/location/cert.pem");
File file = resource.getFile();

Upvotes: 0

Miguel Arroja
Miguel Arroja

Reputation: 81

I usually use a cheat to get there!

Paths.get(SomeClass.class.getClassLoader().getResource("").toURI());

When the java code is built all resources go to their target output, for example you would have something like target/io/geocloud/management/client/* .

For you specific problem i would change a bit the code and do something like

Paths.get(SomeClass.class.getClassLoader().getResource("io/geocloud/management/client/ca/cacerts.pem").toURI()).toAbsolutePath().toString();

Upvotes: 2

Related Questions