Sharing config with another tomcat app

Hi there,

I’m working on a jruby on rails application and we need to share a
couple
of very simple config strings between our app, and another (jsp based)
application which is mounted in the same tomcat instance.

We were hoping to place a custom .properties file in tomcat’s conf/
directory and then load that into a java.util.Properties object. We were
thinking we could include a .properties file of the same name in our
rail
app’s lib/ directory so that it’s in the class path and we can load it,
and
then when our war file is mounted in tomcat, tomcat’s conf/ directory
would
be first in the classpath, therefore the properties file there would be
the
one loaded.

However, we’re having a lot problems getting to the .properties file (we
are using getResourceAsStream, but it returns null).

We may well be totally on the wrong track here, so happy to hear
suggestions on different ways of doing this, or quick tips on how to
load a
file based on it’s filename when it’s located somewhere in the
classpath.

Thanks!

Brent

Maybe this won’t work or would be a bad idea for some reason, but since
you
said it was just a couple very simple config strings, what about making
them Env variables?

On Thu, Aug 22, 2013 at 6:27 PM, Brent W.

You could also store the location of the file in an ENV variable, then
load
it based off that location.

On Fri, Aug 23, 2013 at 1:27 AM, Brent W.
[email protected]wrote:

then when our war file is mounted in tomcat, tomcat’s conf/ directory would
be first in the classpath, therefore the properties file there would be the
one loaded.

Web application class paths are insulated from each other in Tomcat for
good reasons. If you want to share this via classpath you should use
class
loader “Common”. See
http://tomcat.apache.org/tomcat-8.0-doc/class-loader-howto.html

However, we’re having a lot problems getting to the .properties file (we

are using getResourceAsStream, but it returns null).

We may well be totally on the wrong track here, so happy to hear
suggestions on different ways of doing this, or quick tips on how to load a
file based on it’s filename when it’s located somewhere in the classpath.

Generally if you need to share things between web applications it may be
a
sign that it’s really just one application.

Kind regards

robert

Thanks for your replies!

The problem we’re trying to solve is to have the host and port of the
database-like data source that our application, and the other jsp
application uses. This will be different environment to environment, so
putting it into the jar file is not an option.

We were hoping to use something a little more first class than
environment
variables, but it seems like that might be our best option.

Thanks!

Brent

Hmm. I feel the property file should be inside a jar file. Then use the
Threat.current thread().getContextClassloader() to load the properties
file. That should be straight forward.

Brent W. [email protected] schrieb:

If they use the same DB than you should definitely consider setting up a
data-source and sharing it (looking it up via JNDI from both apps).

There are possibilities to use this differently based on the server -
but
if you use separate servers and deploy to them you should be all set
this
way.

K.

On Fri, Aug 23, 2013 at 5:15 PM, Brent W.

On Fri, Aug 23, 2013 at 5:15 PM, Brent W.
[email protected]wrote:

Thanks for your replies!

The problem we’re trying to solve is to have the host and port of the
database-like data source that our application, and the other jsp
application uses. This will be different environment to environment, so
putting it into the jar file is not an option.

We were hoping to use something a little more first class than environment
variables, but it seems like that might be our best option.

Why don’t you want to use the “Common” classloader (the one where you’d
put
JDBC drivers as well so all apps could share them)? That should do the
trick for you since you stated already that you want to use
Class.getResourceAsStream(). Or am I missing something?

Cheers

robert

Yeah, it’s not actually a DB in the traditional sense. It’s a
proprietary
service we connect to.

On Aug 24, 2013, at 6:14 AM, Robert K. wrote:

Why don’t you want to use the “Common” classloader (the one where you’d put JDBC
drivers as well so all apps could share them)? That should do the trick for you
since you stated already that you want to use Class.getResourceAsStream(). Or am
I missing something?

Cheers

robert

+1 on what Robert has suggested. We do that all the time. For us, it’s
typical to have some deployment scoped configuration properties that
don’t belong inside the WAR. We want to keep our WAR files self
contained. We often drop a war on a staging Tomcat server configured
against a test database and then drop that same WAR into our production
server once it’s been verified. We consider things like database and web
service URIs “deployment properties” and load them from .properties
files in $CATALINA_HOME/lib.

-lenny

Hi all,

We’ve looked at this with fresh eyes this morning and have got it
working
with the approach Lenny and Robert described.

Thanks for all of your help!