简体   繁体   中英

getClass.getResource return null

when i run this line:

URL myurl = getClass().getResource("/bla.xml");

I got myurl is null

if I try to debug in runtime this value "getClass().getResource("/bla.xml")" I got the right value. it seems that something went wrong with placement. what it can be? using eclipse oxygen

If maven directory structure is used you can put the XML file in the resources folder. If resources folder is not available in the maven directory structure , you can create a one. The path of the resources folder are src/main/resources and src/test/resources. The XML file needs to be in the classpath. If you are running the jar, the XML file needs to be embedded in the jar file.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM