tag:blogger.com,1999:blog-30587633.post8173928952828911221..comments2022-04-26T03:37:19.740+05:30Comments on My Wiki: How to read a properties file in a web applicationJaikiranhttp://www.blogger.com/profile/08503182723143814781noreply@blogger.comBlogger39125tag:blogger.com,1999:blog-30587633.post-31519567705522067822014-11-07T13:35:32.483+05:302014-11-07T13:35:32.483+05:30That's right. Be sure to close the InputStream...That's right. Be sure to close the InputStream when you are done using it.<br />Jaikiranhttps://www.blogger.com/profile/08503182723143814781noreply@blogger.comtag:blogger.com,1999:blog-30587633.post-58839544157127341622014-11-07T11:34:40.128+05:302014-11-07T11:34:40.128+05:30It is also important to close the file which is op...It is also important to close the file which is opened in the finally blockVenkatRamannoreply@blogger.comtag:blogger.com,1999:blog-30587633.post-10175592256719537072014-07-24T14:30:59.105+05:302014-07-24T14:30:59.105+05:30Easy, simple and Understandable....Thanks
Easy, simple and Understandable....Thanks<br /><br />Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-30587633.post-42204440240974642242013-04-24T16:08:36.902+05:302013-04-24T16:08:36.902+05:30Hi, i'm working on selenium tool. I've som...Hi, i'm working on selenium tool. I've some problem reading data from a properties file, getting null pointer exception. This is happening when i write some data through automation and read the same data from the file. Please help<br /><br />I'm using Eclipse IDE and java code in selenium webdriverAnonymoushttps://www.blogger.com/profile/14978772412934424032noreply@blogger.comtag:blogger.com,1999:blog-30587633.post-50659453654416979302013-04-08T21:49:24.910+05:302013-04-08T21:49:24.910+05:30at com.sun.grizzly.http.ProcessorTask.doProcess(Pr...<i> <br /> at com.sun.grizzly.http.ProcessorTask.doProcess(ProcessorTask.java:746)<br /> at com.sun.grizzly.http.ProcessorTask.process(ProcessorTask.java:1045)<br /> at com.sun.grizzly.http.DefaultProtocolFilter.execute(DefaultProtocolFilter.java:228)<br /> at com.sun.grizzly.DefaultProtocolChain.executeProtocolFilter(DefaultProtocolChain.java:137)<br /> at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:104)<br /> at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:90)<br /> at com.sun.grizzly.http.HttpProtocolChain.execute(HttpProtocolChain.java:79)<br /> at com.sun.grizzly.ProtocolChainContextTask.doCall(ProtocolChainContextTask.java:54)<br /> at com.sun.grizzly.SelectionKeyContextTask.call(SelectionKeyContextTask.java:59)<br /> at com.sun.grizzly.ContextTask.run(ContextTask.java:71)<br /> at com.sun.grizzly.util.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:532)<br /> at com.sun.grizzly.util.AbstractThreadPool$Worker.run(AbstractThreadPool.java:513)<br /> at java.lang.Thread.run(Thread.java:662)<br /></i><br /><br /><br />PS : the method <i>doSomeOperation</i> became method <i>getProperty</i> in my classthierryhttps://www.blogger.com/profile/18142861951104179170noreply@blogger.comtag:blogger.com,1999:blog-30587633.post-91038584416838148892013-04-08T21:48:13.616+05:302013-04-08T21:48:13.616+05:30I try to use your java class to read a property fi...I try to use your java class to read a property file but each time I used it, i've got a java.lang.NullPointerException. Don't understand what i'm doing wrong<br /><br />Here's the error message :<br /><i>INFO: wsimport successful<br />INFO: InputStream is: null<br />GRAVE: java.lang.NullPointerException<br /> at java.util.Properties$LineReader.readLine(Properties.java:418)<br /> at java.util.Properties.load0(Properties.java:337)<br /> at java.util.Properties.load(Properties.java:325)<br /> at fr.inra.ga.helloworld.MyPropertiesReader.getProperty(MyPropertiesReader.java:42)<br /> at fr.inra.ga.helloworld.HelloWorld.hello(HelloWorld.java:39)<br /> at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)<br /> at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)<br /> at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)<br /> at java.lang.reflect.Method.invoke(Method.java:597)<br /> at org.glassfish.webservices.InstanceResolverImpl$1.invoke(InstanceResolverImpl.java:143)<br /> at com.sun.xml.ws.server.InvokerTube$2.invoke(InvokerTube.java:149)<br /> at com.sun.xml.ws.server.sei.SEIInvokerTube.processRequest(SEIInvokerTube.java:94)<br /> at com.sun.xml.ws.api.pipe.Fiber.__doRun(Fiber.java:961)<br /> at com.sun.xml.ws.api.pipe.Fiber._doRun(Fiber.java:910)<br /> at com.sun.xml.ws.api.pipe.Fiber.doRun(Fiber.java:873)<br /> at com.sun.xml.ws.api.pipe.Fiber.runSync(Fiber.java:775)<br /> at com.sun.xml.ws.api.pipe.helper.AbstractTubeImpl.process(AbstractTubeImpl.java:116)<br /> at org.glassfish.webservices.MonitoringPipe.process(MonitoringPipe.java:142)<br /> at com.sun.xml.ws.api.pipe.helper.PipeAdapter.processRequest(PipeAdapter.java:119)<br /> at com.sun.xml.ws.api.pipe.Fiber.__doRun(Fiber.java:961)<br /> at com.sun.xml.ws.api.pipe.Fiber._doRun(Fiber.java:910)<br /> at com.sun.xml.ws.api.pipe.Fiber.doRun(Fiber.java:873)<br /> at com.sun.xml.ws.api.pipe.Fiber.runSync(Fiber.java:775)<br /> at com.sun.xml.ws.api.pipe.helper.AbstractTubeImpl.process(AbstractTubeImpl.java:116)<br /> at com.sun.enterprise.security.webservices.CommonServerSecurityPipe.processRequest(CommonServerSecurityPipe.java:212)<br /> at com.sun.enterprise.security.webservices.CommonServerSecurityPipe.process(CommonServerSecurityPipe.java:144)<br /> at com.sun.xml.ws.api.pipe.helper.PipeAdapter.processRequest(PipeAdapter.java:119)<br /> at com.sun.xml.ws.api.pipe.Fiber.__doRun(Fiber.java:961)<br /> at com.sun.xml.ws.api.pipe.Fiber._doRun(Fiber.java:910)<br /> at com.sun.xml.ws.api.pipe.Fiber.doRun(Fiber.java:873)<br /> at com.sun.xml.ws.api.pipe.Fiber.runSync(Fiber.java:775)<br /> at com.sun.xml.ws.server.WSEndpointImpl$2.process(WSEndpointImpl.java:386)<br /> at com.sun.xml.ws.transport.http.HttpAdapter$HttpToolkit.handle(HttpAdapter.java:640)<br /> at com.sun.xml.ws.transport.http.HttpAdapter.handle(HttpAdapter.java:263)<br /> at com.sun.xml.ws.transport.http.servlet.ServletAdapter.handle(ServletAdapter.java:163)<br /> at org.glassfish.webservices.JAXWSServlet.doPost(JAXWSServlet.java:145)<br /> at javax.servlet.http.HttpServlet.service(HttpServlet.java:688)<br /> at javax.servlet.http.HttpServlet.service(HttpServlet.java:770)<br /> at org.apache.catalina.core.StandardWrapper.service(StandardWrapper.java:1542)<br /> at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:281)<br /> at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)<br /> at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:655)<br /> at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:595)<br /> at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:161)<br /> at org.apache.catalina.connector.CoyoteAdapter.doService(CoyoteAdapter.java:331)<br /> at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:231)<br /> at com.sun.enterprise.v3.services.impl.ContainerMapper$AdapterCallable.call(ContainerMapper.java:317)<br /> at com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:195)<br /> at com.sun.grizzly.http.ProcessorTask.invokeAdapter(ProcessorTask.java:849)<br /></i>thierryhttps://www.blogger.com/profile/18142861951104179170noreply@blogger.comtag:blogger.com,1999:blog-30587633.post-70948990474937785022012-08-30T03:41:09.167+05:302012-08-30T03:41:09.167+05:30Man, you are the God, this is so simple but I took...Man, you are the God, this is so simple but I took over 2 hours to get this code to implement my app. A special thanks from Brazil!Rafael Cintrahttps://www.blogger.com/profile/05654599741651097678noreply@blogger.comtag:blogger.com,1999:blog-30587633.post-12202167352894097082012-06-18T15:48:32.558+05:302012-06-18T15:48:32.558+05:30{quote}
This method is great, but what my 'doS...{quote}<br />This method is great, but what my 'doSomeOperation()' method is static. Is there a way to cater for this?<br />{quote}<br /><br />It's just a matter of getting to the right classloader. So instead of this.getClass().getClassLoader(), if the method in which you are using this is static, just use MyPropertiesReader.class.getClassLoader() or a similar technique.Jaikiranhttps://www.blogger.com/profile/08503182723143814781noreply@blogger.comtag:blogger.com,1999:blog-30587633.post-79080116394875091132012-06-18T13:57:47.579+05:302012-06-18T13:57:47.579+05:30This method is great, but what my 'doSomeOpera...This method is great, but what my 'doSomeOperation()' method is static. Is there a way to cater for this?Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-30587633.post-20296276826287793202012-05-18T11:17:42.301+05:302012-05-18T11:17:42.301+05:30The resource should be kept in WEB-INF\classes, NO...The resource should be kept in WEB-INF\classes, NOT inside WEB-INF.Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-30587633.post-16556816202237582592011-11-04T15:47:51.278+05:302011-11-04T15:47:51.278+05:30Thanks for the clear explanation. And also thanks ...Thanks for the clear explanation. And also thanks to dracik for the extra info about eclipse and tomcat: exactly what I needed!mathieunoreply@blogger.comtag:blogger.com,1999:blog-30587633.post-47826035124238279032011-11-02T08:12:09.789+05:302011-11-02T08:12:09.789+05:30For portability in webapps, you cant rely on it fi...For portability in webapps, you cant rely on it finding items in the root context. See this stackoverflow post:<br /><br />http://stackoverflow.com/questions/2308188/getresourceasstream-vs-fileinputstream<br /><br />I recommend you consider using servletContext.getResource where possible, as it is guaranteed to be looking relative to your apps context.Toolmanhttps://www.blogger.com/profile/00351556847237003891noreply@blogger.comtag:blogger.com,1999:blog-30587633.post-6830006127480090392010-11-30T22:35:34.120+05:302010-11-30T22:35:34.120+05:30If you are want to load the properties file in a s...If you are want to load the properties file in a static way, use URL instead of 'InputStream'. Please find the code snippet below.<br /><br />URL url = Class_Name.class.getClassLoader().getResource("WEB-INF/property_file_name.properties");<br /> properties = new Properties();<br /> properties.load(url.openStream());Gopinoreply@blogger.comtag:blogger.com,1999:blog-30587633.post-50734394037841911892010-05-01T00:17:25.278+05:302010-05-01T00:17:25.278+05:30You saved me much headache. Plus I also learned s...You saved me much headache. Plus I also learned something. Thanks<br />AnnAnnhttp://www.randrinc.comnoreply@blogger.comtag:blogger.com,1999:blog-30587633.post-58254284619994022302010-04-28T23:56:23.299+05:302010-04-28T23:56:23.299+05:30Wasted a good amount of time before finding your b...Wasted a good amount of time before finding your blog... thanks for the info and people please go through this link http://tomcat.apache.org/tomcat-4.1-doc/class-loader-howto.html to understand the class loading in tomcatAjay Karthiknoreply@blogger.comtag:blogger.com,1999:blog-30587633.post-69766404669792783422010-03-08T00:36:15.736+05:302010-03-08T00:36:15.736+05:30Lavanya,
What does the entire exception stacktrac...Lavanya,<br /><br />What does the entire exception stacktrace look like?Jaikiranhttps://www.blogger.com/profile/08503182723143814781noreply@blogger.comtag:blogger.com,1999:blog-30587633.post-9393173264571830742010-03-04T05:36:20.804+05:302010-03-04T05:36:20.804+05:30I am trying to follow what you're doing here, ...I am trying to follow what you're doing here, but I get a null pointer exception from the load function. I am trying to do this in a jsp.<br /><br />any thoughts on this?Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-30587633.post-20434304903706336522009-12-03T22:03:47.894+05:302009-12-03T22:03:47.894+05:30I am using JDK 1.5 and Tomcat 5.25
I call from a...I am using JDK 1.5 and Tomcat 5.25<br /> <br />I call from a jsp<br />.<br />.<br />import="org.myApp.MyPropertiesReader" <br />.<br />.<br />.<br />.<br /><br /> MyPropertiesReader mp = new MyPropertiesReader();<br /> mp.doSomeOperation();<br /><br /><br />This is the console with the exception<br /><br />INFO: Server startup in 906 ms<br />InputStream is: null<br />03/12/2009 13:27:12 org.apache.catalina.core.StandardWrapperValve invoke<br />GRAVE: Servlet.service() para servlet jsp lanzó excepción<br />java.lang.NullPointerException<br /> at java.util.Properties$LineReader.readLine(Properties.java:365)<br /> at java.util.Properties.load(Properties.java:293)<br /> at org.myApp.MyPropertiesReader.doSomeOperation(MyPropertiesReader.java:39)<br /> at org.apache.jsp.index_jsp._jspService(index_jsp.java:55)<br /><br />========================<br /><br />and I also from a servlet<br /><br /><br />protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {<br /> MyPropertiesReader mp = new MyPropertiesReader();<br /> mp.doSomeOperation();<br /> }<br /><br />This is the console with the exception<br /><br />INFO: Server startup in 907 ms<br />InputStream is: null<br />03/12/2009 13:25:21 org.apache.catalina.core.StandardWrapperValve invoke<br />GRAVE: Servlet.service() para servlet Prueba lanzó excepción<br />java.lang.NullPointerException<br /> at java.util.Properties$LineReader.readLine(Properties.java:365)<br /> at java.util.Properties.load(Properties.java:293)<br /> at org.myApp.MyPropertiesReader.doSomeOperation(MyPropertiesReader.java:39)<br /> at org.servlet.Prueba.doGet(Prueba.java:45)<br /><br />======<br /><br />Please<br />What I am doing wrong?Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-30587633.post-27139931057605740922009-11-15T22:18:29.902+05:302009-11-15T22:18:29.902+05:30I found this worked only when I put the properties...I found this worked only when I put the properties file in the "WEB-INF\classes" folder.<br /><br />It did not work when it was in the WEB-INF directory.<br /><br />I am using NetBeans, JDK 6 and a web service application on Glassfish.Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-30587633.post-10561966962346308392009-10-20T03:47:10.299+05:302009-10-20T03:47:10.299+05:30How about is the method is static method that retu...How about is the method is static method that returns property value ? In that you can not instantiate some thing like this.class.<br /><br />For example in my case I have utility method,<br /><br />public static String getPropertyValue(String name){<br /> Properties properties = new Properties();<br /> <br /> try {<br />//This is not working properties.load(new FileInputStream("/webapps/DayParser/enviornment.properties"));<br /> return properties.getProperty(name);<br /> } catch (FileNotFoundException e) {<br /> // TODO Auto-generated catch block<br /> e.printStackTrace();<br /> } catch (IOException e) {<br /> // TODO Auto-generated catch block<br /> e.printStackTrace();<br /> }<br /> return null;<br />}Yogihttps://www.blogger.com/profile/13222275932054732457noreply@blogger.comtag:blogger.com,1999:blog-30587633.post-53720441276391822062009-07-25T04:40:19.455+05:302009-07-25T04:40:19.455+05:30Hi Nagaraju,
blogspot.com allows you to create bl...Hi Nagaraju,<br /><br />blogspot.com allows you to create blogs of your own. There are other services like wordpress.com too which allow you to create blogs for free.<br /><br />On the top right corner of my blogspot, you will find a "Create Blog" link. Just click on that link and follow the instructions.Jaikiranhttps://www.blogger.com/profile/08503182723143814781noreply@blogger.comtag:blogger.com,1999:blog-30587633.post-70955947169856044782009-07-22T19:27:35.880+05:302009-07-22T19:27:35.880+05:30Hi jaikiran My Name is nagaraju. i am also a java/...Hi jaikiran My Name is <b>nagaraju</b>. i am also a <b>java/j2ee</b> developer. i would like to create one blog like u, can u tell me how did u create u r blog. plz.............I am so impressed for u r blog.Nagarajuhttps://www.blogger.com/profile/14880473510259013140noreply@blogger.comtag:blogger.com,1999:blog-30587633.post-8729365028673635852009-07-10T12:35:44.354+05:302009-07-10T12:35:44.354+05:30You can even use it without explicitly calling the...You can even use it without explicitly calling the getClassLoader()<br /><br />InputStream is = getClass().getResourceAsStream("/init.properties");<br /><br />Make sure you take note of the "/" at the begining. The "/init.properties" needs to be in the WEB-INF/classes folderUnknownhttps://www.blogger.com/profile/06583858400516524613noreply@blogger.comtag:blogger.com,1999:blog-30587633.post-82500474612983536382009-05-31T06:22:03.106+05:302009-05-31T06:22:03.106+05:30Thank you, I had to change an application that som...Thank you, I had to change an application that someone else had written and had never used a properties file before (or maybe I just forgot). After banging my head against the wall decided to search and found your info. thanks very much. AnnAnonymousnoreply@blogger.comtag:blogger.com,1999:blog-30587633.post-44944630098278085462009-05-25T18:04:48.599+05:302009-05-25T18:04:48.599+05:30This comment has been removed by the author.Anonymousnoreply@blogger.com