Help with simple JRuby/Java integration


#1

Hi all,

I’m in the process of trying to add native JRuby support to the
ruby-yui-compressor gem, but I’m stumped. I thought this would be a
great chance to both get familiar with JRuby and do something really
useful at the same time, and I’ve gotten most of the way there.
There’s just one last snag (I think).

I’ve reduced the problem to a simple test case you can find at
http://github.com/mjijackson/jruby-yuicompressor. If you run the
test.rb file with the latest JRuby, you’ll see what I mean. There’s an
exception being thrown from within the Java code. I think it’s being
caused by some error on the input stream, though I’ve checked the
input stream with a normal read loop (from Ruby land) and it works
just fine.

If someone with a bit more JRuby/Java experience would kindly take a
look at this, I’d appreciate it very much. BTW, here’s my `ruby -v’.

jruby 1.5.1 (ruby 1.8.7 patchlevel 249) (2010-06-06 f3a3480) (Java
HotSpot™ 64-Bit Server VM 1.6.0_20) [x86_64-java]

Thanks.


Michael J.
http://mjijackson.com
@mjijackson


To unsubscribe from this list, please visit:

http://xircles.codehaus.org/manage_email

#2

Hi Michel,

could you please send a pastie with your error? I’m trying to reproduce
it
put it works fine here. Perhaps something is wrong in your classpath.

[david@calavera:jruby-yuicompressor]$ jdev -v test.rb

jruby 1.6.0.dev (ruby 1.8.7 patchlevel 249) (2010-07-13 745bf05) (Java

HotSpot™ 64-Bit Server VM 1.6.0_20) [x86_64-java]

var a;

[david@calavera:jruby-yuicompressor]$ jruby -v test.rb

jruby 1.5.1 (ruby 1.8.7 patchlevel 249) (2010-06-06 f3a3480) (Java

HotSpot™ 64-Bit Server VM 1.6.0_20) [x86_64-java]

var a;


#3

Hi David,

Sorry. I should have included it in the first email. Here’s what I get.

$ ruby -v test.rb
jruby 1.5.1 (ruby 1.8.7 patchlevel 249) (2010-06-06 f3a3480) (Java
HotSpot™ 64-Bit Server VM 1.6.0_20) [x86_64-java]
com/yahoo/platform/yui/compressor/JavaScriptCompressor.java:299:in
printSourceNumber': java.lang.RuntimeException: null (NativeException) from com/yahoo/platform/yui/compressor/JavaScriptCompressor.java:336:inparse’
from
com/yahoo/platform/yui/compressor/JavaScriptCompressor.java:533:in
<init>' from sun/reflect/NativeConstructorAccessorImpl.java:-2:innewInstance0’
from sun/reflect/NativeConstructorAccessorImpl.java:39:in
newInstance' from sun/reflect/DelegatingConstructorAccessorImpl.java:27:innewInstance’
from java/lang/reflect/Constructor.java:513:in newInstance' from org/jruby/javasupport/JavaConstructor.java:291:innewInstanceDirect’
from test.rb:12:in `new_proxy’
from test.rb:28


Michael J.
http://mjijackson.com
@mjijackson

On Sun, Jul 18, 2010 at 3:59 AM, David C.
removed_email_address@domain.invalid wrote:

Hi all,
exception being thrown from within the Java code. I think it’s being
Thanks.


To unsubscribe from this list, please visit:

http://xircles.codehaus.org/manage_email

#4

I also tried your repo and could not get it to fail. I even changed
some of the source around like adding a couple of var statements
including assignments. Are you getting this error with source other
than what you provided because the stacktrace you reported seems to be
choking on a Token.Number in the Java side of things and although I
don’t know what this token represents there does not appear to be a
number in test.js.

Brainstorming:

  1. There is an interesting environmental difference (ENV or -D you are
    always running)
  2. There is a bug in the parser code itself in yuicompressor and you
    are using some source which hits it and not test.js
  3. You are using a charset we are (JRuby) doing something bad to?

-Tom

On Sun, Jul 18, 2010 at 7:53 AM, Michael J. removed_email_address@domain.invalid
wrote:

`printSourceNumber’: java.lang.RuntimeException: null
from test.rb:28

Hi Michel,

[david@calavera:jruby-yuicompressor]$ jruby -v test.rb

caused by some error on the input stream, though I’ve checked the


blog: http://blog.enebo.com twitter: tom_enebo
mail: removed_email_address@domain.invalid


To unsubscribe from this list, please visit:

http://xircles.codehaus.org/manage_email

#5

I’m using JRuby and YUI Compressor in a project. Here’s the source.

http://github.com/consiliens/regenerate_site/blob/master/lib/regenerate_site/css_compress.rb
http://github.com/consiliens/regenerate_site/blob/master/spec/regenerate_site/css_compress_spec.rb

On 07/18/2010 06:53 AM, Michael J. wrote:

`printSourceNumber’: java.lang.RuntimeException: null
from test.rb:28

Hi Michel,

[david@calavera:jruby-yuicompressor]$ jruby -v test.rb

caused by some error on the input stream, though I’ve checked the


To unsubscribe from this list, please visit:

http://xircles.codehaus.org/manage_email

#6

I should also note that the YUI Compressor source is available on
GitHub as well.

http://github.com/yui/yuicompressor


Michael J.
http://mjijackson.com
@mjijackson

On Sun, Jul 18, 2010 at 6:50 AM, Michael J. removed_email_address@domain.invalid
wrote:

   from com/yahoo/platform/yui/compressor/JavaScriptCompressor.java:336:in `parse'

put it works fine here. Perhaps something is wrong in your classpath.

jruby 1.5.1 (ruby 1.8.7 patchlevel 249) (2010-06-06 f3a3480) (Java
ruby-yui-compressor gem, but I’m stumped. I thought this would be a
just fine.
Michael J.


To unsubscribe from this list, please visit:

http://xircles.codehaus.org/manage_email

#7

Thanks for the example. I can get the CSS compressor to work fine on
my end too. It’s the JS one that’s giving me problems.


Michael J.
http://mjijackson.com
@mjijackson

On Sun, Jul 18, 2010 at 9:31 AM, consiliens removed_email_address@domain.invalid
wrote:

http://github.com/yui/yuicompressor

   from
   from java/lang/reflect/Constructor.java:513:in `newInstance'

var a;
There’s just one last snag (I think).
look at this, I’d appreciate it very much. BTW, here’s my `ruby -v’.


http://xircles.codehaus.org/manage_email


To unsubscribe from this list, please visit:

http://xircles.codehaus.org/manage_email

#8

Hi Thomas,

Thanks for giving it a try. I’m using the code exactly as provided in
the repo, without any modifications. I can understand how you thought
it was a strange error because there aren’t any numbers. I thought the
same thing. :wink:

Here’s what my JRuby environment looks like.

$ ruby -v -rpp -e ‘pp ENV’
jruby 1.5.1 (ruby 1.8.7 patchlevel 249) (2010-06-06 f3a3480) (Java
HotSpot™ 64-Bit Server VM 1.6.0_20) [x86_64-java]
{“LANG”=>“en_US.UTF-8”,
“rvm_release_version”=>“1”,
“rvm_major_version”=>“5”,
“MANPATH”=>"/Users/michael/.rvm/man:",
“rvm_scripts_path”=>"/Users/michael/.rvm/scripts",
“rvm_ruby_gem_home”=>"/Users/michael/.rvm/gems/jruby-1.5.1",
“rvm_ruby_gem_path”=>
“/Users/michael/.rvm/gems/jruby-1.5.1:/Users/michael/.rvm/gems/jruby-1.5.1@global”,
“JAVA_ARCH”=>“x86_64”,
“GEM_PATH”=>
“/Users/michael/.rvm/gems/jruby-1.5.1:/Users/michael/.rvm/gems/jruby-1.5.1@global”,
“TERM_PROGRAM”=>“Apple_Terminal”,
“__shell_array_start”=>“0”,
“rvm_ruby_interpreter”=>“jruby”,
“rvm_ruby_string”=>“jruby-1.5.1”,
“rvm_verbose_flag”=>“1”,
“IRBRC”=>"/Users/michael/.rvm/rubies/jruby-1.5.1/.irbrc",
“USER”=>“michael”,
“rvm_ruby_home”=>"/Users/michael/.rvm/rubies/jruby-1.5.1",
“rvm_minor_version”=>“1”,
“TERM_PROGRAM_VERSION”=>“273”,
“JAVA_MAIN_CLASS_438”=>“org.jruby.Main”,
“SHLVL”=>“1”,
“rvm_bin_path”=>"/Users/michael/.rvm/bin",
“MY_RUBY_HOME”=>"/Users/michael/.rvm/rubies/jruby-1.5.1",
“rvm_rubies_path”=>"/Users/michael/.rvm/rubies",
“rvm_gems_path”=>"/Users/michael/.rvm/gems",
“TERM”=>“xterm-color”,
“rvm_ruby_src_path”=>"/Users/michael/.rvm/src/jruby-1.5.1",
“__CF_USER_TEXT_ENCODING”=>“0x1F5:0:0”,
“rvm_ruby_irbrc”=>"/Users/michael/.rvm/rubies/jruby-1.5.1/.irbrc",
“rvm_patchsets_path”=>"/Users/michael/.rvm/patchsets",
“TMPDIR”=>"/var/folders/HP/HPBSHqdtEI0ydtmLFEzALU+++TI/-Tmp-/",
“rvm_ruby_package_name”=>“jruby-1.5.1”,
“rvm_patches_path”=>"/Users/michael/.rvm/patches",
“rvm_tmp_path”=>"/Users/michael/.rvm/tmp",
“rvm_gemsets_path”=>"/Users/michael/.rvm/gemsets",
“SSH_AUTH_SOCK”=>"/tmp/launch-CNyFs4/Listeners",
“Apple_PubSub_Socket_Render”=>"/tmp/launch-scQfti/Render",
“rvm_ruby_log_path”=>"/Users/michael/.rvm/log/jruby-1.5.1",
“rvm_url”=>
http://jruby.org.s3.amazonaws.com/downloads/1.5.1/jruby-bin-1.5.1.tar.gz”,
“rvm_ruby_version”=>“1.5.1”,
“BUNDLE_PATH”=>"/Users/michael/.rvm/gems/jruby-1.5.1",
“rvm_src_path”=>"/Users/michael/.rvm/src",
“rvm_log_path”=>"/Users/michael/.rvm/log",
“rvm_gems_cache_path”=>"/Users/michael/.rvm/gems/cache",
“GEM_HOME”=>"/Users/michael/.rvm/gems/jruby-1.5.1",
“rvm_repo_path”=>"/Users/michael/.rvm/repos",
“rvm_hooks_path”=>"/Users/michael/.rvm/hooks",
“DISPLAY”=>"/tmp/launch-vTuBi4/org.x:0",
“RUBY_VERSION”=>“jruby-1.5.1”,
“rvm_version”=>“0.1.40”,
“COMMAND_MODE”=>“unix2003”,
“rvm_interactive”=>“1”,
“rvm_gemset_separator”=>"@",
“rvm_config_path”=>"/Users/michael/.rvm/config",
“rvm_ruby_selected_flag”=>“1”,
“rvm_action”=>“use”,
“PATH”=>
“/Users/michael/.rvm/gems/jruby-1.5.1/bin:/Users/michael/.rvm/gems/jruby-1.5.1@global/bin:/Users/michael/.rvm/rubies/jruby-1.5.1/bin:/Users/michael/.rvm/bin:/usr/local/depot_tools:/usr/local/bin:/usr/local/sbin:/opt/local/bin:/opt/local/sbin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/X11/bin”,
“SHELL”=>"/bin/bash",
“rvm_path”=>"/Users/michael/.rvm",
“LOGNAME”=>“michael”,
“HOME”=>"/Users/michael",
“PWD”=>"/Users/michael",
“rvm_archives_path”=>"/Users/michael/.rvm/archives",
“rvm_ruby_binary”=>"/Users/michael/.rvm/rubies/jruby-1.5.1/bin/ruby"}

The only thing that I can think of about my environment that isn’t
exactly standard is that I’m using JRuby as installed by RVM instead
of installing it myself. However, I have tried downloading and
installing JRuby from jruby.org with the same result.

As far as character sets go, Vim tells me that both files (test.rb and
test.js) are encoded using utf-8.

I know that’s not a lot to go on. Any other ideas?

Thanks.


Michael J.
http://mjijackson.com
@mjijackson

On Sun, Jul 18, 2010 at 8:19 AM, Thomas E Enebo removed_email_address@domain.invalid
wrote:

always running)

http://github.com/yui/yuicompressor

`’
http://mjijackson.com

[david@calavera:jruby-yuicompressor]$ jdev -v test.rb

useful at the same time, and I’ve gotten most of the way there.
If someone with a bit more JRuby/Java experience would kindly take a
@mjijackson


blog: http://blog.enebo.com twitter: tom_enebo
mail: removed_email_address@domain.invalid


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

#9

So. I reinstalled Mac OSX today because some other weirdness was
happening as well … and now it works. Ugh.

Thanks for your help!


Michael J.
http://mjijackson.com
@mjijackson

On Sun, Jul 18, 2010 at 10:06 AM, Michael J. removed_email_address@domain.invalid
wrote:

On Sun, Jul 18, 2010 at 9:31 AM, consiliens removed_email_address@domain.invalid wrote:

http://github.com/yui/yuicompressor

   from
   from java/lang/reflect/Constructor.java:513:in `newInstance'

var a;
There’s just one last snag (I think).
look at this, I’d appreciate it very much. BTW, here’s my `ruby -v’.


http://xircles.codehaus.org/manage_email


To unsubscribe from this list, please visit:

http://xircles.codehaus.org/manage_email

#10

Consider setting up a development VM with snapshots of known good
states.
http://www.virtualbox.org/

On 07/19/2010 06:19 PM, Michael J. wrote:

GitHub as well.
On Sun, Jul 18, 2010 at 6:50 AM, Michael J.removed_email_address@domain.invalid

`printSourceNumber’: java.lang.RuntimeException: null
from sun/reflect/DelegatingConstructorAccessorImpl.java:27:in
@mjijackson

HotSpot™ 64-Bit Server VM 1.6.0_20) [x86_64-java]
great chance to both get familiar with JRuby and do something really

http://mjijackson.com


 http://xircles.codehaus.org/manage_email

To unsubscribe from this list, please visit:

http://xircles.codehaus.org/manage_email