Basically, I have a model of my project set up this way:
ModelFolder
----- CSI
----- bin, etc.
----- PropertiesFolder1
--------File1.properties
--------File2.properties, etc.
----- PropertiesFolder2
--------File1.properties
--------File2.properties, etc.
-----MainPropertiesFile1.properties
----- MainPropertiesFile2.properties
I try to use it with my view, which is a dynamic web project, and I got property files that finally loaded in my web project after changing
foo.load(new FileInputStream("foo.properties"));
to
foo.load(Thread.currentThread().getContextClassLoader().getResourceAsStream("foo.properties"));
and export the project to a JAR file, which is then included in WEB-INF / lib. However, I had to add another method to the model, and when I tried to test this method, the model was unable to read my properties file. I know that I can use FileInputStream with the full path to get a properties file that works in the model and view, but are there any alternatives?
I don’t want to constantly change the full path every time I switch computers (I use H: \ username \ ... \ Java \ Workspace at work, while at home it is just C: \ Java \ Workspace).
I also do not want my property files to be moved to different folders; and finally, I don’t want to change the way the properties file is loaded every time I test my model or my view.
Is there any way to do this?
It drives me crazy, I tried all of the following:
try { foo.load(this.getClass().getResourceAsStream("foo.properties")); //foo.load(Thread.currentThread().getContextClassLoader().getResourceAsStream("foo.properties")); //foo.getClass().getResourceAsStream("foo.properties"); //foo.load(new FileInputStream("foo.properties")); } catch (IOException ex) { al.logIntoProgrammerLog(ex); }
All these lines either work in the model or in the view. Is it possible to somehow call these property files through the relative path in the model, and then somehow properly connect the model to the view so that all files are found and loaded?
Any help would be greatly appreciated; I am new to Java, so maybe something very simple to me. Thanks.
EDIT:
Sorry for not clarifying this, the model is a Java project, while the view is a dynamic web project running on the local Tomcat Server version 6.0.
Better (hopefully) explanation:
My View has a LoginServlet with the following doPost method:
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { String username = request.getParameter("usernameField"); String password = request.getParameter("passwordField"); ActivityLogger al = new ActivityLogger(); LoginController l_c = new LoginController();
Thanks again