I have a maven java ee application
Path to the file is
~/Work/appname/WebContent/resources/json/menu.json
After deploying on glassfish file located here:
~/Tools/glassfish4/glassfish/domains/domain1/applications/appname/resources/json/menu.json
In this file stores menu in json format. I need to do basic crud (create, read, update, delete) operations with this file.
I've tried to get file like this:
InputStream inputStream = ModulMenuUtil.class.getClassLoader().getResourceAsStream("/menu.json");
I get a NullPointerException. I don't know how to get path to this file. Please help me.
Make sure your json
folder and the file are placed under src/main/resources
.
Try the following:
this.getClass().getClassLoader().getResourceAsStream("json/menu.json");
or (not recommended)
Thread.currentThread().getContextClassLoader().getResourceAsStream("json/menu.json");
If both methods don't work you can also try to put the file in the root of your src
folder.
See also:
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.