How to compile assets from within exploded war?

We are trying to move asset compilation step to deployment, after the
is exploded on deployment, but before the application starts. Our
is a Rails 3.2.10 app on JRuby 1.7.1, includes turbo-sprockets-rails3
packaged as war under Jetty.

I have a vendor bundle directory with all my gems in the war. I figured
could invoke the assets using java, passing the jruby-complete jar as an
argument. The process finds gem dependencies and rails will start, but
rake task fails because rake/file_utils.rb tries to invoke my args as a
shell argument. I think the issue is that it interpets the path to jruby
with the “file:/” prefix. And if one was to try to invoke a binary with
that prefix, it will simply fail.

Has anyone tried to compile assets while in a war structure using jruby


#invoked from a bash script during the deploy process but before Jetty
starts up.
#APP_ROOT_DIR is the root of the war file
export GEM_HOME=$APP_ROOT_DIR/WEB-INF/vendor/bundle/jruby/1.9
export BUNDLE_WITHOUT=“development:test”
export RAILS_ENV=production

java -jar lib/jruby-complete-1.7.1.jar -S
$APP_ROOT_DIR/WEB-INF/vendor/bundle/jruby/1.9/bin/rake --trace


starting asset compilation…
Booted rails in 3.153
Included bundled gems in 5.32
** Invoke assets:precompile (first_time)
** Execute assets:precompile
assets:precompile:all RAILS_ENV=production RAILS_GROUPS=assets --trace
rake aborted!
Command failed with status (127):

Thanks for any info you can provide. We have no issue compiling assets
during our build.
NOTE: I don’t have rvm on the server (wish I did).


That doesn’t work very well if you don’t know which env the war is going
to be deployed to eg: stage or prod. The different envs will often have
different asset host.

Why not precompile the assets before packaging up the war file? That
would be much safer and standard.

However, if you really need to do it at deploy time then you should
check out this pull request to warbler and see if it works for you:

The wabler-exec gem might be of help:, depending on where you want the
compiled assets to be deployed. You might have to hack it a little since
in the current state it just takes the war and unpacks it to a different
path, but in general, there’s no reason why it shouldn’t be possible to
feed it the path to an unpacked war as an option.


On Jan 25, 2013, at 5:57 PM, Patrick R. wrote:

out this pull request to warbler and see if it works for you:

java -jar lib/jruby-complete-1.7.1.jar -S
** Execute assets:precompile

To unsubscribe from this list, please visit:

Felix Gilcher

m. +49 172 840 88 28

asquera GmbH
Ohlauer Strae 43
D-10999 Berlin

AG Charlottenburg, HRB 140808 B
Geschftsfhrung: Felix Gilcher, Florian G.

That doesn’t address the issue where you have different asset hosts on
each env.


You can make the precompiled assets relative which will allow them to
work in any environment by doing something like this:

I run rake assets:precompile and then I run assets:relativize and then
when I package my war file it will work for whatever path you put it

I think the way I would do that would be to just build the war for
staging and build the war for production separately.

You should make the asset host configurable using an environment
variable or a system property or use another mode of deployment that
doesn’t use wars.

Wars are not really meant to be changed or partially deployed.


That could work, but asset pre-compilation is expensive. Our build
currently generate the war on every commit to master, compiling the
twice (once for test and once for stage) would add significant time to
build process.

What we are trying to do is disconnect asset compilation from the war
move it elsewhere in our deploy process.

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs