Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

210
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda