0
votes

I'm working with a local WebSphere server configured in IntelliJ Idea, and the application I'm working on is using a third-party library that loads a properties file with:

ThirdPartyClass.class.getClassLoader().getResourceAsStream(fileNameParameter);

It uses the default bootstrapClassLoader.

I've been instructed to make sure the properties file is in a config directory so that it can be edited without deploying a code change. My project looks something like this:

ProjectName
    Configs
        my.properties
    src
        java (sources root)
            packages, .java files, etc
        main (resources root)
            schemas, web docs, etc

I have tried several of paths to make it work but it always returns null. Since I initially thought it was reaching from within the third party library package, I tried adding several ..\'s to the file path, but then I learned that this method loads from the classpath, so I pulled a

String test = System.getProperty("java.class.path");

and upon inspection, my classpath is all made up of websphere directories and jars within them:

C:\Users\me\Programs\IBM\AppServer\profiles\AppSrv01/properties C:\Users\me\Programs\IBM\AppServer\AppSrv01/properties and several jar files in C:\Users\me\Programs\IBM\AppServer/lib/

So just as a test I stuck the file in C:\Users\me\Programs\IBM\AppServer\AppSrv01/properties, then tried to grab it with just its file name (my.properties), but still couldn't reach it. I've also tried moving the file into the src directory and the main directory, but no matter what I do it just can't seem to find the file.

I'm aware that this method is typically used to grab resources from within a jar file, but from my understanding it seems like it should be possible to reach my file from outside of one as long as it's in a directory in the classpath... but apparently not since that didn't work.

I have the absolute path on my hard drive and will have said path on the server; is there a way to derive the path that ClassLoader.getResourceFromStream() wants with that info? Failing that, is there some obvious mistake I'm making with the resource url?

1

1 Answers

0
votes

I think your fileNameParameter simply needs to start with / to indicate that it is in the root level of the classpath. Otherwise it will be searched relative to the class it is loaded from, i.e. the package of ThirdPartyClass in your example.