Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

208
Views
java access resource files from class loaded by another classloader

I have a class which needs to do some https request.
Just in case the ssl truststore and keystore are not set, the jar which contains my class, has them in its resource folder.
My class is being dynamically loaded by some classloader I have no control about and now when I do

getClass().getClassLoader().getResourceAsStream("keystore.jks");

the resource is not being found.
My theory on this is that getClassLoader returns the classloader returns the classloader from a webserver, which probably isn't able to find the resource keystore.jks in the jar file.
Any help is appreciated.

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

I found a way around the problem. I can use MyClass.class.getResourceAsStream("/keystore.jks"); to load the resource properly.
I am not exactly sure why it works though. When I was using MyClass.class.getClassLoader().getResourceAsStream("keystore.jks"); it wasn't working. Although I think I read somewhere that Class.getResource() with a leading / is the same as ClassLoader.getResource() without one.

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!