Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

LoadError with 'compiled' ruby files with JRuby9000 #3018

Closed
MSNexploder opened this issue Jun 4, 2015 · 6 comments
Closed

LoadError with 'compiled' ruby files with JRuby9000 #3018

MSNexploder opened this issue Jun 4, 2015 · 6 comments

Comments

@MSNexploder
Copy link
Contributor

Compiling any Ruby code into a class file and trying to load it afterwards leads to "LoadError: use `java_import' to load normal Java classes".

test.rb

puts 'hello world'

compiled and run with

jrubyc test.rb
ruby -e "load 'test.class'"

leads to

LoadError: use `java_import' to load normal Java classes: test
   load at org/jruby/RubyKernel.java:958
  <top> at -e:1

Happens in both 9.0.0.0.pre2 and current master (393e64f).

This essentially breaks warblers 'compiled' feature - which uses shims in order to transparently load the generated class files (jruby/warbler#325).

@torcido
Copy link

torcido commented Jun 15, 2015

I'm finding the same issue with 9.0.0.0.rc1 also. Your simple test case illustrates it well. It looks like you're using rvm or rbenv to launch jruby. I'm invoking it from jruby-complete.jar and getting the same result.

Trying to use "java_import" the ruby classes results in an error like:

NameError: cannot load Java class test

Even if I rename the input file "Test.rb" with a capital "T", and it generates a java class called "Test", I still get the error:

NameError: cannot load Java class Test

$ javap Test.class
Compiled from "Test.rb"
public class Test {
  public static void main(java.lang.String[]);
}

By the way, have you noticed how much cleaner the compiled classes are? Version 1.7.20 produces class files that look like this:

$ javap Test.class
Compiled from "Test.rb"
public class Test extends org.jruby.ast.executable.AbstractScript {
  public Test();
  public static org.jruby.runtime.builtin.IRubyObject __file__(Test, org.jruby.runtime.ThreadContext, org.jruby.runtime.builtin.IRubyObject, org.jruby.runtime.builtin.IRubyObject[], org.jruby.runtime.Block);
  public org.jruby.runtime.builtin.IRubyObject __file__(org.jruby.runtime.ThreadContext, org.jruby.runtime.builtin.IRubyObject, org.jruby.runtime.builtin.IRubyObject[], org.jruby.runtime.Block);
  public org.jruby.runtime.builtin.IRubyObject load(org.jruby.runtime.ThreadContext, org.jruby.runtime.builtin.IRubyObject, boolean);
  public static void main(java.lang.String[]);
}

@headius headius added this to the JRuby 9.0.0.0.rc2 milestone Jul 6, 2015
@headius headius closed this as completed in 1494436 Jul 6, 2015
@headius
Copy link
Member

headius commented Jul 6, 2015

Ok, this is fixed now for RC2. There's one caveat, however...

In order to speed load times, we have removed .class from load searching by default. In order to have JRuby search for .class, you'll need to pass -Xaot.loadClasses=true to JRuby or -Djruby.aot.loadClasses=true to the JVM. This probably needs to change in warbler or jruby-rack somewhere (what do you think, @kares?)

@kares
Copy link
Member

kares commented Jul 6, 2015

JRuby-Rack should be fine ... but Warbler might be affected by the .class loading change // cc @jkutner

@jkutner
Copy link
Member

jkutner commented Jul 7, 2015

With a quick warbler test, it looks like this fixes the problem (without the aot.loadClasses=true). I'll investigate further to make sure that's right, but I don't expect any difficulty. Thanks @headius!

@amiracam
Copy link

amiracam commented Aug 10, 2018

I am bumping into this issue and I am packaging with warbler on 9.2.0.0

I tried passing this -Djruby.aot.loadClasses=true but the jvm rejected i.e. 1.8.0_171

@mfinnessy
Copy link

I've opened up a new ticket since this one is closed and doesn't appear to be seen. See #5341 for similar issue in 9.2.0.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

7 participants