RE: How to start a standalone app from a servlet and problems with reading properties file
On 19 Dec 2002 at 11:14, aps olute wrote: The problem is someone else had written the support class. The support class will only take (File f) as its argument in its constructor. The You could read your properties, put it into a temp file, which you are guaranteed to be able to create, and pass the temp file. See this very recent message From: Bill Barker [EMAIL PROTECTED] Subject: Re: How do load a properties file from servlet? Date: Thu, 19 Dec 2002 21:27:00 -0800 support classes are written by separate developers. I can make changes to the portion I am responsible for but cant do much with the other part. Anyhow, the support class is having a fit not finding this file to read. My servlet sits at mycontext/WEB-INF/classes/ and the support class sits at mycontext/WEB-INF/classes/util/ so the relative path to that support class is then mycontext/WEB-INF/classes/util/ and this is where I would put the file it needs? --- Tim Moore [EMAIL PROTECTED] wrote: Well when you call getResourceAsStream, the path is resolved relative to the package the class is in, so if the servlet and the support class are in different packages, this would be expected. What if you call it on the servlet class from the support class? e.g., InputStream is = WhateverTheServletIsCalled.class.getResourceAsStream( parmPassedFromServlet ) or even better, instead of passing the file name from the servlet to the support class, why not have the servlet just load the properties and pass the properties object to the support class? -- Tim Moore / Blackboard Inc. / Software Engineer 1899 L Street, NW / 5th Floor / Washington, DC 20036 Phone 202-463-4860 ext. 258 / Fax 202-463-4863 -Original Message- From: aps olute [mailto:[EMAIL PROTECTED]] Sent: Thursday, December 19, 2002 1:45 PM To: Tomcat Users List Subject: Re: How to start a standalone app from a servlet and problems with reading properties file Tim, Thanks for responding. Partial success was I was able to read the properties file using code snippet below in the servlet init() method: Properties p = new Properties(); InputStream is = getClass().getResourceAsStream(configFileName); //configFileName is test.properties p.load(is) This property file is loaded and parsed for a property needed by a support class. The parameter read is passed to the support class. When doing exact same InputStream is = getClass().getResourceAsStream(parmPassedFromservlet); in the support class, Tomcat does not start. I posted this earlier last week on: http://marc.theaimsgroup.com/?l=tomcat-userm=103982860916736 w=2 Basically, I am facing two issues, 1) dependent on where I start Tomcat from and 2) Using getResourceAsStream() fails in the support class. Any tips would be appreciated. Thanks. __ Do you Yahoo!? Yahoo! Mail Plus - Powerful. Affordable. Sign up now. http://mailplus.yahoo.com -- To unsubscribe, e-mail: mailto:[EMAIL PROTECTED] For additional commands, e-mail: mailto:[EMAIL PROTECTED] -- To unsubscribe, e-mail: mailto:[EMAIL PROTECTED] For additional commands, e-mail: mailto:[EMAIL PROTECTED] __ Do you Yahoo!? Yahoo! Mail Plus - Powerful. Affordable. Sign up now. http://mailplus.yahoo.com -- To unsubscribe, e-mail: mailto:[EMAIL PROTECTED] For additional commands, e-mail: mailto:[EMAIL PROTECTED] -- To unsubscribe, e-mail: mailto:[EMAIL PROTECTED] For additional commands, e-mail: mailto:[EMAIL PROTECTED]
How to start a standalone app from a servlet and problems with reading properties file
Greetings, I have been trying to do the following using Tomcat 4.1.12: 1) Attempt to have a servlet read a properties or any text file. Reading the file from the doGet() method by: BufferedReader br = null; br = new BufferedReader(new FileReader(file)); //file is test.properties Result: Varying success, because I dont quite comprehend the Tomcat startup directory. Discovered that there is dependency on from where Tomcat was started. For example, if started Tomcat by ./bin/starup.sh from tomcat_home/bin/, I must have the file the servlet reads located at tomcat_cat/bin/. If I started Tomcat from tomcat_home/webapps/ by ../bin/startup.sh, I must have the properties file located at tomcat_home/webapps/ or else the servlet will not find this. 2) Atempt to have a servlet read a properties or any text file. Reading the file from the init() method by: BufferedReader br = null; br = new BufferedReader(new FileReader(file)); Result: Starting Tomcat from tomcat_home/bin/ by ./bin/startup.sh, failure to get Tomcat even to start, the log shows it only goes as far as Apache Tomcat/4.1.12 and stops. Starting Tomcat from tomcat_home/webapps/ by ../bin/startup.sh Tomcat starts, some other context are running, but the servlet reading this properties file on this specific context fails to find the properties file. Is using File IO bad in the init() method? I want to do this to initialize a standalone application. I surmized I cant read a properties file from init() method using File class. I did try as one suggested about using getResourceAsStream() with partial success. 3) Can a stand alone application be started at all from a servlet? I cant seem to get this to work, either from the init() or doGet() method. I can not launch an application why from a servlet, why? Any help on #3 please? __ Do you Yahoo!? Yahoo! Mail Plus - Powerful. Affordable. Sign up now. http://mailplus.yahoo.com -- To unsubscribe, e-mail: mailto:[EMAIL PROTECTED] For additional commands, e-mail: mailto:[EMAIL PROTECTED]
Re: How to start a standalone app from a servlet and problems with reading properties file
Hi, this question has been answered many times. Look for properties files in the archive. Hint: Use servletContext.getResourceAsStream(); On 19 Dec 2002 at 9:20, aps olute wrote: Greetings, I have been trying to do the following using Tomcat 4.1.12: 1) Attempt to have a servlet read a properties or any text file. Reading the file from the doGet() method by: BufferedReader br = null; br = new BufferedReader(new FileReader(file)); //file is test.properties Result: Varying success, because I dont quite comprehend the Tomcat startup directory. Discovered that there is dependency on from where Tomcat was started. For example, if started Tomcat by ./bin/starup.sh from tomcat_home/bin/, I must have the file the servlet reads located at tomcat_cat/bin/. If I started Tomcat from tomcat_home/webapps/ by ../bin/startup.sh, I must have the properties file located at tomcat_home/webapps/ or else the servlet will not find this. 2) Atempt to have a servlet read a properties or any text file. Reading the file from the init() method by: BufferedReader br = null; br = new BufferedReader(new FileReader(file)); Result: Starting Tomcat from tomcat_home/bin/ by ./bin/startup.sh, failure to get Tomcat even to start, the log shows it only goes as far as Apache Tomcat/4.1.12 and stops. Starting Tomcat from tomcat_home/webapps/ by ../bin/startup.sh Tomcat starts, some other context are running, but the servlet reading this properties file on this specific context fails to find the properties file. Is using File IO bad in the init() method? I want to do this to initialize a standalone application. I surmized I cant read a properties file from init() method using File class. I did try as one suggested about using getResourceAsStream() with partial success. 3) Can a stand alone application be started at all from a servlet? I cant seem to get this to work, either from the init() or doGet() method. I can not launch an application why from a servlet, why? Any help on #3 please? -- To unsubscribe, e-mail: mailto:[EMAIL PROTECTED] For additional commands, e-mail: mailto:[EMAIL PROTECTED]
Re: How to start a standalone app from a servlet and problems with reading properties file
Can you kindly read the entire posting before responding? I did mention I attmpted to use geResourceAsStream() with partial sucess didnt I? There are several questions posted, so please read the entirety and put your responses according to the numbered question. The next reader of the post would most likely ignore the entire post because you Andreas Probst seem to answer the entire post without regard to the whole picture. There were 3 question posted. Your partial answer may have answered one, and did not answer the rest. --- Andreas Probst [EMAIL PROTECTED] wrote: Hi, this question has been answered many times. Look for properties files in the archive. Hint: Use servletContext.getResourceAsStream(); On 19 Dec 2002 at 9:20, aps olute wrote: Greetings, I have been trying to do the following using Tomcat 4.1.12: 1) Attempt to have a servlet read a properties or any text file. Reading the file from the doGet() method by: BufferedReader br = null; br = new BufferedReader(new FileReader(file)); //file is test.properties Result: Varying success, because I dont quite comprehend the Tomcat startup directory. Discovered that there is dependency on from where Tomcat was started. For example, if started Tomcat by ./bin/starup.sh from tomcat_home/bin/, I must have the file the servlet reads located at tomcat_cat/bin/. If I started Tomcat from tomcat_home/webapps/ by ../bin/startup.sh, I must have the properties file located at tomcat_home/webapps/ or else the servlet will not find this. 2) Atempt to have a servlet read a properties or any text file. Reading the file from the init() method by: BufferedReader br = null; br = new BufferedReader(new FileReader(file)); Result: Starting Tomcat from tomcat_home/bin/ by ./bin/startup.sh, failure to get Tomcat even to start, the log shows it only goes as far as Apache Tomcat/4.1.12 and stops. Starting Tomcat from tomcat_home/webapps/ by ../bin/startup.sh Tomcat starts, some other context are running, but the servlet reading this properties file on this specific context fails to find the properties file. Is using File IO bad in the init() method? I want to do this to initialize a standalone application. I surmized I cant read a properties file from init() method using File class. I did try as one suggested about using getResourceAsStream() with partial success. 3) Can a stand alone application be started at all from a servlet? I cant seem to get this to work, either from the init() or doGet() method. I can not launch an application why from a servlet, why? Any help on #3 please? -- To unsubscribe, e-mail: mailto:[EMAIL PROTECTED] For additional commands, e-mail: mailto:[EMAIL PROTECTED] __ Do you Yahoo!? Yahoo! Mail Plus - Powerful. Affordable. Sign up now. http://mailplus.yahoo.com -- To unsubscribe, e-mail: mailto:[EMAIL PROTECTED] For additional commands, e-mail: mailto:[EMAIL PROTECTED]
RE: How to start a standalone app from a servlet and problems with reading properties file
What does partial success mean? And in regards to question three, what exactly did you try, and in what manner did it fail? -- Tim Moore / Blackboard Inc. / Software Engineer 1899 L Street, NW / 5th Floor / Washington, DC 20036 Phone 202-463-4860 ext. 258 / Fax 202-463-4863 -Original Message- From: aps olute [mailto:[EMAIL PROTECTED]] Sent: Thursday, December 19, 2002 1:11 PM To: Tomcat Users List Subject: Re: How to start a standalone app from a servlet and problems with reading properties file Can you kindly read the entire posting before responding? I did mention I attmpted to use geResourceAsStream() with partial sucess didnt I? There are several questions posted, so please read the entirety and put your responses according to the numbered question. The next reader of the post would most likely ignore the entire post because you Andreas Probst seem to answer the entire post without regard to the whole picture. There were 3 question posted. Your partial answer may have answered one, and did not answer the rest. --- Andreas Probst [EMAIL PROTECTED] wrote: Hi, this question has been answered many times. Look for properties files in the archive. Hint: Use servletContext.getResourceAsStream(); On 19 Dec 2002 at 9:20, aps olute wrote: Greetings, I have been trying to do the following using Tomcat 4.1.12: 1) Attempt to have a servlet read a properties or any text file. Reading the file from the doGet() method by: BufferedReader br = null; br = new BufferedReader(new FileReader(file)); //file is test.properties Result: Varying success, because I dont quite comprehend the Tomcat startup directory. Discovered that there is dependency on from where Tomcat was started. For example, if started Tomcat by ./bin/starup.sh from tomcat_home/bin/, I must have the file the servlet reads located at tomcat_cat/bin/. If I started Tomcat from tomcat_home/webapps/ by ../bin/startup.sh, I must have the properties file located at tomcat_home/webapps/ or else the servlet will not find this. 2) Atempt to have a servlet read a properties or any text file. Reading the file from the init() method by: BufferedReader br = null; br = new BufferedReader(new FileReader(file)); Result: Starting Tomcat from tomcat_home/bin/ by ./bin/startup.sh, failure to get Tomcat even to start, the log shows it only goes as far as Apache Tomcat/4.1.12 and stops. Starting Tomcat from tomcat_home/webapps/ by ../bin/startup.sh Tomcat starts, some other context are running, but the servlet reading this properties file on this specific context fails to find the properties file. Is using File IO bad in the init() method? I want to do this to initialize a standalone application. I surmized I cant read a properties file from init() method using File class. I did try as one suggested about using getResourceAsStream() with partial success. 3) Can a stand alone application be started at all from a servlet? I cant seem to get this to work, either from the init() or doGet() method. I can not launch an application why from a servlet, why? Any help on #3 please? -- To unsubscribe, e-mail: mailto:[EMAIL PROTECTED] For additional commands, e-mail: mailto:[EMAIL PROTECTED]
Re: How to start a standalone app from a servlet and problems with reading properties file
Tim, Thanks for responding. Partial success was I was able to read the properties file using code snippet below in the servlet init() method: Properties p = new Properties(); InputStream is = getClass().getResourceAsStream(configFileName); //configFileName is test.properties p.load(is) This property file is loaded and parsed for a property needed by a support class. The parameter read is passed to the support class. When doing exact same InputStream is = getClass().getResourceAsStream(parmPassedFromservlet); in the support class, Tomcat does not start. I posted this earlier last week on: http://marc.theaimsgroup.com/?l=tomcat-userm=103982860916736w=2 Basically, I am facing two issues, 1) dependent on where I start Tomcat from and 2) Using getResourceAsStream() fails in the support class. Any tips would be appreciated. Thanks. __ Do you Yahoo!? Yahoo! Mail Plus - Powerful. Affordable. Sign up now. http://mailplus.yahoo.com -- To unsubscribe, e-mail: mailto:[EMAIL PROTECTED] For additional commands, e-mail: mailto:[EMAIL PROTECTED]
RE: How to start a standalone app from a servlet and problems with reading properties file
Well when you call getResourceAsStream, the path is resolved relative to the package the class is in, so if the servlet and the support class are in different packages, this would be expected. What if you call it on the servlet class from the support class? e.g., InputStream is = WhateverTheServletIsCalled.class.getResourceAsStream( parmPassedFromServlet ) or even better, instead of passing the file name from the servlet to the support class, why not have the servlet just load the properties and pass the properties object to the support class? -- Tim Moore / Blackboard Inc. / Software Engineer 1899 L Street, NW / 5th Floor / Washington, DC 20036 Phone 202-463-4860 ext. 258 / Fax 202-463-4863 -Original Message- From: aps olute [mailto:[EMAIL PROTECTED]] Sent: Thursday, December 19, 2002 1:45 PM To: Tomcat Users List Subject: Re: How to start a standalone app from a servlet and problems with reading properties file Tim, Thanks for responding. Partial success was I was able to read the properties file using code snippet below in the servlet init() method: Properties p = new Properties(); InputStream is = getClass().getResourceAsStream(configFileName); //configFileName is test.properties p.load(is) This property file is loaded and parsed for a property needed by a support class. The parameter read is passed to the support class. When doing exact same InputStream is = getClass().getResourceAsStream(parmPassedFromservlet); in the support class, Tomcat does not start. I posted this earlier last week on: http://marc.theaimsgroup.com/?l=tomcat-userm=103982860916736; w=2 Basically, I am facing two issues, 1) dependent on where I start Tomcat from and 2) Using getResourceAsStream() fails in the support class. Any tips would be appreciated. Thanks. __ Do you Yahoo!? Yahoo! Mail Plus - Powerful. Affordable. Sign up now. http://mailplus.yahoo.com -- To unsubscribe, e-mail: mailto:[EMAIL PROTECTED] For additional commands, e-mail: mailto:[EMAIL PROTECTED] -- To unsubscribe, e-mail: mailto:[EMAIL PROTECTED] For additional commands, e-mail: mailto:[EMAIL PROTECTED]
RE: How to start a standalone app from a servlet and problems with reading properties file
The problem is someone else had written the support class. The support class will only take (File f) as its argument in its constructor. The support classes are written by separate developers. I can make changes to the portion I am responsible for but cant do much with the other part. Anyhow, the support class is having a fit not finding this file to read. My servlet sits at mycontext/WEB-INF/classes/ and the support class sits at mycontext/WEB-INF/classes/util/ so the relative path to that support class is then mycontext/WEB-INF/classes/util/ and this is where I would put the file it needs? --- Tim Moore [EMAIL PROTECTED] wrote: Well when you call getResourceAsStream, the path is resolved relative to the package the class is in, so if the servlet and the support class are in different packages, this would be expected. What if you call it on the servlet class from the support class? e.g., InputStream is = WhateverTheServletIsCalled.class.getResourceAsStream( parmPassedFromServlet ) or even better, instead of passing the file name from the servlet to the support class, why not have the servlet just load the properties and pass the properties object to the support class? -- Tim Moore / Blackboard Inc. / Software Engineer 1899 L Street, NW / 5th Floor / Washington, DC 20036 Phone 202-463-4860 ext. 258 / Fax 202-463-4863 -Original Message- From: aps olute [mailto:[EMAIL PROTECTED]] Sent: Thursday, December 19, 2002 1:45 PM To: Tomcat Users List Subject: Re: How to start a standalone app from a servlet and problems with reading properties file Tim, Thanks for responding. Partial success was I was able to read the properties file using code snippet below in the servlet init() method: Properties p = new Properties(); InputStream is = getClass().getResourceAsStream(configFileName); //configFileName is test.properties p.load(is) This property file is loaded and parsed for a property needed by a support class. The parameter read is passed to the support class. When doing exact same InputStream is = getClass().getResourceAsStream(parmPassedFromservlet); in the support class, Tomcat does not start. I posted this earlier last week on: http://marc.theaimsgroup.com/?l=tomcat-userm=103982860916736; w=2 Basically, I am facing two issues, 1) dependent on where I start Tomcat from and 2) Using getResourceAsStream() fails in the support class. Any tips would be appreciated. Thanks. __ Do you Yahoo!? Yahoo! Mail Plus - Powerful. Affordable. Sign up now. http://mailplus.yahoo.com -- To unsubscribe, e-mail: mailto:[EMAIL PROTECTED] For additional commands, e-mail: mailto:[EMAIL PROTECTED] -- To unsubscribe, e-mail: mailto:[EMAIL PROTECTED] For additional commands, e-mail: mailto:[EMAIL PROTECTED] __ Do you Yahoo!? Yahoo! Mail Plus - Powerful. Affordable. Sign up now. http://mailplus.yahoo.com -- To unsubscribe, e-mail: mailto:[EMAIL PROTECTED] For additional commands, e-mail: mailto:[EMAIL PROTECTED]
RE: How to start a standalone app from a servlet and problems with reading properties file
If you MUST create a File object, then you really need to know the full path of the file somehow. You can try using servletContext.getRealPath(/WEB-INF/classes/ + configFileName) but that will mean that you cannot distribute your webapp as a packed WAR, and it may not work in other circumstances (depending on the appserver, security settings, etc.) And of course, you can put the file wherever you want in the webapp, it doesn't have to be in classes (and probably shouldn't be, since it's not a class, natch). Just pass getRealPath the path relative to the context root. -- Tim Moore / Blackboard Inc. / Software Engineer 1899 L Street, NW / 5th Floor / Washington, DC 20036 Phone 202-463-4860 ext. 258 / Fax 202-463-4863 -Original Message- From: aps olute [mailto:[EMAIL PROTECTED]] Sent: Thursday, December 19, 2002 2:14 PM To: Tomcat Users List Subject: RE: How to start a standalone app from a servlet and problems with reading properties file The problem is someone else had written the support class. The support class will only take (File f) as its argument in its constructor. The support classes are written by separate developers. I can make changes to the portion I am responsible for but cant do much with the other part. Anyhow, the support class is having a fit not finding this file to read. My servlet sits at mycontext/WEB-INF/classes/ and the support class sits at mycontext/WEB-INF/classes/util/ so the relative path to that support class is then mycontext/WEB-INF/classes/util/ and this is where I would put the file it needs? --- Tim Moore [EMAIL PROTECTED] wrote: Well when you call getResourceAsStream, the path is resolved relative to the package the class is in, so if the servlet and the support class are in different packages, this would be expected. What if you call it on the servlet class from the support class? e.g., InputStream is = WhateverTheServletIsCalled.class.getResourceAsStream( parmPassedFromServlet ) or even better, instead of passing the file name from the servlet to the support class, why not have the servlet just load the properties and pass the properties object to the support class? -- Tim Moore / Blackboard Inc. / Software Engineer 1899 L Street, NW / 5th Floor / Washington, DC 20036 Phone 202-463-4860 ext. 258 / Fax 202-463-4863 -Original Message- From: aps olute [mailto:[EMAIL PROTECTED]] Sent: Thursday, December 19, 2002 1:45 PM To: Tomcat Users List Subject: Re: How to start a standalone app from a servlet and problems with reading properties file Tim, Thanks for responding. Partial success was I was able to read the properties file using code snippet below in the servlet init() method: Properties p = new Properties(); InputStream is = getClass().getResourceAsStream(configFileName); //configFileName is test.properties p.load(is) This property file is loaded and parsed for a property needed by a support class. The parameter read is passed to the support class. When doing exact same InputStream is = getClass().getResourceAsStream(parmPassedFromservlet); in the support class, Tomcat does not start. I posted this earlier last week on: http://marc.theaimsgroup.com/?l=tomcat-userm=103982860916736; w=2 Basically, I am facing two issues, 1) dependent on where I start Tomcat from and 2) Using getResourceAsStream() fails in the support class. Any tips would be appreciated. Thanks. __ Do you Yahoo!? Yahoo! Mail Plus - Powerful. Affordable. Sign up now. http://mailplus.yahoo.com -- To unsubscribe, e-mail: mailto:[EMAIL PROTECTED] For additional commands, e-mail: mailto:[EMAIL PROTECTED] -- To unsubscribe, e-mail: mailto:tomcat-user- [EMAIL PROTECTED] For additional commands, e-mail: mailto:[EMAIL PROTECTED] __ Do you Yahoo!? Yahoo! Mail Plus - Powerful. Affordable. Sign up now. http://mailplus.yahoo.com -- To unsubscribe, e-mail: mailto:[EMAIL PROTECTED] For additional commands, e-mail: mailto:[EMAIL PROTECTED] -- To unsubscribe, e-mail: mailto:[EMAIL PROTECTED] For additional commands, e-mail: mailto:[EMAIL PROTECTED]