Since it was really difficult for me to find an answer to this question I'm gonna post both the question and the answer I found to this problem.
Problem: How to use a configuration file in java while working with Netbeans and deploying into a GlassFish Server?
Main problem is to actually access the file (a lot of trouble with the path in which things as getResource, creating a new File and getting it's absolute path, and many other tricks didn't work).
In this particular case I wanted the file to be in my ejb Project.
You will be able to see the file from Netbeans in your project configuration Files:
Once your code is deployed to GlassFIsh, all conf files seem to be deployed to this META-INF folder:
private String[] getBadWordsFromFile() throws IOException { InputStream resourceAsStream = getClass().getClassLoader().getResourceAsStream(BAD_WORDS_FILE_NAME); Properties properties = new Properties(); properties.load(resourceAsStream); String badWordsAsString = properties.getProperty(BAD_WORDS_PROPERTY_NAME); return badWordsAsString.split(BAD_WORDS_SEPARATOR); }
This was the Solution I found, which worked but was only tested on a local machine... this might get some trouble on Release.
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.