You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by john S <em...@gmail.com> on 2009/05/26 16:26:33 UTC
Problem Reading Property files
Hi All
I am planning to migrate my web application from iplanet 4.1 to
tomcat 6. In this process I need to read the properties files initially.
for eg: i got the property files in a *iPlanet*:
*Config
directory*---
*abc.properties.---*
*
abc.log--
*
In *tomcat* I configured them in *web.xml* saying that.
<servlet>
<servlet-name>ABC</servlet-name>
<servlet-class>com.ijk.abc</servlet-class>
<init-param>
<param-name>Loan</param-name>
* <param-value>/WEB-INF/config</param-value>*
</init-param>
<init-param>
<param-name>loan.props</param-name>
* <param-value>/WEB-INF/config/abc.props</param-value>*
</init-param>
<init-param>
<param-name>loan.log</param-name>
* <param-value>/WEB-INF/config/abc.log</param-value>*
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>ABC</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
I need to read initially all the property files and then proceed.
While configuring in this way, it am getting error saying that
* abc.props or abc.log..............(FILE NOT FOUND EXCEPTION)*
Can anyone suggest me how to configure them.
Thanks in Advance.
Re: Problem Reading Property files
Posted by john S <em...@gmail.com>.
I am really not sure where to configure the Servlet Arguments in tomcat. Can
any one help me please.......
On Tue, May 26, 2009 at 1:26 PM, Juha Laiho <Ju...@iki.fi> wrote:
> john S wrote:
> > I am planning to migrate my web application from iplanet 4.1 to
> > tomcat 6. In this process I need to read the properties files initially.
> >
> > for eg: i got the property files in a *iPlanet*:
> > *Config
> > directory*---
> >
> > *abc.properties.---*
> > *
> >
> > abc.log--
> > *
> >
> > In *tomcat* I configured them in *web.xml* saying that.
> >
> >
> > <servlet>
> > <servlet-name>ABC</servlet-name>
> > <servlet-class>com.ijk.abc</servlet-class>
> > <init-param>
> > <param-name>Loan</param-name>
> > * <param-value>/WEB-INF/config</param-value>*
> > </init-param>
> > <init-param>
> > <param-name>loan.props</param-name>
> > * <param-value>/WEB-INF/config/abc.props</param-value>*
> > </init-param>
> > <init-param>
> > <param-name>loan.log</param-name>
> > * <param-value>/WEB-INF/config/abc.log</param-value>*
> > </init-param>
> > <load-on-startup>1</load-on-startup>
> > </servlet>
> > <servlet-mapping>
> > <servlet-name>ABC</servlet-name>
> > <url-pattern>/</url-pattern>
> > </servlet-mapping>
> >
> >
> > I need to read initially all the property files and then proceed.
> > While configuring in this way, it am getting error saying that
> > * abc.props or abc.log..............(FILE NOT FOUND EXCEPTION)*
>
> You're missing some data form your question.
>
> The above web.xml snipper tells me that you're set a bunch
> of servlet init parameter variables to their corresponding
> values.
>
> What you're not telling is:
> - how you're reading the parameter values in your applications
> (code)
> - what you're doing to the values after you've read them
> (code)
> - how you're attempting to access the actual files
> (code)
> - where the files are located respective to your web-app
> set-up (I can guess based on the web.xml snippet, but just
> want to make sure)
>
> Or in other words, you're missing a SSCCE (http://www.sscce.org/).
> --
> ..Juha
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org
>
>
Re: Problem Reading Property files
Posted by Christopher Schultz <ch...@christopherschultz.net>.
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
John,
On 5/26/2009 10:43 PM, john S wrote:
> Thanks for your response, Actually we dont have the source code for that
> because it is very old code, but i m using decompiler in which i can get
> some information.
:(
> this.m_im.gatherProperties(localProcessorGroup);-----------this is where it
> is calling the property files.*
(Note that localProcessorGroup is not declared in your code snippet.
[snip]
> public void gatherProperties(ProcessorGroup paramProcessorGroup)*
> {
> Object localObject;
> this.m_props.clear();
>
> String str1 = this.m_servlet.getInitParameter(*"loan.dir"*);
> if (str1 == null) {
> str1 = System.getProperty("server.root", System.getProperty("user.dir",
> "."));
> }
>
> this.m_props.put("loan.dir", str1);
>
> String str2 = this.m_servlet.getInitParameter("abc.log");
> setLogFile(str2);
The code for setLogFile might be useful. Oh, and the stack trace of the
original exception.
> try
> {
> String str3 = this.m_servlet.getInitParameter("abc.props");
> if (str3 == null)
> str3 = "abc.props";
>
> localObject = str1 + File.separator + str3;
> Utils.info("Reading properties from file: " + ((String)localObject));
What does this line of code print to the log file? Or, does nothing
print because the log file has not been correctly configured?
*Sigh*... why can't people use standard logging facilities instead of
using their own?
> Utils.loadProperties(this.m_props, new BufferedInputStream(new
> FileInputStream((String)localObject)));
Yeah, this really should be changed to getResourceAsStream instead of
using a FileInputStream, though since you don't have the original code
it might not be a good idea to mess around with it.
> }
> catch (IOException localIOException) {
> *Utils.info("NON FATAL WARNING: Could not read props file",
> localIOException);--while running i m getting this error
> *}
Do you get a stack trace along with the error?
> this.m_rroots =
> StringUtils.getPathsFromList(this.m_props.getProperty("resource.path",
> "/com/loan/resources/:/"));
This could be a problem: the use of a forward-slash on a DOS/Windows
filesystem may not get you the desired results. In other code above,
File.separator (and File.pathSeparator) was correctly used so that it
would work on any platform. /This/ line of code uses / and : without
regard for the platform, and is likely to confuse Windows. On the other
hand, nobody here knows what getPathsFromList will do.
>
> clearAllPGs();
> }
> =================================================================
>
> the above is the servlet class and the method which is using to read the
> property files from root directory in Unix.
>
> ie*../opt/mywebapp/loan/abc.props,abc.log*
>
> loan is the directory in which two property files are placed.
If the files are really in /opt/mywebapp/loan/abc.props, then you did
you tell web.xml that they were in [path to webapp]/WEB-INF/config? Just
tell your servlet where the files really are!
> i just want to where to place property files in tomcat so that its going to
> read the property files.
Then you need to move them.
> Right now, i placing it in the
> WEBAPPS/MYWEBAPPLICATION/WEB-INF/LOAN/abc.props,abc.logs.
If you are using /WEB-INF/LOAN/abc.props then you need to use
<param-value>/WEB-INF/LOAN/abc.props</param-value> instead of
<param-value>/WEB-INF/config/abc.props</param-value>.
> Its giving me errors such as FILENOTFOUNDEXCEPTION or cannot read the
> property files.
The path of the file it's trying to read would be immensely helpful. Can
you post a full stack trace please?
> The main problem is ...I donot have the complete source code. while
> decompiling i m not able view complete source code.
You should be able to view the complete, decompiled source code...
- -chris
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/
iEYEARECAAYFAkodRPQACgkQ9CaO5/Lv0PAsTgCfbG0pspsQr+j7byHjYe1GRQw1
M+UAn1psjw0X/DUdVfIqgXaE3w8R53tq
=lvhY
-----END PGP SIGNATURE-----
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org
Re: Problem Reading Property files
Posted by john S <em...@gmail.com>.
Thanks for your response, Actually we dont have the source code for that
because it is very old code, but i m using decompiler in which i can get
some informtaion.
OS used for *iPlanet* is *Unix* but now I need to deploy this application in
*tomcat* in *windows server 2003*.
*
SERVLET CLASS*:
Class com.ijk.abc implements extends *HttpServlet* implements *PropertyKeys*
{
private IClickManager m_im;
public void init(ServletConfig paramServletConfig) throws ServletException
{
Utils.info("Servlet initialization");
try {
super.init(paramServletConfig);
Utils.info("ServerInfo: " + getServletContext().getServerInfo());
PGroup localPGroup = this.m_im.claimPG();
Utils.trace("Got " + localProcessorGroup + " for initialization");
*
this.m_im.gatherProperties(localProcessorGroup);-----------this is where it
is calling the property files.*
this.m_im.freePG(localPGroup);
Utils.trace("Released " + localPGroup + " for new Properties");
localPGroup = this.m_im.claimPG();
Utils.trace("Got " + localPGroup + " for new Properties");
try
{
ConHandler localDBHandler =
(ConHandler)localPGroup.getDBHandler("config.dbhandler");
this.m_im.setNumPGs(localDBHandler.getNumPGroups());
}
catch (Exception localException1) {
Utils.info("NON FATAL ERROR: failed to set number of PGs", localException1);
}
try
{
Session.createAndStartSessionTask(localPGroup);
localPGroup.resumeAllTasks();
}
catch (Exception localException2) {
Utils.info("NON FATAL ERROR: failed to start tasks", localException2);
}
this.m_im.freePG(localPGroup);
Utils.trace("Released " + localPGroup + " for initialization");
Utils.info("Servlet initialization finished");
}
catch (FatalServletError localFatalServletError) {
Utils.error("FatalServletError: ", localFatalServletError);
throw new UnavailableException(this, localFatalServletError.toString());
}
catch (Error localError) {
Utils.error("Error: ", localError);
throw localError;
}
}
}
------------------------
*
public void gatherProperties(ProcessorGroup paramProcessorGroup)*
{
Object localObject;
this.m_props.clear();
String str1 = this.m_servlet.getInitParameter(*"loan.dir"*);
if (str1 == null) {
str1 = System.getProperty("server.root", System.getProperty("user.dir",
"."));
}
this.m_props.put("loan.dir", str1);
String str2 = this.m_servlet.getInitParameter("abc.log");
setLogFile(str2);
try
{
String str3 = this.m_servlet.getInitParameter("abc.props");
if (str3 == null)
str3 = "abc.props";
localObject = str1 + File.separator + str3;
Utils.info("Reading properties from file: " + ((String)localObject));
Utils.loadProperties(this.m_props, new BufferedInputStream(new
FileInputStream((String)localObject)));
}
catch (IOException localIOException) {
*Utils.info("NON FATAL WARNING: Could not read props file",
localIOException);--while running i m getting this error
*}
Utils.info("Reading properties from Servlet Parameters");
Enumeration localEnumeration = this.m_servlet.getInitParameterNames();
while (localEnumeration.hasMoreElements()) {
localObject = (String)localEnumeration.nextElement();
this.m_props.put(localObject,
this.m_servlet.getInitParameter((String)localObject));
}
Utils.info("Reading properties from DB");
try {
localObject =
(ConDBHandler)paramProcessorGroup.getDBHandler("config.dbhandler");
String str5 = ((ConDBHandler)localObject).getPropertiesFile();
Utils.loadProperties(this.m_props, new
ByteArrayInputStream(str5.getBytes()));
}
catch (Exception localException) {
*Utils.info("NON FATAL WARNING: Could not read props file",
localIOException);--while running i m getting this error*
}
String str4 = this.m_props.getProperty("smtp.host");
if (str4 != null) MailUtils.setSMTPHost(str4.trim());
if (str2 == null) {
str2 = this.m_props.getProperty("*abc.log");*
setLogFile(str2);
}
runInitializers(paramPGroup);
Utils.info("New Properties:", this.m_props);
this.m_rroots =
StringUtils.getPathsFromList(this.m_props.getProperty("resource.path",
"/com/loan/resources/:/"));
clearAllPGs();
}
=================================================================
the above is the servlet class and the method which is using to read the
property files from root directory in Unix.
ie*../opt/mywebapp/loan/abc.props,abc.log*
loan is the directory in which two property files are placed.
i just want to where to place property files in tomcat so that its going to
read the property files.
Right now, i placing it in the
WEBAPPS/MYWEBAPPLICATION/WEB-INF/LOAN/abc.props,abc.logs.
Its giving me errors such as FILENOTFOUNDEXCEPTION or cannot read the
property files.
The main problem is ...I donot have the complete source code. while
decompiling i m not able view complete source code.
Please help me regarding this.........
Thanks in advance.
Re: Problem Reading Property files
Posted by David Smith <dn...@cornell.edu>.
Assuming you wrote this servlet, it would *really* help if you provided
relevant parts of your servlet where this file is read. We're flying
blind here.
Normally the servlet would do something like this:
class MyServlet extends javax.servlet.http.HttpServlet {
function init(ServletConfig sc) throws javax.servlet.ServletException {
string properties_file_path = sc.getInitParameter( "loan.props" ) ;
try {
loanProps = new java.util.Properties() ;
loanProps.load(
sc.getServletContext().getResourceAsStream(properties_file_path) ) ;
/* Do something with the properties object ... maybe make it
a class variable. */
} catch (java.io.FileNotFoundException fnfe) {
throw new ServletException( "Could not configure. Servlet
disabled.", fnfe) ;
}
}
/* other methods here */
}
This may not be perfect, but it's enough to illustrate the idea. With
the above, you should be able to declare the path to your properties in
the web.xml as servlet init-params.
I'm guessing iPlanet is doing something different. What's posted above
is supported as part of the servlet spec.
--David
john S wrote:
> I placed under WEB-INF itself. I created a directory called config adn
> placed the abc.props and abc.log under it.
>
> Whether i need to configure them in the web.xml? or should i remove it from
> there.
>
> Because wen i removed the init param, there is no change i am getting the
> same error......not able to find the abc.props or abc.log files
> .........FILENOTFOUNDEXCEPTION.
>
> Just want to know where should i specify them.
>
> On Tue, May 26, 2009 at 2:34 PM, Juha Laiho <Ju...@iki.fi> wrote:
>
>
>> john S wrote:
>>
>>> Actually, I am not sure where to place and configure the property
>>> files (*SERVLET ARGS*) in tomcat.
>>>
>> If it's ok for you to have the files deployed along with your application,
>> then I'd like to propose the following:
>> Place the files within /WEB-INF/ directory in your web application.
>> You could also create a subdirectory within /WEB-INF/ to contain
>> just these files, such as /WEB-INF/config/ .
>>
>> Then read the files with getResourceAsStream method of ServletContext,
>> and process the stream to get the data you need. This way is specified
>> by the Servlet specification, so is portable across different containers.
>>
>>
>> Files places within /WEB-INF/ cannot be accessed by direct browser
>> requests, so they are safe from prying eyes.
>>
>> The other way would be to place the configuration files outside
>> your web application. For this you'll likely want to split the
>> "root" directory for the files from the file names (and possibly
>> directory hierarchy underneath the "root") so that the placement
>> underneath the "root" is dictated by the application, but the "root"
>> location is set from outside the application. For this there is no
>> standard way, but you could use a Java system property (specified
>> with "-Dprop_name=value" on the JVM command line), or Tomcat context
>> parameters, to set the root directory. The placement underneath the
>> root would still be as it is now. Then in your code you'd concatenate
>> the "root" location with the file path/name from web.xml and process
>> the files as such.
>>
>> --
>> ..Juha
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
>> For additional commands, e-mail: users-help@tomcat.apache.org
>>
>>
>>
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org
Re: Problem Reading Property files
Posted by john S <em...@gmail.com>.
I placed under WEB-INF itself. I created a directory called config adn
placed the abc.props and abc.log under it.
Whether i need to configure them in the web.xml? or should i remove it from
there.
Because wen i removed the init param, there is no change i am getting the
same error......not able to find the abc.props or abc.log files
.........FILENOTFOUNDEXCEPTION.
Just want to know where should i specify them.
On Tue, May 26, 2009 at 2:34 PM, Juha Laiho <Ju...@iki.fi> wrote:
> john S wrote:
> > Actually, I am not sure where to place and configure the property
> > files (*SERVLET ARGS*) in tomcat.
>
> If it's ok for you to have the files deployed along with your application,
> then I'd like to propose the following:
> Place the files within /WEB-INF/ directory in your web application.
> You could also create a subdirectory within /WEB-INF/ to contain
> just these files, such as /WEB-INF/config/ .
>
> Then read the files with getResourceAsStream method of ServletContext,
> and process the stream to get the data you need. This way is specified
> by the Servlet specification, so is portable across different containers.
>
>
> Files places within /WEB-INF/ cannot be accessed by direct browser
> requests, so they are safe from prying eyes.
>
> The other way would be to place the configuration files outside
> your web application. For this you'll likely want to split the
> "root" directory for the files from the file names (and possibly
> directory hierarchy underneath the "root") so that the placement
> underneath the "root" is dictated by the application, but the "root"
> location is set from outside the application. For this there is no
> standard way, but you could use a Java system property (specified
> with "-Dprop_name=value" on the JVM command line), or Tomcat context
> parameters, to set the root directory. The placement underneath the
> root would still be as it is now. Then in your code you'd concatenate
> the "root" location with the file path/name from web.xml and process
> the files as such.
>
> --
> ..Juha
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org
>
>
Re: Problem Reading Property files
Posted by Juha Laiho <Ju...@iki.fi>.
john S wrote:
> Actually, I am not sure where to place and configure the property
> files (*SERVLET ARGS*) in tomcat.
If it's ok for you to have the files deployed along with your application,
then I'd like to propose the following:
Place the files within /WEB-INF/ directory in your web application.
You could also create a subdirectory within /WEB-INF/ to contain
just these files, such as /WEB-INF/config/ .
Then read the files with getResourceAsStream method of ServletContext,
and process the stream to get the data you need. This way is specified
by the Servlet specification, so is portable across different containers.
Files places within /WEB-INF/ cannot be accessed by direct browser
requests, so they are safe from prying eyes.
The other way would be to place the configuration files outside
your web application. For this you'll likely want to split the
"root" directory for the files from the file names (and possibly
directory hierarchy underneath the "root") so that the placement
underneath the "root" is dictated by the application, but the "root"
location is set from outside the application. For this there is no
standard way, but you could use a Java system property (specified
with "-Dprop_name=value" on the JVM command line), or Tomcat context
parameters, to set the root directory. The placement underneath the
root would still be as it is now. Then in your code you'd concatenate
the "root" location with the file path/name from web.xml and process
the files as such.
--
..Juha
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org
Re: Problem Reading Property files
Posted by john S <em...@gmail.com>.
Thanks for your response.
Actually, I am not sure where to place and configure the property
files (*SERVLET
ARGS*) in tomcat.
The problem is-> In the iPlanet webserver they configured the servlet
configurations in this way:
*Servlet Name: *
* Servlet Code (class name): *
* Servlet Classpath: *
* Servlet Args: loan=/opt/mywebapp/config,
loan.props=abc.props, loan.log=abc.log*
CONFIG IS DIRECTORY AND IN WHICH *ABC.PROPS* AND *ABC.LOG* ARE PRESENT.
While migrating them to Tomcat 6, I need to configure the *SERVLET ARGS in
the tomcat.*
The think is all the security setting and database handlers are present in
the property files itself.
For eg : In my web application wen I click the login button in
login.html .it needs to read the configuration files (abc.props and
abc.logs) and redirects to index.html.
*Can you help me where to place these servlet arg in the web.xml or
somewhere else.,so that its going to read them.?*
**
On Tue, May 26, 2009 at 1:26 PM, Juha Laiho <Ju...@iki.fi> wrote:
> john S wrote:
> > I am planning to migrate my web application from iplanet 4.1 to
> > tomcat 6. In this process I need to read the properties files initially.
> >
> > for eg: i got the property files in a *iPlanet*:
> > *Config
> > directory*---
> >
> > *abc.properties.---*
> > *
> >
> > abc.log--
> > *
> >
> > In *tomcat* I configured them in *web.xml* saying that.
> >
> >
> > <servlet>
> > <servlet-name>ABC</servlet-name>
> > <servlet-class>com.ijk.abc</servlet-class>
> > <init-param>
> > <param-name>Loan</param-name>
> > * <param-value>/WEB-INF/config</param-value>*
> > </init-param>
> > <init-param>
> > <param-name>loan.props</param-name>
> > * <param-value>/WEB-INF/config/abc.props</param-value>*
> > </init-param>
> > <init-param>
> > <param-name>loan.log</param-name>
> > * <param-value>/WEB-INF/config/abc.log</param-value>*
> > </init-param>
> > <load-on-startup>1</load-on-startup>
> > </servlet>
> > <servlet-mapping>
> > <servlet-name>ABC</servlet-name>
> > <url-pattern>/</url-pattern>
> > </servlet-mapping>
> >
> >
> > I need to read initially all the property files and then proceed.
> > While configuring in this way, it am getting error saying that
> > * abc.props or abc.log..............(FILE NOT FOUND EXCEPTION)*
>
> You're missing some data form your question.
>
> The above web.xml snipper tells me that you're set a bunch
> of servlet init parameter variables to their corresponding
> values.
>
> What you're not telling is:
> - how you're reading the parameter values in your applications
> (code)
> - what you're doing to the values after you've read them
> (code)
> - how you're attempting to access the actual files
> (code)
> - where the files are located respective to your web-app
> set-up (I can guess based on the web.xml snippet, but just
> want to make sure)
>
> Or in other words, you're missing a SSCCE (http://www.sscce.org/).
> --
> ..Juha
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org
>
>
Re: Problem Reading Property files
Posted by Juha Laiho <Ju...@iki.fi>.
john S wrote:
> I am planning to migrate my web application from iplanet 4.1 to
> tomcat 6. In this process I need to read the properties files initially.
>
> for eg: i got the property files in a *iPlanet*:
> *Config
> directory*---
>
> *abc.properties.---*
> *
>
> abc.log--
> *
>
> In *tomcat* I configured them in *web.xml* saying that.
>
>
> <servlet>
> <servlet-name>ABC</servlet-name>
> <servlet-class>com.ijk.abc</servlet-class>
> <init-param>
> <param-name>Loan</param-name>
> * <param-value>/WEB-INF/config</param-value>*
> </init-param>
> <init-param>
> <param-name>loan.props</param-name>
> * <param-value>/WEB-INF/config/abc.props</param-value>*
> </init-param>
> <init-param>
> <param-name>loan.log</param-name>
> * <param-value>/WEB-INF/config/abc.log</param-value>*
> </init-param>
> <load-on-startup>1</load-on-startup>
> </servlet>
> <servlet-mapping>
> <servlet-name>ABC</servlet-name>
> <url-pattern>/</url-pattern>
> </servlet-mapping>
>
>
> I need to read initially all the property files and then proceed.
> While configuring in this way, it am getting error saying that
> * abc.props or abc.log..............(FILE NOT FOUND EXCEPTION)*
You're missing some data form your question.
The above web.xml snipper tells me that you're set a bunch
of servlet init parameter variables to their corresponding
values.
What you're not telling is:
- how you're reading the parameter values in your applications
(code)
- what you're doing to the values after you've read them
(code)
- how you're attempting to access the actual files
(code)
- where the files are located respective to your web-app
set-up (I can guess based on the web.xml snippet, but just
want to make sure)
Or in other words, you're missing a SSCCE (http://www.sscce.org/).
--
..Juha
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org
Re: Problem Reading Property files
Posted by john S <em...@gmail.com>.
Thanks for your response, Actually we dont have the source code for that
because it is very old code, but i m using decompiler in which i can get
some informtaion.
OS used for *iPlanet* is *Unix* but now I need to deploy this application in
*tomcat* in *windows server 2003*.
Servlet clss:
*SERVLET CLASS*:
Class com.ijk.abc implements extends *HttpServlet* implements *PropertyKeys
*
**{
private IClickManager m_im;
public void init(ServletConfig paramServletConfig)
throws ServletException
{
Utils.info("Servlet initialization");
try {
super.init(paramServletConfig);
Utils.info("ServerInfo: " + getServletContext().getServerInfo());
PGroup localPGroup = this.m_im.claimPG();
Utils.trace("Got " + localProcessorGroup + " for initialization");
* this.m_im.gatherProperties(localProcessorGroup);-----------this is
where it is calling the property files.*
this.m_im.freePG(localPGroup);
Utils.trace("Released " + localPGroup + " for new Properties");
localPGroup = this.m_im.claimPG();
Utils.trace("Got " + localPGroup + " for new Properties");
try
{
ConHandler localDBHandler =
(ConHandler)localPGroup.getDBHandler("config.dbhandler");
this.m_im.setNumPGs(localDBHandler.getNumPGroups());
}
catch (Exception localException1) {
Utils.info("NON FATAL ERROR: failed to set number of PGs",
localException1);
}
try
{
Session.createAndStartSessionTask(localPGroup);
localPGroup.resumeAllTasks();
}
catch (Exception localException2) {
Utils.info("NON FATAL ERROR: failed to start tasks",
localException2);
}
this.m_im.freePG(localPGroup);
Utils.trace("Released " + localPGroup + " for initialization");
Utils.info("Servlet initialization finished");
}
catch (FatalServletError localFatalServletError) {
Utils.error("FatalServletError: ", localFatalServletError);
throw new UnavailableException(this,
localFatalServletError.toString());
}
catch (Error localError) {
Utils.error("Error: ", localError);
throw localError;
}
}
}
==========================================================
*public void gatherProperties(ProcessorGroup paramProcessorGroup)*
{
Object localObject;
this.m_props.clear();
String str1 = this.m_servlet.getInitParameter(*"loan.dir"*);
if (str1 == null) {
str1 = System.getProperty("server.root",
System.getProperty("user.dir", "."));
}
this.m_props.put("loan.dir", str1);
String str2 = this.m_servlet.getInitParameter("abc.log");
setLogFile(str2);
try
{
String str3 = this.m_servlet.getInitParameter("abc.props");
if (str3 == null)
str3 = "abc.props";
localObject = str1 + File.separator + str3;
Utils.info("Reading properties from file: " + ((String)localObject));
Utils.loadProperties(this.m_props, new BufferedInputStream(new
FileInputStream((String)localObject)));
}
catch (IOException localIOException) {
* Utils.info("NON FATAL WARNING: Could not read props file",
localIOException);--while running i m getting this error
* }
Utils.info("Reading properties from Servlet Parameters");
Enumeration localEnumeration = this.m_servlet.getInitParameterNames();
while (localEnumeration.hasMoreElements()) {
localObject = (String)localEnumeration.nextElement();
this.m_props.put(localObject,
this.m_servlet.getInitParameter((String)localObject));
}
Utils.info("Reading properties from DB");
try {
localObject =
(ConDBHandler)paramProcessorGroup.getDBHandler("config.dbhandler");
String str5 = ((ConDBHandler)localObject).getPropertiesFile();
Utils.loadProperties(this.m_props, new
ByteArrayInputStream(str5.getBytes()));
}
catch (Exception localException) {
*Utils.info("NON FATAL WARNING: Could not read props file",
localIOException);--while running i m getting this error*
}
String str4 = this.m_props.getProperty("smtp.host");
if (str4 != null) MailUtils.setSMTPHost(str4.trim());
if (str2 == null) {
str2 = this.m_props.getProperty("*abc.log");*
setLogFile(str2);
}
runInitializers(paramPGroup);
Utils.info("New Properties:", this.m_props);
this.m_rroots =
StringUtils.getPathsFromList(this.m_props.getProperty("resource.path",
"/com/loan/resources/:/"));
clearAllPGs();
}
=================================================================
the above is the servlet class and the method which is using to read the
property files from root directory in Unix.
ie..*/opt/mywebapp/loan/abc.props,abc.lo*g
loan is the directory in which two property files are placed.
i just want to where to place property files in tomcat so that its going to
read the property files.
Right now, i placing it in the
WEBAPPS/MYWEBAPPLICATION/WEB-INF/LOAN/abc.props,abc.logs.
Its giving me errors such as FILENOTFOUNDEXCEPTION or cannot read the
property files.
The main problem is ...I donot have the complete source code. while
decompiling i m not able view complete source code.
Please help me regarding this.........
Thanks in advance.
Re: Problem Reading Property files
Posted by Konstantin Kolinko <kn...@gmail.com>.
2009/5/26 john S <em...@gmail.com>:
>
> <servlet>
> <servlet-name>ABC</servlet-name>
> <servlet-class>com.ijk.abc</servlet-class>
> <init-param>
Who wrote this "com.ijk.abc" servlet?
Does it have installation instructions? Are you following them?
Do you have source code? If not, ask the authors of that servlet.
If you do not know how they read those files, most of your
attempts will be futile.
What is your operating system?
> *Servlet Name: *
> * Servlet Code (class name): *
> * Servlet Classpath: *
> * Servlet Args: loan=/opt/mywebapp/config,
> loan.props=abc.props, loan.log=abc.log*
/opt/.. is an absolute path. So I think that relative paths
(/WEB-INF/...) that you are trying to use, will not work in your case.
Also, loan.props and loan.log are relative paths.
Also, parameter names are case-sensitive. It is "loan", not "Loan"
that you tried.
Best regards,
Konstantin Kolinko
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org