We have a web application distributed in a WAR file that consists of
servlets that were compiled from JSPs, one index.jsp file and a number of
JavaBeans and JAR files on Tomcat 3.2.1. When Tomcat is started, it unpacks
the war file correctly with everything in its place. However, part of the
initialization process contained in the index.jsp is to attempt to read a
properties file to obtain the DB connection info. It is the attempt to read
this properties file that causes the NullPointerException. This only happens
when Tomcat has expanded the WAR file. If Tomcat is stopped and started
again, everything works, the property files are found and read.

What can we do to prevent this exception and read the files without
restarting Tomcat after the WAR file has been unpacked?

Here is the code fragment for reading the properties files. The parameter
passed to the method is the name of the properties file. The path is
included in the classpath environment variable.

    /**
     * This static method retrieves and stores a file into the java class
Properties.
     *
     * @param _file The name of the file to be read.
     * @return The converted file to a java Properties class.
     */
    public static Properties getProperties(String _file) throws IOException
{
        Properties p = new Properties();
        InputStream is = Class.class.getResourceAsStream(_file);
        p.load(is);
        is.close();

        return p;
    }

Error stack trace follows:

java.lang.NullPointerException
        at java.io.Reader.<init>(Reader.java:64)
        at java.io.InputStreamReader.<init>(InputStreamReader.java:89)
        at java.io.InputStreamReader.<init>(InputStreamReader.java:78)
        at java.util.Properties.load(Properties.java:189)
        at
com.ieasoftware.bean.util.WebUtilities.getProperties(WebUtilities.java:35)
        at com.ieasoftware.bean.BeanBase.initProperties(BeanBase.java:77)
        at
_0002findex_0002ejspindex_jsp_0._jspService(_0002findex_0002ejspindex_jsp_0.
java:772)
        at
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:119)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
        at
org.apache.jasper.servlet.JspServlet$JspServletWrapper.service(JspServlet.ja
va:177)
        at
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:318)
        at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:391)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
        at
org.apache.tomcat.core.ServletWrapper.doService(ServletWrapper.java:404)
        at org.apache.tomcat.core.Handler.service(Handler.java:286)
        at
org.apache.tomcat.core.ServletWrapper.service(ServletWrapper.java:372)
        at
org.apache.tomcat.core.ContextManager.internalService(ContextManager.java:79
7)
        at
org.apache.tomcat.core.ContextManager.service(ContextManager.java:743)
        at
org.apache.tomcat.service.http.HttpConnectionHandler.processConnection
HttpConnectionHandler.java:210)
        at
org.apache.tomcat.service.TcpWorkerThread.runIt(PoolTcpEndpoint.java:416)
        at
org.apache.tomcat.util.ThreadPool$ControlRunnable.run(ThreadPool.java:498)
        at java.lang.Thread.run(Thread.java:484)



   Richard Hart
   Sr. Software Engineer
   IEA Software, Inc.
   http://www.iea-software.com



---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, email: [EMAIL PROTECTED]

Reply via email to