3

How can I add a folder to the System ClassLoader classpath so my TOMCAT app find resources?

inside a jar file from a 3rd party lib I have resource been loaded by the code

String resourceName = "MyResource";    
ResourceBundle RESOURCE = ResourceBundle.getBundle(resourceName, Locale.getDefault(), ClassLoader.getSystemClassLoader());

in this folder I have the resources

/opt/properties/
     MyResource.properties
     MyResource_en.properties
     MyResource_en_US.properties
Ruben Trancoso
  • 1,444
  • 5
  • 27
  • 55

1 Answers1

2

Add /opt/properties to the common.loader property of /conf/catalina.properties file.

Code you posted looks correct to load it, should work with that property in place

Durandal
  • 5,575
  • 5
  • 35
  • 49
  • dont know what's happening but i'm still getting java.util.MissingResourceException: Can't find bundle for base name MyResource, locale en_US :? – Ruben Trancoso Jan 31 '14 at 01:16
  • You already restart Tomcat after changing the properties file? – Durandal Jan 31 '14 at 01:20
  • yes, tried to run from eclipse editing the catalina.properties on ide and from command line and the common.loader looks like D:\\opt\\properties,/opt/properties,${catalina.base}/lib,${catalina.base}/lib/*.jar,${catalina.home}/lib,${catalina.home}/lib/*.jar – Ruben Trancoso Jan 31 '14 at 01:22
  • Try it without specifying the ClassLoader: `ResourceBundle RESOURCE = ResourceBundle.getBundle(resourceName, Locale.getDefault());` – Durandal Jan 31 '14 at 01:28
  • I cant, it's a code from a 3rd party. I decompiled the jar to reach this code. – Ruben Trancoso Jan 31 '14 at 01:31
  • I can do a test. Maybe is something with security policy. – Ruben Trancoso Jan 31 '14 at 01:32
  • Yeah that was my next guess; `/opt/*` should be accessible but worth checking. – Durandal Jan 31 '14 at 01:34
  • This might be related: http://stackoverflow.com/questions/19394570/java-jre-7u45-breaks-classloader-getresources – Durandal Jan 31 '14 at 01:43
  • maybe, this is a security lib from an app that I'm rebuilding the environment with no documentation. The class that call the resource is a signed class in production. I'm preparing the code to work on dev without the secret part. This System ClassLoader is doing some trick – Ruben Trancoso Jan 31 '14 at 01:46