Skip to content

C Extension Alternatives

Charles Oliver Nutter edited this page Dec 24, 2020 · 58 revisions

JRuby does not support native C extensions, but it does have its own Java native extensions API. Several gems have implementations of both Java and C extensions rolled into the same gem and those will not be listed here since they will just work. In some cases there is a JRuby version with a slightly different name or possibly even a totally different name and we list these here so you can update your Gemfile:

gem 'therubyracer', platform: :mri
gem 'therubyrhino', platform: :jruby

When there is not an exact match some gems come close enough where a little work on your part can make your application compatible with JRuby.

This page lists common C extensions and JRuby-friendly alternatives you can use to replace them.

If you are interested in helping us port an extension to JRuby, this article is helpful: Your first Ruby native extension: Java see also JRuby examples for a maven build.

Gem Suggestions
bson_ext bson_ext isn't used with JRuby. Instead, some native Java extensions are bundled with the bson gem.
charlock_holmes Use charlock_holmes-jruby instead.
curb Rurl is an example how to implement some of curb's functionality using Apache HttpClient
curses Use ffi-ncurses. ncurses is literal API and lower level than curses
fast_xor use xorcist instead or roll slower but pure ruby equivalent.
escape_utils Most of the escape methods here are now native code in CRuby and JRuby for the CGI library. Others can be found in the JDK itself.
image_science Use image_voodoo instead.
kyotocabinet Try using kyotocabinet-java instead. This isn't 100% complete yet, but it covers most of the API.
memcached Try using jruby-memcached instead. Alternatively you can use jruby-ehcache, a JRuby interface to Java's (JSR-107 compliant) Ehcache.
mysql Use activerecord-jdbcmysql-adapter.
mysql2 Use activerecord-jdbcmysql-adapter.
oj Try gson, json or json_pure instead.
pg Use activerecord-jdbcpostgresql-adapter instead or pg_jruby (drop-in replacement).
pry-byebug Use pry-debugger-jruby instead.
RDiscount Use kramdown, Maruku (pure Ruby) or markdown_j (wrapper around a Java library)
RedCarpet Same as with RDiscount use alternatives such as kramdown, Maruku or markdown_j
RMagick Try RMagick4J (implements ImageMagick functionality in Java) or preferably use alternatives mini_magick & quick_magick. For simple resizing, cropping, greyscaling, etc look at image_voodoo. You can also use Java's Graphics2D.
sqlite3 Use activerecord-jdbcsqlite3-adapter.
therubyracer Try using therubyrhino instead (or dienashorner on Java 8+).
Thin Use Puma.
Unicorn Use Puma.
win32ole Use the jruby-win32ole gem (preinstalled in JRuby's Windows installer).
yajl-ruby Try json or json_pure instead. Unfortunately there is no known equivalent JSON stream parser.
rugged Try using rjgit. Not a drop-in replacement, but API is pretty similar

Please add to this list with your findings.

*Note that the JRuby-Lint gem parses the contents of the list above to use for its Ruby gem checker. In order for JRuby-Lint to use the information, please adhere to the table format above and the links to projects below (in the source for this page).

Clone this wiki locally