Friday, July 13, 2007

JRuby Goldspike in Context Root

If you're using JRuby's Goldspike plugin to create a WAR for deployment, you might discover that rake war:standalone:run puts the application into a named context (e.g. http://localhost:8080/myapplication). Since most Ruby applications run at the root, this might disrupt your application if it wasn't built to handle a changing path (or your remote tests, which might have the same problem).

Fortunately, it's very easy to modify Goldspike to use the root:

  1. Open vendor/plugins/goldspike/lib/run.rb
  2. Find the WebAppContext definition
  3. Adjust the second argument from
    <Arg>/<%= config.name %></Arg>
    to:
    <Arg>/</Arg>
You're done. When Jetty boots up, you'll see something like "NO JSP Support for /, did not ...". The "/" is the context, so you're in good shape.

4 comments:

Anonymous said...

You mention "this might disrupt your application if it wasn't built to handle a changing path"

What do you mean? How could an application be build to handle a changing path?

Geoffrey Wiseman said...

This is where I show my Ruby ignorance; I have no idea how I'd do this in Ruby on Rails.

In Java web applications, your application is aware of the root of its 'context', and if it always forms links in relationship to that context, you can move it around with relative impunity, without breaking the application itself (although you might still break things that rely on knowledge of where the application is).

Anonymous said...

I just found that if you use Rails helpers like link_to, image_tag, form_tag, etc, Rails will handle the path correctly whether you are in webrick or tomcat.

Now, I have to find how to handle path to my images hardcoded in my css...

Carlos said...

Check out this how-to for a different context-root in rails:

http://snippets.dzone.com/posts/show/3758

(you override an action controller method for relative application root)