Can all Jruby apps be complied to class files?

I’ve been playing with rawr which can compile jruby code to Java class
files and subsequently generate an executable jar. I just want to be
certain that any Jruby “application” code can be compiled to .class
files.

thanks

Charles

Hi I think that the the answer is yes. But you must be careful with
native
Ruby resources because the classes couldnt see it on some cases… I’m
using Jrubyc to do that and Jruby complete jar as runtime environment
onto
a fatjar for distribution…

Reggards
El 26/09/2013 03:21, “Charles M.” [email protected] escribi:

Hi Charles,

My experience is also yes. I’m doing the same thing for several
projects,
and I’m using rawr as well. I monkeyed around with warbler for awhile,
but
it seems more oriented towards creating ears and wars than jars, and I
just
couldn’t get it to do what I needed it to do. My experience with
packaging
ruby code as compiled class files in jars is that the classloading is a
little wonky… it’s not as straightforward as loading .rb files from a
noncompressed file system (things like File.join(File.dirname(FILE),
“whatever”) don’t really work), but its doable once you figure out the
uris
that represent paths to resources inside the jar. If you run into
problems
with that, post back and I can try to share more concrete examples.

Mark

One thing to keep in mind is that although JRuby source files can be
compiled to class files, they cannot be run without the JRuby
interpreter. That is, the JRuby jar file must be included in the
distribution, and will be used at runtime to process those class files.
Ian D., coauthor of the excellent JRuby book, explained this to me at
CukeUpNYC a couple of weeks ago.

  • Keith

I would be interested since I just added the feature to created
executable
jars out of a jruby project - that could be something to a compilation
of
ruby files as well. just thinking aloud . . .

  • christian

Theres a posts line about end on July beginning August about this theres
info about differents points of view and some resource links… As you
said
without a Jruby Interpreter Jar included or referenced its imposible to
make a distribution…

Reggards
El 26/09/2013 15:48, “Keith B.” [email protected] escribi:

Charles M. wrote:

I’ve been playing with rawr which can compile jruby code to Java class files and
subsequently generate an executable jar. I just want to be certain that any Jruby
“application” code can be compiled to .class files.

Rawr does this by calling jrubyc to do the compilation.

James B.

Neurogami - Avant-garage Research & Development

[email protected]

Keith B. wrote:

One thing to keep in mind is that although JRuby source files can be
compiled to class files, they cannot be run without the JRuby
interpreter. That is, the JRuby jar file must be included in the
distribution, and will be used at runtime to process those class files.

That’s basically what Rawr does. The resulting executable bundle
includes a jruby-complete.jar.

You also have to be sure that your project source code is not relying on
gems or other files that are not also going to be somehow included in
the resulting executable, since if you run the results on another
machine you cannot be sure of what is installed.

James B.

Neurogami - Avant-garage Research & Development

[email protected]

well sorry for advertising jbundler but it does pack the jruby itselfm
the
bundled gems (from Gemfile) and the bundled jars (Jarfile) to create jar
containing all those with executable set to bootstrap file to start the
application.

but does it have the option of compiling the app’s ruby source to .class
files ?

thanks

Charles M.
[email protected]

I will add that feature right now - adding a jrubyc call in the sequence
is
actually straight forward. but it is NOT part of it yet.

even if I get it pushed today I need to call that feature experimental
or
at least beta state :wink:

christian wrote:

well sorry for advertising jbundler but it does pack the jruby itselfm
the bundled gems (from Gemfile) and the bundled jars (Jarfile) to create
jar containing all those with executable set to bootstrap file to start
the application.

Very cool.

Something to watch for when including third-party code into what should
be a standalone executable is that some some gems will call other gems
even though those other gems have not been specified in the gemspec or
in Gemfile.

The trick is to ensure that only files included in the packaged
executable are on the load path.

Basically, $: should only refer to the included jruby-complete jar and
the files explicitly included in the resulting executable bundle of
code.

James

Neurogami - Avant-garage Research & Development

[email protected]

As i said before to get easily a class… Jrubyc

Then you can proceed as a java jar on jdk including Jruby Complete jar
on
classpath of jre…
El 27/09/2013 03:25, “Charles M.” [email protected] escribi:

just pushed a jbundler-0.5.3 which can compile the ruby classes before
packing them into the exectuable jar

Something to watch for when including third-party code into what should
be

that is quite tricky: jruby-complete.jar even includes the
$HOME/.gem/jruby/1.x to Gem.path, i.e. any gem installed there will be
found by ‘require’

something like this:
Gem.path.delete_if{ |p| !p.match( /^file:/ ) }
in the bootstrap script could do the trick as well assuming all gems are
located inside the jar in jruby.home/lib/ruby/shared/gems/

-christian

well I will be your beta tester and promise not to hold you liable for
any damages to our production system :), thanks will you generator a gem
for that as well ?
Charles M.
[email protected]

thanks all for the feedback.

I’ll be honest I’m hitting a learning curb on the Jruby deployment /
packaging stage, some of that is because its been ages since I have
packaged a Java app and partly because the documentation for the
packagers I have seen so far is not complete or assumes the user being
familiar with Java packaging which is perhaps fair.

I have 3 active Jruby projects in only one of those cases do I have sole
control over the deployment box, the other two I absolutely cannot
expose source code and thus all app source must be compiled to .class
files.

the projects are:

sinatra on trinidad or torque box which leverages multiple gems, more of
a service thing with minor use of views for admin purposes
jrubyfx client app

Ideally I would like in both cases to come up with all inclusive
installer which installs :

JRE i.e. not system install but for specific use by app
Jruby complete jar + jars of app with .class files for app’s ruby source

  • all necessary gems
    In the case of jrubyfx client I would also prefer a single executable
    for the app along with #1 & 2

I started with RAWR and tested with trivial app that included ruby
source and was able to generate the jar i.e.hello world type of thing,
however trying to use the “compile ruby source” resulted in issues. I
tried to use bundler’s install – deployment flag to generate the source
for the gems locally in my project but could not figure out if it was
possible to tell RAWR to compile to class files certain ruby code i.e.
my app’s source and not other ruby source i.e. source for gems

I guess I was hoping for some cookbook style recipe for the scenario
where one wants to deploy a non trivial Jruby app without source.

Maybe we can hash it out here and put it up on the wiki :slight_smile:

Charles M.
[email protected]

Charles, Id be surprised if you havent turned this up searching already,
but this article from the author of rawr is definitely the best
explanation
of its usage Ive seen: Getting Started with Rawr

Similarly, I’ve written about how to use the javafx packaging tools on
the
jruby wiki. Javafx comes with a bunch of ant tasks for packaging apps,
and
they are upgraded in jdk8 so that you can use them to package any java
app,
including jruby apps. I’ve described that here

As far as compiling to .class files go, there’s a lot of information
about
how to do that out there. You’ll probably want to do that in a rake
task,
as a prior step to building a jar, and then go from there to building
the
executable. There’s a good example of doing both of these things in the
Using Jruby book.

All of these things are going to take a bit of fiddling to get right on
a
per-app basis, which is probably why I doubt you will find the cookbook
style instructions for the entire process that you are hoping for. Best
of
luck to you.

Eric:

thanks, I will go thru all of this and the link you provided in the
other email.

We are a software vendor that develops enterprise financial apps our
source cannot be exposed never mind the possibility of reverse
engineering byte code. I just am not allowed to deploy anything that can
be un-archived to show source. I think that in general Ruby and Jruby
must be deployed typically in contexts that are controlled by the IP
owner and thus a generic solution for building a closed deliverable has
not been fully thought out.

I plan to put in github a couple projects that mimic the two deployment
contexts i.e. a server side Sinatra app and a Jrubyfx client UI and
figure out how to script a one button click build of a non-source code
exposed deliverable i.e compiled to .class files.

Hope folks will chime in.

thanks

Charles M.
[email protected]