I have Java webapp and I am trying to read a file from classpth.
if (fileName == null){
fileName = Thread.currentThread().getContextClassLoader().getResource("config.properties");
}
objFile = new File(fileName.toURI());
I have config.properties in my classpath. WEB-INF/classes. When I inspect locally it gives: fileName.toURI(), it gives me file:/D:/dev/Tomcat_6_0/webapps/testApp/WEB-INF/classes/config.properties. And works fine.
Issue is on production linux server I am getting this path there vfsfile:/export/home/u/bin/jboss-5.1.0.BE/server/default/deploy/testApp.war/WEB-INF/classes/config.properties.
And I am getting following exception.
Caused by: java.lang.IllegalArgumentException: URI scheme is not "file"
at java.io.File.<init>(File.java:366)
at com.utils.ConfigLoader.loadConfigFilePath(ConfigLoader.java:87)
What is the workaround for handeling vfs?
You must not try to convert a resource from the classpath to a File. It may not even be a File if it’s inside a WAR/JAR. The File class only represents filesystem objects.