Java maven project trying to read file from resources -
i trying read xml file resources folder of maven web project, instead of trying read source files, tries read jar file generated in web-inf folder, throws not found exception. how can address issue? thanks
classloader classloader = getclass().getclassloader(); file file = new file(classloader.getresource("folder_x/file.xml").getfile());
under resources, have folder_x , in there have file.xml
if run:
classloader classloader = getclass().getclassloader(); file file = new file(classloader.getresource("/folder_x/file.xml").getfile());
i null pointer exception.
pom.xml
:
<?xml version="1.0" encoding="utf-8"?> <project xmlns="maven.apache.org/pom/4.0.0"; xmlns:xsi="w3.org/2001/xmlschema-instance"; xsi:schemalocation="maven.apache.org/pom/4.0.0 maven.apache.org/xsd/maven-4.0.0.xsd">; <modelversion>4.0.0</modelversion> <groupid>xmltest</groupid> <artifactid>xmltest</artifactid> <version>1.0-snapshot</version> </project>
Comments
Post a Comment