Using Java .class files directly from JRuby

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:


To unsubscribe from this list, please visit:

http://xircles.codehaus.org/manage_email

On Jan 12, 2009, at 1:22 PM, Stephen B. wrote:

‘RedclothScanService$Base’

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

The problem is described in more detail here: gist:46140 · GitHub

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

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: gist:46140 · GitHub

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:

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

On Jan 12, 2009, at 1:22 PM, Stephen B. 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.

gist:46177 · GitHub

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