# J2EE equivalent

**URL:** <https://www.ruby-forum.com/t/j2ee-equivalent/51878>\
**Category:** Rails\
**Created:** [January 8, 2006, 5:33pm UTC](https://www.ruby-forum.com/t/j2ee-equivalent/51878 "2006-01-08T17:33:19Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![thila](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/3d9bf3/32.png) [@thila](https://www.ruby-forum.com/u/thila)\
**Post date:** [January 8, 2006, 5:33pm UTC](https://www.ruby-forum.com/t/j2ee-equivalent/51878/1 "2006-01-08T17:33:19Z")

</div>

Gang-

1. Is there anything in Ruby that handles the .properites files similar  
to the J2EE application servers. Or do I need to define all of the  
properties as constants?

2. Is there anyway I can load some of my classes (such as singletons)  
during the startup? I am looking for the startup classes that J2EE  
containers provide.

Thanks

---

<div class="post-metadata">

**Author:** ![thila](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/3d9bf3/32.png) [@thila](https://www.ruby-forum.com/u/thila)\
**Post date:** [January 8, 2006, 7:22pm UTC](https://www.ruby-forum.com/t/j2ee-equivalent/51878/2 "2006-01-08T19:22:46Z")

</div>

1. You can store/access config information in .yml files, similar to  
the way that you configure your database connections in Rails.

2. I’m afraid this question doesn’t make too much sense without  
additional context. Are you referring to shared services of some sort?  
Do you understand the way that Rails processes are “shared-nothing”,  
meaning each would have its own set of “singletons”?

Maybe if you share a little bit more information about what you’re  
trying to accomplish we could give you a better answer?

---

<div class="post-metadata">

**Author:** ![thila](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/3d9bf3/32.png) [@thila](https://www.ruby-forum.com/u/thila)\
**Post date:** [January 8, 2006, 10:40pm UTC](https://www.ruby-forum.com/t/j2ee-equivalent/51878/3 "2006-01-08T22:40:17Z")

</div>

thila thila wrote:

> 1. Is there anyway I can load some of my classes (such as singletons)  
> during the startup? I am looking for the startup classes that J2EE  
> containers provide.

Like Obie said, I think you might be trying to do the Wrong Thing here.  
But any code in e.g. config/environment.rb will be executed as the  
application is being loaded. Try just putting “puts ‘hello world’” in  
the file and starting the WEBrick server. NB: This will happen once (I  
think) when you’re running in WEBrick, but it might happen many times in  
a CGI context - I have not checked. Be careful…

~Johannes

---

<div class="post-metadata">

**Author:** ![thila](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/3d9bf3/32.png) [@thila](https://www.ruby-forum.com/u/thila)\
**Post date:** [January 8, 2006, 11:57pm UTC](https://www.ruby-forum.com/t/j2ee-equivalent/51878/4 "2006-01-08T23:57:34Z")

</div>

On 9/01/2006, at 5:33 AM, thila thila wrote:

> 1. Is there anything in Ruby that handles the .properites files  
> similar  
> to the J2EE application servers. Or do I need to define all of the  
> properties as constants?

You can use YAML to load a config file, but constants in  
environment.rb are fine for basic configuration. If you have a  
complex configuration file you’re probably doing something wrong.

> 1. Is there anyway I can load some of my classes (such as singletons)  
> during the startup? I am looking for the startup classes that J2EE  
> containers provide.

You’re thinking in J2EE application server terms. Rails does not  
provide an application server, it just processes requests as they  
come past. Some state may be maintained in sessions, but there is no  
other preserved state.

As for singletons, Ruby classes are objects, use them. You can also  
check out the singleton mixin at [RDoc Documentation](http://www.ruby-doc.org/stdlib/)  
libdoc/singleton/rdoc/index.html.

–  
Phillip H.  
removed\_email\_address@domain.invalid

---

<div class="post-metadata">

**Author:** ![thila](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/3d9bf3/32.png) [@thila](https://www.ruby-forum.com/u/thila)\
**Post date:** [January 9, 2006, 9:30am UTC](https://www.ruby-forum.com/t/j2ee-equivalent/51878/5 "2006-01-09T09:30:58Z")

</div>

On 1/8/06, thila thila [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Gang-
> 
> 1. Is there anything in Ruby that handles the .properites files similar  
> to the J2EE application servers. Or do I need to define all of the  
> properties as constants?

Let me take this opportunity to shamelessly pimp my own custom solution:

[http://blog.lavalamp.ca/articles/2005/12/30/application-specific-configuration](http://blog.lavalamp.ca/articles/2005/12/30/application-specific-configuration)

-Steven

---

<div class="post-metadata">

**Author:** ![thila](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/3d9bf3/32.png) [@thila](https://www.ruby-forum.com/u/thila)\
**Post date:** [January 9, 2006, 2:02pm UTC](https://www.ruby-forum.com/t/j2ee-equivalent/51878/6 "2006-01-09T14:02:48Z")

</div>

> > 1. Is there anything in Ruby that handles the .properites files  
> > similar  
> > to the J2EE application servers. Or do I need to define all of the  
> > properties as constants?
> 
> You can use YAML to load a config file, but constants in  
> environment.rb are fine for basic configuration. If you have a  
> complex configuration file you’re probably doing something wrong.

I use YAML files as well for configuration. What makes you think that  
a complex configuration file is “the wrong thing”? The application I  
have written runs embedded (a network monitoring tool). There is only  
one user, and there’s a bunch of configuration stuff. The alternative  
would have been to create a database table to hold the configuration  
(which might make sense in a multi user environment). There ARE uses  
where you want complex configurations…

cu jc

---

<div class="post-metadata">

**Author:** ![thila](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/3d9bf3/32.png) [@thila](https://www.ruby-forum.com/u/thila)\
**Post date:** [January 9, 2006, 12:05pm UTC](https://www.ruby-forum.com/t/j2ee-equivalent/51878/7 "2006-01-09T12:05:15Z")

</div>

> 1. Is there anyway I can load some of my classes (such as singletons)  
> during the startup? I am looking for the startup classes that J2EE  
> containers provide.

Hi

could you describe your (functional) goal ? For instance, you may wish  
to  
start background working services (such as a scheduler) at startup ?  
This  
way more people will be likely to answer.

Thibaut
