Forum: JRuby Compiling Rails app/**/* to .class files

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Rich M. (Guest)
on 2008-10-09 22:59
(Received via mailing list)
Does anyone know if compiling rb files to class files using jrubyc works
with Rails?

Rich
Charles Oliver N. (Guest)
on 2008-10-10 10:10
(Received via mailing list)
Rich M. wrote:
> Does anyone know if compiling rb files to class files using jrubyc works
> with Rails?

I believe Peter Chan was doing something with this, and possible Ricardo
Trinidade...you guys out there?

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email
Peter K Chan (Guest)
on 2008-10-10 10:34
(Received via mailing list)
I compiled a subset of Rails, activerecord and activesupport, into java
byte code and found it working very well in my app.

Peter
Rich M. (Guest)
on 2008-10-10 23:01
(Received via mailing list)
Thanks!  I'll create a rake task to compile everything in my app dir and
see
if it works.

Rich
Rich M. (Guest)
on 2008-10-11 00:01
(Received via mailing list)
Did my own test on an existing JRoR app (jrubyc app/) and it didn't
work.
Complained about an application_support dependency.  Looking into it
further.

Peter, did you compile your app source or just the vendor/rails dir?

Rich
Peter K Chan (Guest)
on 2008-10-11 00:32
(Received via mailing list)
Can you post the exact error message?

I haven’t noticed any problem with loading compiled code, compared to
ruby
source. Mixed loading of compiled and plain source also worked. You may
want
to double check to make sure that you have at least something called
application_support.rb or application_support.class (with the
appropriate java
package prefix, if applicable) and that it is inside the loadpath or
classpath.

I just compiled activerecord and activesupport, ensure that the
resulting
files are in classpath, and was able to load them from my application
code.

Peter

From: Rich M. [mailto:removed_email_address@domain.invalid]
Sent: Friday, October 10, 2008 3:01 PM
To: removed_email_address@domain.invalid
Subject: Re: [jruby-user] Compiling Rails app/**/* to .class files

Did my own test on an existing JRoR app (jrubyc app/) and it didn't
work. 
Complained about an application_support dependency.  Looking into it
further.

Peter, did you compile your app source or just the vendor/rails dir?

Rich
On Fri, Oct 10, 2008 at 12:00 PM, Rich M.
<removed_email_address@domain.invalid>
wrote:
Thanks!  I'll create a rake task to compile everything in my app dir and
see
if it works.

Rich

On Thu, Oct 9, 2008 at 11:33 PM, Peter K Chan 
<removed_email_address@domain.invalid> wrote:
I compiled a subset of Rails, activerecord and activesupport, into java
byte
code and found it working very well in my app.

Peter
Rich M. (Guest)
on 2008-10-11 01:03
(Received via mailing list)
Here's what I did:

> jrubyc app/
> jruby script/server  <- rb/class files together... works fine.
> rm `find app/ -name "*.rb"`
> jruby script/server <- class files only... fails with the following error:

=> Booting Mongrel (use 'script/server webrick' to force WEBrick)
=> Rails 2.1.0 application starting on 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...
JRuby limited openssl loaded. gem install jruby-openssl for full
support.
http://wiki.jruby.org/wiki/JRuby_Builtin_OpenSSL
Exiting
/Users/richmanalang/dev/connect.git/vendor/rails/activesupport/lib/active_support/dependencies.rb:512:in
`require': uninitialized constant ApplicationHelper (NameError)
    from
/Users/richmanalang/dev/connect.git/vendor/rails/railties/lib/commands/server.rb:39
    from
/Users/richmanalang/dev/connect.git/vendor/rails/railties/lib/commands/server.rb:27:in
`require'
    from
/Users/richmanalang/lib/jruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:in
`require'
    from script/server:3

Thoughts?

Rich
Peter K Chan (Guest)
on 2008-10-11 01:49
(Received via mailing list)
I don’t use the full Rails framework myself, so I have to defer other
experts
on this subject.

The only thing that I can think of is for you to trace where the error
originates. Figure out what file defines ApplicationHelper and what line
is
loading it, and from that point determine what is not working in loading
the
compiled file.

You may also find it helpful to leave the source file and see if the app
can
pick that up, instead of the compiled version.

Peter

From: Rich M. [mailto:removed_email_address@domain.invalid]
Sent: Friday, October 10, 2008 3:42 PM
To: removed_email_address@domain.invalid
Subject: Re: [jruby-user] Compiling Rails app/**/* to .class files

Here's what I did:

> jrubyc app/
> jruby script/server  <- rb/class files together... works fine.
> rm `find app/ -name "*.rb"`
> jruby script/server <- class files only... fails with the following error:

=> Booting Mongrel (use 'script/server webrick' to force WEBrick)
=> Rails 2.1.0 application starting on 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...
JRuby limited openssl loaded. gem install jruby-openssl for full
support.
http://wiki.jruby.org/wiki/JRuby_Builtin_OpenSSL
Exiting
/Users/richmanalang/dev/connect.git/vendor/rails/activesupport/lib/active_supp
ort/dependencies.rb:512:in `require': uninitialized constant
ApplicationHelper
(NameError)
    from
/Users/richmanalang/dev/connect.git/vendor/rails/railties/lib/commands/server.
rb:39
    from
/Users/richmanalang/dev/connect.git/vendor/rails/railties/lib/commands/server.
rb:27:in `require'
    from
/Users/richmanalang/lib/jruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.r
b:27:in `require'
    from script/server:3

Thoughts?

Rich
On Fri, Oct 10, 2008 at 1:30 PM, Peter K Chan 
<removed_email_address@domain.invalid> wrote:
Can you post the exact error message?

I haven't noticed any problem with loading compiled code, compared to
ruby
source. Mixed loading of compiled and plain source also worked. You may
want
to double check to make sure that you have at least something called
application_support.rb or application_support.class (with the
appropriate java
package prefix, if applicable) and that it is inside the loadpath or
classpath.

I just compiled activerecord and activesupport, ensure that the
resulting
files are in classpath, and was able to load them from my application
code.

Peter

From: Rich M. [mailto:removed_email_address@domain.invalid]
Sent: Friday, October 10, 2008 3:01 PM
To: removed_email_address@domain.invalid
Subject: Re: [jruby-user] Compiling Rails app/**/* to .class files

Did my own test on an existing JRoR app (jrubyc app/) and it didn't
work. 
Complained about an application_support dependency.  Looking into it
further.

Peter, did you compile your app source or just the vendor/rails dir?

Rich
On Fri, Oct 10, 2008 at 12:00 PM, Rich M.
<removed_email_address@domain.invalid>
wrote:
Thanks!  I'll create a rake task to compile everything in my app dir and
see
if it works.

Rich

On Thu, Oct 9, 2008 at 11:33 PM, Peter K Chan 
<removed_email_address@domain.invalid> wrote:
I compiled a subset of Rails, activerecord and activesupport, into java
byte
code and found it working very well in my app.

Peter
Rich M. (Guest)
on 2008-10-11 02:03
(Received via mailing list)
Looks like the dependencies module in active support tries to load
dependencies by appending the .rb to the constant names which is why
it's
failing.  I'm patching these now to see if I can get it to work.

More to come...

Rich
Peter K Chan (Guest)
on 2008-10-11 02:08
(Received via mailing list)
I seem to remember that JRuby automatically handles loading file ending
in .rb
to using the compiled version. But it has been a while (and a few
versions),
so maybe you need to discard the .rb suffix.



Peter



From: Rich M. [mailto:removed_email_address@domain.invalid]
Sent: Friday, October 10, 2008 5:02 PM
To: removed_email_address@domain.invalid
Subject: Re: [jruby-user] Compiling Rails app/**/* to .class files



Looks like the dependencies module in active support tries to load
dependencies by appending the .rb to the constant names which is why
it's
failing.  I'm patching these now to see if I can get it to work.

More to come...

Rich

On Fri, Oct 10, 2008 at 2:48 PM, Peter K Chan 
<removed_email_address@domain.invalid> wrote:

I don't use the full Rails framework myself, so I have to defer other
experts
on this subject.

The only thing that I can think of is for you to trace where the error
originates. Figure out what file defines ApplicationHelper and what line
is
loading it, and from that point determine what is not working in loading
the
compiled file.

You may also find it helpful to leave the source file and see if the app
can
pick that up, instead of the compiled version.


Peter

From: Rich M. [mailto:removed_email_address@domain.invalid]

Sent: Friday, October 10, 2008 3:42 PM

To: removed_email_address@domain.invalid
Subject: Re: [jruby-user] Compiling Rails app/**/* to .class files

Here's what I did:

> jrubyc app/
> jruby script/server  <- rb/class files together... works fine.
> rm `find app/ -name "*.rb"`
> jruby script/server <- class files only... fails with the following error:

=> Booting Mongrel (use 'script/server webrick' to force WEBrick)
=> Rails 2.1.0 application starting on 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...
JRuby limited openssl loaded. gem install jruby-openssl for full
support.
http://wiki.jruby.org/wiki/JRuby_Builtin_OpenSSL
Exiting
/Users/richmanalang/dev/connect.git/vendor/rails/activesupport/lib/active_supp
ort/dependencies.rb:512:in `require': uninitialized constant
ApplicationHelper
(NameError)
    from
/Users/richmanalang/dev/connect.git/vendor/rails/railties/lib/commands/server.
rb:39
    from
/Users/richmanalang/dev/connect.git/vendor/rails/railties/lib/commands/server.
rb:27:in `require'
    from
/Users/richmanalang/lib/jruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.r
b:27:in `require'
    from script/server:3

Thoughts?

Rich
On Fri, Oct 10, 2008 at 1:30 PM, Peter K Chan 
<removed_email_address@domain.invalid> wrote:
Can you post the exact error message?

I haven't noticed any problem with loading compiled code, compared to
ruby
source. Mixed loading of compiled and plain source also worked. You may
want
to double check to make sure that you have at least something called
application_support.rb or application_support.class (with the
appropriate java
package prefix, if applicable) and that it is inside the loadpath or
classpath.

I just compiled activerecord and activesupport, ensure that the
resulting
files are in classpath, and was able to load them from my application
code.

Peter

From: Rich M. [mailto:removed_email_address@domain.invalid]
Sent: Friday, October 10, 2008 3:01 PM
To: removed_email_address@domain.invalid
Subject: Re: [jruby-user] Compiling Rails app/**/* to .class files

Did my own test on an existing JRoR app (jrubyc app/) and it didn't
work.
Complained about an application_support dependency.  Looking into it
further.

Peter, did you compile your app source or just the vendor/rails dir?

Rich
On Fri, Oct 10, 2008 at 12:00 PM, Rich M.
<removed_email_address@domain.invalid>
wrote:
Thanks!  I'll create a rake task to compile everything in my app dir and
see
if it works.

Rich

On Thu, Oct 9, 2008 at 11:33 PM, Peter K Chan 
<removed_email_address@domain.invalid> wrote:
I compiled a subset of Rails, activerecord and activesupport, into java
byte
code and found it working very well in my app.

Peter
Charles Oliver N. (Guest)
on 2008-10-11 02:15
(Received via mailing list)
I'll wait to see from Rich, but you're right, it should try to find both
foo.class and foo.rb (in that order) if you require 'foo.rb', but I'm
not sure whether we made it do that for load or not. I'd have to check
the code, and I'm working on something else at the moment.

Peter K Chan wrote:
> *From:* Rich M. [mailto:removed_email_address@domain.invalid]
> More to come...
> The only thing that I can think of is for you to trace where the error
> From: Rich M. [mailto:removed_email_address@domain.invalid
>  > jruby script/server  <- rb/class files together... works fine.
> JRuby limited openssl loaded. gem install jruby-openssl for full support.
> /Users/richmanalang/dev/connect.git/vendor/rails/railties/lib/commands/server.
> <mailto:removed_email_address@domain.invalid>> wrote:
> I just compiled activerecord and activesupport, ensure that the resulting
> Did my own test on an existing JRoR app (jrubyc app/) and it didn't work.
> if it works.
> -----Original Message-----
>  > with Rails?
>
> ---------------------------------------------------------------------
>    http://xircles.codehaus.org/manage_email
>
>
>


---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email
Rich M. (Guest)
on 2008-10-14 02:12
(Received via mailing list)
Attachment: dependencies.diff (0 Bytes)
Ok... I got it to work (compiled app/ and lib/), but I had to modify
rails/activesupport/lib/active_support/dependencies.rb.  This file loads
all
deps during rails initialization and looks specifically for *.rb files.
I
had to add *.class to the searches.

I've attached the diff.  I'd love for rails to be able to do this
automatically, how would you guys suggest getting this stuff to rails
core?

Rich



On Fri, Oct 10, 2008 at 3:12 PM, Charles Oliver N. <
Rich M. (Guest)
on 2008-10-14 08:41
(Received via mailing list)
FYI -- I've forked rails and added my changes here:

http://github.com/manalang/rails/commit/29de7f2746...

Rich
Charles Oliver N. (Guest)
on 2008-10-15 04:25
(Received via mailing list)
Rich M. wrote:
> Ok... I got it to work (compiled app/ and lib/), but I had to modify
> rails/activesupport/lib/active_support/dependencies.rb.  This file loads
> all deps during rails initialization and looks specifically for *.rb
> files.  I had to add *.class to the searches.
>
> I've attached the diff.  I'd love for rails to be able to do this
> automatically, how would you guys suggest getting this stuff to rails core?

I think we should actually modify JRuby so that "load 'foo.rb'" will
also look for .class, since basically this is like .py/.pyc in Python
and .rb/.rbc in Rubinius; the .class version should be treated as an
equivalent compiled version of the .rb file.

Agreed? I think we may have had a bug on this previous and either not
fixed it or punted on it, since it's obviously not doing that.

- Charlie

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email
Rich M. (Guest)
on 2008-10-15 05:49
(Received via mailing list)
I agree this should be in JRuby, but it looks like ActiveSupport
overrides
load and require... which is why it doesn't work out of the box.

Rich

On Tue, Oct 14, 2008 at 5:22 PM, Charles Oliver N. <
Charles Oliver N. (Guest)
on 2008-10-15 05:59
(Received via mailing list)
Rich M. wrote:
> I agree this should be in JRuby, but it looks like ActiveSupport
> overrides load and require... which is why it doesn't work out of the box.

Eventually it needs to fall back on require/load logic though, which is
where JRuby is falling down:

~/projects/jruby âž” vi foo.rb

~/projects/jruby âž” jrubyc foo.rb
Compiling foo.rb to class foo

~/projects/jruby âž” rm foo.rb

~/projects/jruby âž” jruby -e "load './foo.rb'"
-e:1:in `load': No such file to load -- ./foo.rb (LoadError)
  from -e:1

~/projects/jruby âž” jruby -e "load './foo.class'"
here

I will file a bug for 1.1.5. I see the light now, and believe load
should search for both .class and .rb when requested to load xxx.rb.

- Charlie


---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email
This topic is locked and can not be replied to.