Forum: JRuby using Java .class files directly from JRuby

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.
6f608b6766f79343062a2aa3985933dc?d=identicon&s=25 Stephen Bannasch (Guest)
on 2009-01-12 21:23
(Received via mailing list)
I'm experimenting to see if I can get a gem that normally uses a jar
to use the .class files instead. If this works I could package the
gem with .class files instead of the jar and then more easily include
it in with jruby-complete.jar (avoiding the jar within a jar problem).

Specificall I'm trying to get the redcloth gem (that normally uses a
jar) working with the Java class files directly.

Does anyone know if this should work: include_class
'RedclothScanService$Base'

I'm getting an: include_class': undefined method
`RedclothScanService' for main:Object (NoMethodError)

The problem is described in more detail here:
http://gist.github.com/46140


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

    http://xircles.codehaus.org/manage_email
Ea3084bf9444c7d0cd0c640ca0ac93b3?d=identicon&s=25 Logan Barnett (Guest)
on 2009-01-13 07:15
(Received via mailing list)
On Jan 12, 2009, at 1:22 PM, Stephen Bannasch wrote:

> 'RedclothScanService$Base'
>
> I'm getting an: include_class': undefined method
> `RedclothScanService' for main:Object (NoMethodError)
>
> The problem is described in more detail here: http://gist.github.com/46140

For the "Is your computer plugged in" question - Is lib (where the
classes live) on the classpath?
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe from this list, please visit:
>
>  http://xircles.codehaus.org/manage_email
>
>


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

    http://xircles.codehaus.org/manage_email
6f608b6766f79343062a2aa3985933dc?d=identicon&s=25 Stephen Bannasch (Guest)
on 2009-01-13 09:39
(Received via mailing list)
>>
>>Does anyone know if this should work: include_class
>>'RedclothScanService$Base'
>>
>>I'm getting an: include_class': undefined method
>>`RedclothScanService' for main:Object (NoMethodError)
>>
>>The problem is described in more detail here: http://gist.github.com/46140
>
>For the "Is your computer plugged in" question - Is lib (where the
>classes live) on the classpath?

I modified the Rake task so the classes are copied to lib/ also:

[redcloth.git (nojar)]$ ls -l lib/
total 3360
-rw-r--r--  1 stephen  staff   24976 Jan 12 14:32
RedclothAttributes.class
-rw-r--r--  1 stephen  staff  560002 Jan 12 14:32 RedclothInline.class
-rw-r--r--  1 stephen  staff    9548 Jan 12 14:32
RedclothScanService$Base.class
-rw-r--r--  1 stephen  staff  597763 Jan 12 14:32
RedclothScanService$Transformer.class
-rw-r--r--  1 stephen  staff    5423 Jan 12 14:32
RedclothScanService.class
drwxr-xr-x  3 stephen  staff     102 Jul 27 21:23 case_sensitive_require
drwxr-xr-x  7 stephen  staff     238 Nov 20 17:59 redcloth
-rw-r--r--@ 1 stephen  staff    1522 Jan 12 18:39 redcloth.rb
-rw-r--r--  1 stephen  staff  506272 Jan 12 14:32 redcloth_scan.jar


This is the statement I am trying to replace:

   require 'redcloth_scan'

I just want to replicate with a set of bare *.classes what require
does with a jar.

RedclothScanService implements BasicLibraryService -- it's adding
methods to RedCloth::TextileDoc
You can see the RedclothScanService.java code ragel generated here:
http://gist.github.com/46177

When JRuby requires a jar (and perhaps a class also?) and there is a
class in that jar that implements BasicLibraryService then it's
basicLoad method get's called.

The classes RedclothScanService$Base and
RedclothScanService$Transformer are static classes
which is why they appear as separate .class files.

This variation executes without complaining but the code still doesn't
work.

require 'jruby'
$CLASSPATH <<  File.dirname(File.expand_path(__FILE__)) + '/'
require 'RedclothScanService$Base'
require 'RedclothScanService$Transformer'
require 'RedclothInline'
require 'RedclothAttributes'
require 'RedclothScanService'

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

    http://xircles.codehaus.org/manage_email
6f608b6766f79343062a2aa3985933dc?d=identicon&s=25 Stephen Bannasch (Guest)
on 2009-01-18 01:37
(Received via mailing list)
>>On Jan 12, 2009, at 1:22 PM, Stephen Bannasch wrote:
>>
>>>I'm experimenting to see if I can get a gem that normally uses a
>>>jar to use the .class files instead. If this works I could package
>>>the gem with .class files instead of the jar and then more easily
>>>include it in with jruby-complete.jar (avoiding the jar within a
>>>jar problem).
>>>
>>>Specificall I'm trying to get the redcloth gem (that normally uses
>>>a jar) working with the Java class files directly.

...

>http://gist.github.com/46177
>
>require 'jruby'
>$CLASSPATH <<  File.dirname(File.expand_path(__FILE__)) + '/'
>require 'RedclothScanService$Base'
>require 'RedclothScanService$Transformer'
>require 'RedclothInline'
>require 'RedclothAttributes'
>require 'RedclothScanService'

But this does work:

   require 'jruby'
   $CLASSPATH <<  File.dirname(File.expand_path(__FILE__)) + '/'
   Java::RedclothScanService.new.basicLoad(JRuby.runtime)

So at least for the redcloth gem which includes redcloth_scan.jar in
it's lib/ dir -- if you instead just put the class files in lib/ and
replace: require 'redcloth_scan' with the three lines above it should
work fine when embedded into a jar with the rest of JRuby.

I added some of these details to this Jira issue:

Unable to embed Hpricot gem in a jar file:
http://jira.codehaus.org/browse/JRUBY-3299

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

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