Search code examples
javatomcat9

how to get the URL of an external properties file in classpath in TOMCAT 10


I have an external properties file named myAccount.properties. This file resides in a folder called ${catalina.home}/usmo/MyAccount/resources/properties. This folder is being added to the class path thru context.xml using configuration below:

<Resources className="org.apache.catalina.webresources.StandardRoot">
    <PostResources className="org.apache.catalina.webresources.DirResourceSet"
        base="${catalina.home}/usmo/MyAccount/resources/properties"
        internalPath="/"
        webAppMount="/WEB-INF/classes" />
</Resources>

I am expecting code below to return the URL or absolute path of this file. Sadly, it is returning a null. Any help would be appreciated.

URL url = MyClass.class.getClassLoader().getResource( "myAccount.properties" );


            

Solution

  • Turns out to be case sensitive issue. The actual file named is 'MyAccount.properties'. But the code uses 'myAccount.properties'. I change the code to below and it works:

    URL url = MyClass.class.getClassLoader().getResource( "MyAccount.properties" );
    

    Weird behavior though:

    1. The code is running in Windows OS, which is a case insensitive.
    2. The code works fine in TOMCAT 7 under java 8. But failed in TOMCAT 8 under java 11.