java - FileNotFoundException when accessing a resource file after deploy to tomcat -
i got 2 maven projects:
- a jar resource file accessed code
- a war has restful service uses jar
when jar unit tests run, able access resource file.
after deploying tomcat, access resource file fails filenotfoundexception
i tried both these lines same results:
file file = new file(getclass().getclassloader().getresource("file.xml").getfile());
and
file file = new file(getclass().getresource("/file.xml").getfile());
when debugging, found value of file
following:
file:/usr/share/tomcat8/webapps/root/web-inf/lib/com.projectgroup.projectname-1.0-snapshot.jar!/file.xml
i've opened jar @ location , found file there. idea why happening.
try use getresourceasstream()
insteed of resource.getfile()
another way xml file loaded in classpath using spring framework below:
pathmatchingresourcepatternresolver resolver = new pathmatchingresourcepatternresolver(); resolver.getresources("classpath*:your/package/**/file.xml");
Comments
Post a Comment