java - FileNotFoundException when accessing a resource file after deploy to tomcat -


i got 2 maven projects:

  1. a jar resource file accessed code
  2. 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

Popular posts from this blog

sql - invalid in the select list because it is not contained in either an aggregate function -

Angularjs unit testing - ng-disabled not working when adding text to textarea -

How to start daemon on android by adb -