# AOT compile rails apps

**URL:** <https://www.ruby-forum.com/t/aot-compile-rails-apps/150914>\
**Category:** JRuby\
**Created:** [October 14, 2008, 10:08pm UTC](https://www.ruby-forum.com/t/aot-compile-rails-apps/150914 "2008-10-14T22:08:17Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![sam](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/5f9b8f/32.png) [@sam](https://www.ruby-forum.com/u/sam)\
**Post date:** [October 14, 2008, 10:08pm UTC](https://www.ruby-forum.com/t/aot-compile-rails-apps/150914/1 "2008-10-14T22:08:17Z")

</div>

Hi,  
I got a question regarding jruby’s aot compile feature. Is it possible  
to ship an obfuscated rails app with it?

I tried compiling only my controllers but I get an error regarding  
Invalid characters (see stacktrace).

Does someone know how to start an obfuscated rails app or can provide  
a tutorial? At least ThoughtWorks mingle is shiping as obfuscated  
project so it should be possible.

Thanks  
Sam

First stacktrace

mb-2:jrubyc -p “” controllers/  
Compiling all in ‘/Users/main/repositories/testapp/trunk/app/  
controllers’…  
Compiling controllers//activities\_controller.rb to class controllers/  
activities\_controller  
Compiling controllers//application.rb to class controllers/application  
…  
…  
…

mb-2:cd controllers/  
mb-2:controllers main$ ls -d _.class | sed 's/(._).class$/mv “&”  
“\1.rb”/’ | sh  
mb-2:controllers main$ cd …/…/  
mb-2:trunk main$ jruby -S script/server  
=\> Booting Mongrel (use ‘script/server webrick’ to force WEBrick)  
=\> Rails 2.1.0 application starting on [http://0.0.0.0:3000](http://0.0.0.0:3000)  
=\> Call with -d to detach  
=\> Ctrl-C to shutdown server  
\*\* Starting Mongrel listening at 0.0.0.0:3000  
\*\* Starting Rails with development environment…  
Exiting  
/Users/main/repositories/testapp/trunk/app/controllers/application.rb:  
215: /Users/main/repositories/testapp/trunk/app/controllers/  
application.rb:1: Invalid char `\276' ('?') in expression (SyntaxError) from /Users/main/repositories/testapp/trunk/app/controllers/ application.rb:215:in `load’  
from /Users/main/repositories/testapp/trunk/vendor/rails/  
activesupport/lib/active\_support/dependencies.rb:215:in `load_file' from /Users/main/repositories/testapp/trunk/vendor/rails/ activesupport/lib/active_support/dependencies.rb:354:in `new\_constants\_in’  
from /Users/main/repositories/testapp/trunk/vendor/rails/  
activesupport/lib/active\_support/dependencies.rb:214:in `load_file' from /Users/main/repositories/testapp/trunk/vendor/rails/ activesupport/lib/active_support/dependencies.rb:95:in `require\_or\_load’  
from /Users/main/repositories/testapp/trunk/vendor/rails/  
activesupport/lib/active\_support/dependencies.rb:60:in `depend_on' from /Users/main/repositories/testapp/trunk/vendor/rails/ activesupport/lib/active_support/dependencies.rb:456:in `require\_dependency’  
from /Users/main/repositories/testapp/trunk/vendor/rails/actionpack/  
lib/action\_controller/dispatcher.rb:18:in `define_dispatcher_callbacks' ... 38 levels... from /Users/main/repositories/testapp/trunk/vendor/rails/railties/lib/ commands/server.rb:27:in `require’  
from /opt/local/share/java/jruby/lib/ruby/site\_ruby/1.8/rubygems/  
custom\_require.rb:27:in `require’  
from script/server:3  
mb-2:trunk main$

second stacktrace

mb-2:trunk main$ java -cp .:/Users/main/Desktop/test/WEB-INF/lib/jruby-  
complete-1.1.4.jar script/server  
Exception in thread “main” /Users/main/repositories/testapp/trunk/  
vendor/rails/activesupport/lib/active\_support/vendor.rb:2:in  
`require': no such file to load -- rubygems (LoadError) from /Users/main/repositories/testapp/trunk/vendor/rails/ activesupport/lib/active_support/vendor.rb:2 from /Users/main/repositories/testapp/trunk/vendor/rails/ activesupport/lib/active_support/vendor.rb:26:in `require’  
from /Users/main/repositories/testapp/trunk/vendor/rails/  
activesupport/lib/active\_support.rb:26  
from /Users/main/repositories/testapp/trunk/vendor/rails/  
activesupport/lib/active\_support.rb:1:in `require' from /Users/main/repositories/testapp/trunk/vendor/rails/railties/lib/ commands/server.rb:1 from /Users/main/repositories/testapp/trunk/vendor/rails/railties/lib/ commands/server.rb:3:in `require’  
from script/server:3  
…internal jruby stack elided…  
from Kernel.require(/Users/main/repositories/testapp/trunk/vendor/  
rails/activesupport/lib/active\_support/vendor.rb:2)  
from (unknown).(unknown)(/Users/main/repositories/testapp/trunk/  
vendor/rails/activesupport/lib/active\_support/vendor.rb:26)  
from Kernel.require(/Users/main/repositories/testapp/trunk/vendor/  
rails/activesupport/lib/active\_support.rb:26)  
from (unknown).(unknown)(/Users/main/repositories/testapp/trunk/  
vendor/rails/activesupport/lib/active\_support.rb:1)  
from Kernel.require(/Users/main/repositories/testapp/trunk/vendor/  
rails/railties/lib/commands/server.rb:1)  
from (unknown).(unknown)(/Users/main/repositories/testapp/trunk/  
vendor/rails/railties/lib/commands/server.rb:3)  
from Kernel.require(script/server:3)  
from (unknown).(unknown)(:1)

---

<div class="post-metadata">

**Author:** ![sam](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/5f9b8f/32.png) [@sam](https://www.ruby-forum.com/u/sam)\
**Post date:** [October 14, 2008, 11:05pm UTC](https://www.ruby-forum.com/t/aot-compile-rails-apps/150914/2 "2008-10-14T23:05:47Z")

</div>

Hi Sam. There’s more on this topic on this thread:  
[http://jruby.markmail.org/search/?q=manalang&x=0&y=0#query:manalang+page:1+mid:tyrnpi6h62342rhi+state:results](http://jruby.markmail.org/search/?q=manalang&x=0&y=0#query:manalang+page:1+mid:tyrnpi6h62342rhi+state:results)

The answer is yes, you can compile your rails app (I’ve tested with the  
app/  
and lib/ directories fully compiled using jrubyc). You will need to  
patch  
ActiveSupport to get it to work though.

As far as obfuscation goes, I don’t know what TW is using to obfuscate  
their  
code (I think it’s something they wrote themselves).

Rich

---

<div class="post-metadata">

**Author:** ![sam](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/5f9b8f/32.png) [@sam](https://www.ruby-forum.com/u/sam)\
**Post date:** [October 15, 2008, 2:24am UTC](https://www.ruby-forum.com/t/aot-compile-rails-apps/150914/3 "2008-10-15T02:24:24Z")

</div>

Rich M. wrote:

> Hi Sam. There’s more on this topic on this thread:  
> [http://jruby.markmail.org/search/?q=manalang&x=0&y=0#query:manalang+page:1+mid:tyrnpi6h62342rhi+state:results](http://jruby.markmail.org/search/?q=manalang&x=0&y=0#query:manalang+page:1+mid:tyrnpi6h62342rhi+state:results)  
> [http://jruby.markmail.org/search/?q=manalang&x=0&y=0#query:manalang+page:1+mid:tyrnpi6h62342rhi+state:results](http://jruby.markmail.org/search/?q=manalang&x=0&y=0#query:manalang+page:1+mid:tyrnpi6h62342rhi+state:results)
> 
> The answer is yes, you can compile your rails app (I’ve tested with the  
> app/ and lib/ directories fully compiled using jrubyc). You will need  
> to patch ActiveSupport to get it to work though.

I’m going to comment on that in the recent thread, but I think we should  
fix load to look for .class files as well.

> As far as obfuscation goes, I don’t know what TW is using to obfuscate  
> their code (I think it’s something they wrote themselves).

I believe TW ships a special LoadService (the logic behind require and  
load) that decrypts their encrypted .rb source files.

- Charlie

* * *

To unsubscribe from this list, please visit:

```
http://xircles.codehaus.org/manage_email

```
