See at the end for a truly spectacularly bad potential solution. Note
that I have not tried this, so your mileage may vary.
On 12/8/2012 11:51 AM, vicky wrote:
Thanks Mark for your valuable suggestions.
But in my project i have a requirement to share one
"resource/properties file " across 10 applications deployed on single
tomcat instance
We cannot afford to add the same properties file to all archives as
its contents keep changing.
Another restriction which i have is that i cannot place any file
under "$CATALINA_HOME" directories , these are read only for us.
Based on afore said concerns, do you have any better way out ..please
suggest.
Appreciated all of your help
Thanks for ur time Vicky
________________________________ From: Mark Eggers
<its_toas...@yahoo.com> To: Tomcat Users List
<users@tomcat.apache.org> Sent: Sunday, 9 December 2012 12:23 AM
Subject: Re: Tomcat 6.0 CLASSPATH query
Comments inline below (a bit fuzzy from the move yet).
On 12/8/2012 9:58 AM, vicky wrote:
I have read the Tomcat 6.0 classloader documentation(below link),
from this what i understood is that the
"classes/jar/resource/properties file" get loaded from the
following locations
1.Bootstrap classes of your JVM ($JAVA_HOME/jre/lib/ext).
2.System class loader classes ( Add bootstrap.jar &
tomcat-juli.jar to CLASSPATH variable) 3.Common class loader
classes ( refers $CATALINA_BASE/lib & $CATALINA_HOME/lib ) & uses
$CATALINA_BASE/conf/catalina.properties 4. /WEB-INF/classes of
your web application 5. /WEB-INF/lib/*.jar of your web application
The thing which is still puzzling me is that how my
"resource/properties files" get loaded to Tomcat CLASSPATH when i
add them to "$CATALINA_BASE/bin" directory & When i move the same
files to $CATALINA_BASE/conf directory then it doesn't get added to
Tomcat CLASSPATH.
My deployed applications need"properties/resource files ", Can
someone please help me in understand the optimal way of adding
these files to Tomcat CLASSPATH. Does placing the files under
<CATALINA_BASE>/bin is the right approach.Please suggest
Why in the world are you adding these resource files to Tomcat's
CLASSPATH? If the resources are application - specific, you don't
need to do this at all.
Just add the files to your local application. In Maven, there's a
special directory for that:
src/main/resources
In NetBeans, I normally create a separate package for all of my
configuration files.
I think in Eclipse you'll have to make a subdirectory under
WEB-INF/classes and copy the files there. That's unpleasant. Eclipse
will include that in the build of the WAR file when you do an
"export".
Then, just do the following in your code to reference the resource.
InputStream in =
this.getClass().getClassLoader().getResourceAsStream(configfile);
Where configfile is the complete classpath to your resource.
This is nice. It works in exploded WARs, it works in WAR files, it
works in JARs.
No mucking about with CLASSPATH. No polluting other applications or
Tomcat with spurious application - specific resources. This enables
you to run several copies of the same web application in the same
container, all with different configurations.
Just search for getResourceAsStream() for more explanation.
In my organisation i cannot add anything to "$CATALINA_HOME/lib or
bin" location ,these are read only directories
http://tomcat.apache.org/tomcat-6.0-doc/class-loader-howto.html
Thanks for your help Vicky
Not needed.
________________________________ From: Pid * <p...@pidster.com> To:
Tomcat Users List <users@tomcat.apache.org> Sent: Saturday, 8
December 2012 10:34 PM Subject: Re: Tomcat 6.0 CLASSPATH query
On 8 Dec 2012, at 03:29, "vicky007aggar...@yahoo.co.in"
<vicky007aggar...@yahoo.co.in> wrote:
Application is deployed under tomcat webapps directory . It
tries to refer to application specific properties file from
tomcat classpath, for that we copied it under tomcat bin
directory.
My query is that does this is the right way to add properties
file to tomcat classpath?
Did you try putting it in tomcat/lib?
p
Thanks for ur help, Vicky
On Dec 8, 2012, at 2:11 AM, Christopher Schultz
<ch...@christopherschultz.net> wrote:
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA256
Vicky,
On 12/7/12 11:48 AM, vicky wrote:
I have a requirement in which i need to add couple of
properties files to tomcat CLASSPATH as these are needed for
my application deployed in Tomcat 6.0.
One strange thing is that, i need to add the all my
properties files to "<CATALINA_BASE>/bin" directory else
these all wont get added to Tomcat classpath.
Where does the code live that attempts to load those
properties files?
- -chris
. . . just my (I hate moving) 2 cents /mde/
Vicky,
So let me now understand your requirements.
1. Properties files to be read by web applications
2. 10 web applications on one Tomcat instance
3. All 10 web applications read identical files
4. Property files change frequently
5. $CATALINA_HOME and $CATALINA_BASE are read-only
6. $CATALINA_BASE/lib and $CATALINA_BASE/bin are read-only
In the future it would be a good idea to list all of your requirements
and restrictions at once, rather than having the list extract it by
recommending solutions which fail one or more requirements.
The approach (placing resource files on the CLASSPATH) is probably not a
good one given the requirements as you've stated them.
If you're wedded to reading resources from a CLASSPATH, the only
reasonable way to live with the above requirements is to use files in
WEB-INF/classes. Then the application will have to be changed each time
you update the resource files. This all can be scripted so that
operations won't have too big of a burden.
Placing the resources in a JAR somewhere on Tomcat's CLASSPATH poses
several problems.
1. You cannot modify the directories where Tomcat reads JARs
2. A change to the resource will require a Tomcat restart
One of the only ways I can see around this is as follows.
1. create a setenv.sh in $CATALINA_BASE/bin (or setenv.bat)
I realize you do not have write access to this, but maybe operations can
create that file.
2. In that setenv.sh, add the following:
CLASSPATH=/place/where/your/jar/is.jar
EXPORT CLASSPATH
3. Make the /place/where/your/jar/is.jar readable
This JAR file must be readable by the user running Tomcat
4. In is.jar add all your configuration files
This is a pretty spectacularly bad solution for several reasons.
1. You're reading a file outside of Tomcat's directory structure
2. Eunning under the security manager would be challenging
3. Tomcat restart for changing the JAR with the properties files
At this point, I would seriously look at scripting the 10 web
application updates, or loading the properties files in a database and
access them via JNDI.
. . . . just my two cents.
/mde/
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org
For additional commands, e-mail: users-h...@tomcat.apache.org