RE: R: properties files
thanks :) i noticed that the servlet context isnt available also ... but if i put the properties file inside the WEB-INF/lib, what's it's path ? -Mensagem original- De: Erik Price [mailto:[EMAIL PROTECTED] Enviada: terca-feira, 25 de Fevereiro de 2003 20:12 Para: Tomcat Users List Assunto: Re: R: properties files Simone Chiaretta wrote: I store properties in my the app WEB-INF/web.xml context-param param-namesmtpServer/param-name param-valuemy.smtpserver.net/param-value descriptionSMTP server to be used to send email from forms in the website/description /context-param and I access the value also in JSP pages with String value = getServletContext().getInitParameter(smtpServer); and I assure u that it works even with JSP not only with servlet, Because JSPs are servlets. but I never tryed accessing it from inside a bean. Because you can't, unless you pass the data to the bean somehow (via constructor or method arg) then it has no knowledge of the ServletContext. To the OP: just use the Properties file from the JavaBean the way you would normally in a non-webapp Java application. To be visible to the Tomcat classloader, put your Properties file in WEB-INF/classes or jar it up and put it in WEB-INF/lib. Erik - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: R: properties files
Jose Moreira wrote: thanks :) i noticed that the servlet context isnt available also ... but if i put the properties file inside the WEB-INF/lib, what's it's path ? If the properties file is in WEB-INF/lib, then it must be in a JAR file. The technique for accessing a properties file from a JAR file is something like this (could be a little wrong): String propertyPath = jar:/path/to/jarfile.jar!/path/to/properties; InputStream in = this.getClassLoader().getResourceAsStream(propertyPath); Properties p = new Properties(); p.load(in); The problem here is that this requires you to know the absolute path to the JAR file, which I do not know if it is possible for a webapp to give you the absolute path. However, it must be possible because I believe log4j uses properties files from JAR files in webapps. So, you might want to ask around there or check the log4j source code. Please let us know what you find! Erik - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: R: properties files
Erik Price wrote: However, it must be possible because I believe log4j uses properties files from JAR files in webapps. So, you might want to ask around there or check the log4j source code. Please let us know what you find! Responding to my own post, I took a look at the Log4J source and it /appears/ that Log4J does exactly what you described earlier -- it queries the class loader for the specified resource and then returns the URL of that resource. classLoader = getTCL(); if(classLoader != null) { LogLog.debug(Trying to find [+resource+] using context classloader +classLoader+.); url = classLoader.getResource(resource); if(url != null) { return url; } } The code that I am referring to is viewable at this URL: http://cvs.apache.org/viewcvs/jakarta-log4j/src/java/org/apache/log4j/helpers/Loader.java?rev=1.18content-type=text/vnd.viewcvs-markup Erik - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
R: properties files
Excuse me for the question but cannot u store directly the properties (strings, integer and so on) in the web.xml for the application or the server.xml under Resource - Simone Chiaretta www.piyosailing.com/S Any sufficiently advanced technology is indistinguishable from magic -Messaggio originale- Da: José Moreira [mailto:[EMAIL PROTECTED] Inviato: martedì 25 febbraio 2003 13.36 A: Tomcat Users List Oggetto: properties files Hello, im using a propeties file to store and retrieve application settings (like db conection) using this code : private Properties properties; private String status; private boolean NovoConfig; /** Creates new ConfigReaderBean */ public ConfigReaderBean() { Properties properties = new Properties(); NovoConfig = false; try { properties.load(new FileInputStream(config.properties)); } catch (IOException e) { System.out.println(Erro ao ler config: +e.getMessage()); properties.setProperty(database.url,http://localhost/mysql;); NovoConfig = true; } if (NovoConfig) { try { properties.store(new FileOutputStream(newconfig.properties),null); System.out.println(Criado: newconfig.properties); } catch (IOException e) { System.out.println(Erro ao criar novo config: +e.getMessage()); } } the problem is that it doesnt load the file and saves the 'newconfig.properties' file under the Netbeans IDE dir, how can i load the file located under my webapp WEB-INF dir ? ---*-- José Moreira Técnico de Informática | IT Technician Vila Nova de Gaia, Portugal E-Mail: [EMAIL PROTECTED] MSN: [EMAIL PROTECTED] ICQ: 136936120 IRC: ethernal (irc.ptnet.org) - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
R: properties files
I store properties in my the app WEB-INF/web.xml context-param param-namesmtpServer/param-name param-valuemy.smtpserver.net/param-value descriptionSMTP server to be used to send email from forms in the website/description /context-param and I access the value also in JSP pages with String value = getServletContext().getInitParameter(smtpServer); and I assure u that it works even with JSP not only with servlet, but I never tryed accessing it from inside a bean. The only problem is that when you change the value you have to reload the application.. hope that helps Simo -Messaggio originale- Da: José Moreira [mailto:[EMAIL PROTECTED] Inviato: martedì 25 febbraio 2003 15.25 A: Tomcat Users List; [EMAIL PROTECTED] Oggetto: RE: properties files thank you for the attention, im developing a bean to interact with the properties file. I believe that ServletContext is only available to servlets, but perhaps the filename can be a parameter in the constructor :D the reason why im using a properties file is to make the configuration transparent and easy, to my clients... so i they change the mysql db parameters they can easily edit the properties file without much knowledge. also another advantage i saw in that was the ability to load and save directly to a file. if there is a better way im all ears :) -Mensagem original- De: Arnaud HERITIER [mailto:[EMAIL PROTECTED] Enviada: terça-feira, 25 de Fevereiro de 2003 12:51 Para: 'Tomcat Users List' Assunto: RE: properties files You need to put your property files in WEB-INF/classes or in a jar in WEB-INF/lib Then you can use the getResourceAsStream(..) method of the ServletContext of your webapp : properties.load(getServletContext().getResourceAsStream(filePath)) Arnaud -Message d'origine- De : José Moreira [mailto:[EMAIL PROTECTED] Envoyé : mardi 25 février 2003 13:36 À : Tomcat Users List Objet : properties files Hello, im using a propeties file to store and retrieve application settings (like db conection) using this code : private Properties properties; private String status; private boolean NovoConfig; /** Creates new ConfigReaderBean */ public ConfigReaderBean() { Properties properties = new Properties(); NovoConfig = false; try { properties.load(new FileInputStream(config.properties)); } catch (IOException e) { System.out.println(Erro ao ler config: +e.getMessage()); properties.setProperty(database.url,http://localhost/mysql;); NovoConfig = true; } if (NovoConfig) { try { properties.store(new FileOutputStream(newconfig.properties),null); System.out.println(Criado: newconfig.properties); } catch (IOException e) { System.out.println(Erro ao criar novo config: +e.getMessage()); } } the problem is that it doesnt load the file and saves the 'newconfig.properties' file under the Netbeans IDE dir, how can i load the file located under my webapp WEB-INF dir ? ---*-- José Moreira Técnico de Informática | IT Technician Vila Nova de Gaia, Portugal E-Mail: [EMAIL PROTECTED] MSN: [EMAIL PROTECTED] ICQ: 136936120 IRC: ethernal (irc.ptnet.org) - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: R: properties files
Simone Chiaretta wrote: I store properties in my the app WEB-INF/web.xml context-param param-namesmtpServer/param-name param-valuemy.smtpserver.net/param-value descriptionSMTP server to be used to send email from forms in the website/description /context-param and I access the value also in JSP pages with String value = getServletContext().getInitParameter(smtpServer); and I assure u that it works even with JSP not only with servlet, Because JSPs are servlets. but I never tryed accessing it from inside a bean. Because you can't, unless you pass the data to the bean somehow (via constructor or method arg) then it has no knowledge of the ServletContext. To the OP: just use the Properties file from the JavaBean the way you would normally in a non-webapp Java application. To be visible to the Tomcat classloader, put your Properties file in WEB-INF/classes or jar it up and put it in WEB-INF/lib. Erik - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]