문제

I have a simple portlet to deploy in WebSohere Portal Server.

It´s a war file containing a jar file in its lib folder. Inside jar file, I try to read a properties file. In my portlet project, I have a properties file in root of src and can read that inside jar file without problem.

But if I redeploy the war file and don´t restart the server, the below line of code returns null and it can not read from properties file. after restarting server, everything is ok again.

InputStream inStream = this.getClass().getClassLoader().getResourceAsStream("myFile.properties");

I checked the setting of ClassLoader and the parent is LAST. I don´t know what is the reason. Any idea?

도움이 되었습니까?

해결책

Try using the context classloader instead of the class' class loader since you are not bundling the resource in the jar with the class (if I read your description properly).

Thread.currentThread().getContextClassLoader().getResourceAsStream(...)

Do you by chance have this jar in another web module or perhaps in a WebSphere Shared Library folder? Since the behavior you describe is null and not just the old file value I'm less inclined to think caching is involved and more that you're just getting a different class instance than the one you think and because you're using the classloader of the utility class itself, the properties file in the WEB-INF/classes of the web module isn't being found.

다른 팁

The file is read once and cached for performance reasons.

Edit: If you expect a file to be modified, keep the file outside your EAR file on the local file system, and use an environment/server variable to point to its path. Refer to the variable within your code to load the file.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top