Forum: JRuby Sharing config with another tomcat app

5a54c9342881a19c3d210f4253d751e8?d=identicon&s=25 Brent Wheeldon (Guest)
on 2013-08-23 01:31
(Received via mailing list)
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
C983ad33b47479f17a28e083e1bb3d8b?d=identicon&s=25 Eric West (edubkendo)
on 2013-08-23 04:54
(Received via mailing list)
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 Wheeldon
A8f7c2b66fafa83e9537c1f82348f11d?d=identicon&s=25 Doug Hathaway (Guest)
on 2013-08-23 05:16
(Received via mailing list)
You could also store the location of the file in an ENV variable, then
load
it based off that location.
6d805f7a9c4079d2abb93d5e0d7ce28c?d=identicon&s=25 Christian Meier (Guest)
on 2013-08-23 09:07
(Received via mailing list)
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 Wheeldon <bwheeldon@pivotallabs.com> schrieb:
E0d864d9677f3c1482a20152b7cac0e2?d=identicon&s=25 Robert Klemme (robert_k78)
on 2013-08-23 12:00
(Received via mailing list)
On Fri, Aug 23, 2013 at 1:27 AM, Brent Wheeldon
<bwheeldon@pivotallabs.com>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-load...

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
5a54c9342881a19c3d210f4253d751e8?d=identicon&s=25 Brent Wheeldon (Guest)
on 2013-08-23 17:23
(Received via mailing list)
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
Caa2df9372ffa0a9e95b2bab1e8fea34?d=identicon&s=25 Karol Bucek (Guest)
on 2013-08-23 18:43
(Received via mailing list)
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 Wheeldon
5a54c9342881a19c3d210f4253d751e8?d=identicon&s=25 Brent Wheeldon (Guest)
on 2013-08-23 18:54
(Received via mailing list)
Yeah, it's not actually a DB in the traditional sense. It's a
proprietary
service we connect to.
E0d864d9677f3c1482a20152b7cac0e2?d=identicon&s=25 Robert Klemme (robert_k78)
on 2013-08-24 12:17
(Received via mailing list)
On Fri, Aug 23, 2013 at 5:15 PM, Brent Wheeldon
<bwheeldon@pivotallabs.com>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
54568ee7ba0c78a836e84c8756a3d681?d=identicon&s=25 Lenny Marks (Guest)
on 2013-08-26 17:04
(Received via mailing list)
On Aug 24, 2013, at 6:14 AM, Robert Klemme 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
5a54c9342881a19c3d210f4253d751e8?d=identicon&s=25 Brent Wheeldon (Guest)
on 2013-08-26 17:45
(Received via mailing list)
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!
This topic is locked and can not be replied to.