I have some classes packages in a .jar and put in the myApp\WEB-INF\lib folder of TomCat. These classes read a properties file which will be placed under a conf folder. Fo ex., they should read a file "\conf\db.properties" to get some info. When i created a 'conf' folder under the lib directory, the classes does'nt read from there. Should i package them along with the .jar. But I wanted it to be editable any time.. Any idea where the file should be?
If you want to threat a file on the file syatem the same as you have it in the jar, you need to place it in the myApp\WEB-INF\classes\conf\ directory The ClassLoader is designed so that it only loads jars from the lib directory, not other files. Also be aware that while this is something I do often, it ony works for properties used in pure web-apps. If you have a distributed app with EJB components etc you'l have to find another solution, since these won't be able to see the properties file. Dave
Sure it's ok! It's actually a good practice to keep your configuration info (in the properties file) separate from the code. That way you can deploy the same code to a production or deployment site, and leave the config files there. Some people achieve this using ant to actually construct the prop files, but I don't. Just lazy I guess. Wherever you put them, you need to make sure your app can find them. What I usually do (to prevent hard-coding of these paths) is to use a properties file reader class that searches the classpath for the given file. It also checks every few seconds to see if the file date has changed, and reloads if appropriate. That way I don't need to restart tomcat for config changes. Let me know if you want some code!
David! It still does'nt work. Here is my directory structure %CATALINA_ROOT%\webapps\myapp my jsps and HTML are in myapp folder The \WEB-INF\classes\conf folder has my db.properties file. The \WEB-INF\lib folder contains myapp.jar and the Connector/J mySQL driver jar. The myapp.jar contains classes inpackage structure similar to this org.xxx.web; The bean in this package says it cannot find the db.properties file and raises FileNotFoundException. Here is that code snippet
This is my URL and Driver Class URL : mysql:jdbc://localhost:3306/tamilini?user=tamuser Driver : com.mysql.jdbc.Driver And this is the Exception
hi the exception you showed is not from a missing file but from a missing jdbc driver. make sure your jdbc driver is available to the servlet (or the webserver, depending on how you use it) for the properties file: create a File object with your file name and printout the absolute path to see what file you are trying to read. k