Sharing config with another tomcat app

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
11 messages Options
Reply | Threaded
Open this post in threaded view
|

Sharing config with another tomcat app

Brent Wheeldon
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
Reply | Threaded
Open this post in threaded view
|

Re: Sharing config with another tomcat app

Eric West
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 <[hidden email]> wrote:
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

Reply | Threaded
Open this post in threaded view
|

Re: Sharing config with another tomcat app

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


On Thu, Aug 22, 2013 at 10:52 PM, Eric West <[hidden email]> wrote:
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 <[hidden email]> wrote:
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




--
Doug Hathaway
(407) 680-3631
Reply | Threaded
Open this post in threaded view
|

Re: Sharing config with another tomcat app

mkristian
In reply to this post by Brent Wheeldon
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 <[hidden email]> schrieb:
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

--
Diese Nachricht wurde von meinem Android-Mobiltelefon mit K-9 Mail gesendet.
Reply | Threaded
Open this post in threaded view
|

Re: Sharing config with another tomcat app

Robert Klemme-2
In reply to this post by Brent Wheeldon



On Fri, Aug 23, 2013 at 1:27 AM, Brent Wheeldon <[hidden email]> wrote:
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.

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

--
remember.guy do |as, often| as.you_can - without end
http://blog.rubybestpractices.com/
Reply | Threaded
Open this post in threaded view
|

Re: Sharing config with another tomcat app

Brent Wheeldon
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


On 23 August 2013 05:56, Robert Klemme <[hidden email]> wrote:



On Fri, Aug 23, 2013 at 1:27 AM, Brent Wheeldon <[hidden email]> wrote:
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.

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

--
remember.guy do |as, often| as.you_can - without end
http://blog.rubybestpractices.com/

Reply | Threaded
Open this post in threaded view
|

Re: Sharing config with another tomcat app

Karol Bucek

 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 <[hidden email]> 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.

Thanks!

Brent


On 23 August 2013 05:56, Robert Klemme <[hidden email]> wrote:



On Fri, Aug 23, 2013 at 1:27 AM, Brent Wheeldon <[hidden email]> wrote:
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.

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

--
remember.guy do |as, often| as.you_can - without end
http://blog.rubybestpractices.com/


Reply | Threaded
Open this post in threaded view
|

Re: Sharing config with another tomcat app

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


On Friday, August 23, 2013, Karol Bucek wrote:

 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 <<a href="javascript:_e({}, &#39;cvml&#39;, &#39;bwheeldon@pivotallabs.com&#39;);" target="_blank">bwheeldon@...> 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.

Thanks!

Brent


On 23 August 2013 05:56, Robert Klemme <<a href="javascript:_e({}, &#39;cvml&#39;, &#39;shortcutter@googlemail.com&#39;);" target="_blank">shortcutter@...> wrote:



On Fri, Aug 23, 2013 at 1:27 AM, Brent Wheeldon <<a href="javascript:_e({}, &#39;cvml&#39;, &#39;bwheeldon@pivotallabs.com&#39;);" target="_blank">bwheeldon@...> wrote:
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.

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

--
remember.guy do |as, often| as.you_can - without end
http://blog.rubybestpractices.com/


Reply | Threaded
Open this post in threaded view
|

Re: Sharing config with another tomcat app

Robert Klemme-2
In reply to this post by Brent Wheeldon



On Fri, Aug 23, 2013 at 5:15 PM, Brent Wheeldon <[hidden email]> 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


--
remember.guy do |as, often| as.you_can - without end
http://blog.rubybestpractices.com/
Reply | Threaded
Open this post in threaded view
|

Re: Sharing config with another tomcat app

Lenny Marks

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




On Fri, Aug 23, 2013 at 5:15 PM, Brent Wheeldon <[hidden email]> 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

+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



--
remember.guy do |as, often| as.you_can - without end
http://blog.rubybestpractices.com/

Reply | Threaded
Open this post in threaded view
|

Re: Sharing config with another tomcat app

Brent Wheeldon
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!

On Monday, August 26, 2013, Lenny Marks wrote:

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




On Fri, Aug 23, 2013 at 5:15 PM, Brent Wheeldon <<a href="javascript:_e({}, &#39;cvml&#39;, &#39;bwheeldon@pivotallabs.com&#39;);" target="_blank">bwheeldon@...> 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

+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



--
remember.guy do |as, often| as.you_can - without end
http://blog.rubybestpractices.com/