tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Harry Metske <harry.met...@gmail.com>
Subject Re: loading properties file from WEB-INF instead of WEB-INF/classes
Date Sun, 18 Apr 2010 17:32:41 GMT
2010/4/17 Thufir <hawat.thufir@gmail.com>

> getPropsFromWebINF works so long as the properties file is within the
> package of
> the class (/.  However, I'd like to put the properties file under WEB-INF:
>


>    public void getPropsFromWebINF() throws IOException {
>        Properties p = new Properties();
>        InputStream is;
>        is = getClass().getResourceAsStream("sqljdbc4.properties");
>        p.load(is);
>        log(p.toString());
>    }
>

Class.getResourceAsStream() will delegate to the classloader to find the
resource (searches the classpath) , see
http://java.sun.com/javase/6/docs/api/java/lang/Class.html#getResourceAsStream(java.lang.String)
The tomcat site has an excellent description of Tomcat's classloading :
http://tomcat.apache.org/tomcat-6.0-doc/class-loader-howto.html , this
should bring you to the conclusion that the above won't work.
You should put your sqljdbc4.properties file in WEB-INF/classes, or in
WEB-INF/lib if packaged in a jar file.
If you reference it from your application, make sure you prepend a "/" (or
it will search in your servlet's package) .



I've seen mention of using:
>
> System.getenv("APP_PROPERTIES");
>
> in conjunction with a context (context.xml under META-INF) along the lines
> of:
>
> <?xml version="1.0" encoding="UTF-8"?>
> <Context antiJARLocking="true" path="/A00720398sat">
>    <Environment name="APP_PROPERTIES"
>                 description="The APP Properties File" override="false"
>                 type="java.lang.String"
>                 value="/WEB-INF/app.properties" />
> </Context>
>
>
> however, I'm not able to get the environment, I just get a null value.
>
>
can you be a bit more specific where you get a null value (show some lines
of code)...
although the above won't bring you to the content of the property file, you
only have defined a key/value pair.


regards,
Harry


> What's the correct, and simple, idiom?  (Staying away from jndi and dbcp
> for
> now, and, oddly enough, servlets in this case.)
>
>
>
> Actually, I suppose in a sense it's in WEB-INF:
>
> dtc01l0376-06:~ a00720398$
> dtc01l0376-06:~ a00720398$ jar -tfv
> NetBeansProjects/A00720398sat/dist/A00720398sat.war | grep sql
>   498 Sat Apr 17 14:36:14 PDT 2010
> WEB-INF/classes/controller/sqljdbc4.properties
>
>
>
> however, I'd like to move it from WEB-INF/classes up to just WEB-INF.
>
>
>
> thanks,
>
> Thufir
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org
>
>

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message