java gem extension

19 views
Skip to first unread message

Phil Rees

unread,
Apr 27, 2016, 1:04:20 AM4/27/16
to rawr-lib
I am trying to package up my app with some gem dependencies. I am able to package it up and source the required gems except for one. The nokogiri gem has a java extension in the 'ext' directory. When I include this gem in the package it breaks the rawr compilation:


mkdir -p packaging/migrate/classes/java
javac -source 1.7 -target 1.7 -cp lib/java/jruby-complete.jar:lib/migrate -sourcepath lib/migrate -d packaging/migrate/classes/java lib/migrate/org/monkeybars/rawr/Main.java
warning: [options] bootstrap class path not set in conjunction with -source 1.7
Note: lib/migrate/org/monkeybars/rawr/Main.java uses unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
1 warning
javac -source 1.7 -target 1.7 -cp lib/java/jruby-complete.jar:lib/migrate -sourcepath lib/migrate -d packaging/migrate/classes/java lib/migrate/org/nokogiri/EncodingHandler.java
warning: [options] bootstrap class path not set in conjunction with -source 1.7
lib/migrate/org/nokogiri/EncodingHandler.java:35: error: package nokogiri.internals does not exist
import static nokogiri.internals.NokogiriHelpers.getNokogiriClass;
                                ^
lib/migrate/org/nokogiri/EncodingHandler.java:35: error: static import only from classes and interfaces
import static nokogiri.internals.NokogiriHelpers.getNokogiriClass;
^
lib/migrate/org/nokogiri/EncodingHandler.java:85: error: cannot find symbol
            getNokogiriClass(ruby, "Nokogiri::EncodingHandler"),
            ^
  symbol:   method getNokogiriClass(Ruby,String)
  location: class EncodingHandler
3 errors
1 warning
rake aborted!
Command failed with status (1): [javac -source 1.7 -target 1.7 -cp lib/java...]
org/jruby/RubyProc.java:289:in `call'

So the java portion of nokogiri is not being handled correctly here. My question is, is there a specific place I should put this part of nokogiri or is there a path I can set in the configuration to properly source this directory?

I have tried a few different possibilities but nothing has seemed to change the above results. I have also read several posts on how to properly include gems with rawr and none that I have seen have mentioned a scenario like this. 

Any insight would be greatly appreciated!

Thanks,
Phil 

James Britt

unread,
Apr 27, 2016, 1:31:28 AM4/27/16
to rawr-lib
When you install the java version of Nokogiri, does it not give you a usable jar file? I installed the gem and in the gem installation folder, in nokogiri-1.6.7.2-java/lib, there are a number of jars.  

Rawr shouldn't be trying to compile any source java for this gem (I would think). You should be able to unpack the gem to a local project folder and reference that from your application.

I don't think you need the ext folder, just the lib.   Rawr is essentially invoking jruby against a main class  and a custom $:  And JRubyusing that gem wouldn't need to compile code.

I see that `gem unpack nokogiri` gives you *everything*, but I think all you need is lib/, and to load the jar files there.

But if rawr finds java files in it's path it will try to compile them.

Phil Rees

unread,
Apr 27, 2016, 10:31:54 AM4/27/16
to rawr-lib
Hi James,

Thanks for the quick reply. 

You are correct by simply removing the ext folder from the unpacked gem it works. Thanks! 

More detail for others. I had unpacked the gems and loaded the lib folder on my path. The issue was that I left the remaining parts of the gem in my project folder as well. So even though the lib folder is in place the other files like you say are not needed and actually CAN'T be there in this case. I followed your post here on how to unpack and reference the gems. 

Thanks again!

James Britt

unread,
Apr 27, 2016, 11:25:00 AM4/27/16
to rawr-lib
What's interesting is that rawr still saw those java files in the ext folder and tried to compile them.  I your build_configuration.rb file were you referencing the entire unpacked gem folder as an additional src location?

Phil Rees

unread,
Apr 27, 2016, 11:30:38 AM4/27/16
to rawr-lib
Not directly, but I did reference a parent folder that contains other ruby files. So that could be why.

sunbinyuan1

unread,
Sep 2, 2016, 8:46:49 PM9/2/16
to rawr-lib
How did you make it in the end? After I removed the ext folder, I got some new error including a StackOverFlow error:
Copying source file lib/ruby/nokogiri-1.6.8-java/nokogiri/xml/cdata.rb to package/classes/ruby/lib/ruby/nokogiri-1.6.8-java/nokogiri/xml/cdata.rb
C:/jruby-9.1.3.0/lib/ruby/gems/shared/gems/rake-11.2.2/lib/rake/task.rb:197: warning: singleton on non-persistent Java type Java::JavaLang::StackOverflowError (http://wiki.jruby.org/Persistence)
rake aborted!
Java::JavaLang::StackOverflowError:


Reply all
Reply to author
Forward
0 new messages