Skip to content

Instantly share code, notes, and snippets.

@nicksieger
Created September 1, 2009 17:08
Show Gist options
  • Save nicksieger/179227 to your computer and use it in GitHub Desktop.
Save nicksieger/179227 to your computer and use it in GitHub Desktop.

Here are the basic steps to create a war file from a Rails application. This is what Warbler does.

  1. Make a staging directory to create the structure, and make a WEB-INF directory in side of that.

  2. Copy your application code into the WEB-INF directory.

    %w(app config lib vendor).each {|d| cp_r d, web_inf_dir }

  3. Copy your public assets into the root of the staging directory.

    FileList["public/**/*"].each {|f| cp f, File.join(staging_dir, f.sub(%r{public/}, '')) }

swap directories inside the war

  1. Create a WEB-INF/web.xml file. Example contents follows.

  2. Copy the jruby-core and jruby-stdlib jars from the jruby-jars gem into WEB-INF/lib.

  3. Copy the jruby-rack jar into WEB-INF/lib.

  4. Jar the whole thing up.

    jar cf myapp.war -C staging_dir .

There are details around configuring gems, customizing web.xml, and specifying additional libraries in the war file, and Warbler's configuration helps with that.

<!DOCTYPE web-app PUBLIC
"-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
"http://java.sun.com/dtd/web-app_2_3.dtd">
<web-app>
<context-param>
<param-name>rails.env</param-name>
<param-value>production</param-value>
</context-param>
<context-param>
<param-name>public.root</param-name>
<param-value>/</param-value>
</context-param>
<context-param>
<param-name>jruby.max.runtimes</param-name>
<param-value>1</param-value>
</context-param>
<context-param>
<param-name>jruby.min.runtimes</param-name>
<param-value>1</param-value>
</context-param>
<filter>
<filter-name>RackFilter</filter-name>
<filter-class>org.jruby.rack.RackFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>RackFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<listener>
<listener-class>org.jruby.rack.rails.RailsServletContextListener</listener-class>
</listener>
</web-app>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment