Forum: JRuby Can all Jruby apps be complied to class files ?

2d1b64aaf61046ad166db3009fa8c7dc?d=identicon&s=25 Charles Monteiro (Guest)
on 2013-09-26 03:22
(Received via mailing list)
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
C37cb1a6a19e23f067aae6ccb2d0de4b?d=identicon&s=25 Manuel Ramos (Guest)
on 2013-09-26 10:28
(Received via mailing list)
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 Monteiro" <jruby@smallruby.com> escribi:
8bc8621ef6a6d981a4a41c5069f530cf?d=identicon&s=25 Mark McCraw (Guest)
on 2013-09-26 14:30
(Received via mailing list)
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
B05d3cbc64b0031a24c2887fb6ddc173?d=identicon&s=25 christian (Guest)
on 2013-09-26 14:33
(Received via mailing list)
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
486ca04f06d968004643ce5b47376ded?d=identicon&s=25 Keith B. (keith_b)
on 2013-09-26 15:48
(Received via mailing list)
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 Dees, coauthor of the excellent JRuby book, explained this to me at
CukeUpNYC a couple of weeks ago.

- Keith
C37cb1a6a19e23f067aae6ccb2d0de4b?d=identicon&s=25 Manuel Ramos (Guest)
on 2013-09-26 16:22
(Received via mailing list)
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 Bennett" <keithrbennett@gmail.com> escribi:
0c1520038e7f70997042b0c9e721df76?d=identicon&s=25 James Britt (Guest)
on 2013-09-26 17:23
(Received via mailing list)
Charles Monteiro 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 Britt



--

Neurogami - Avant-garage Research & Development

http://www.neurogami.com

james@neurogami.com
0c1520038e7f70997042b0c9e721df76?d=identicon&s=25 James Britt (Guest)
on 2013-09-26 17:27
(Received via mailing list)
Keith Bennett 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 Britt


--

Neurogami - Avant-garage Research & Development

http://www.neurogami.com

james@neurogami.com
B05d3cbc64b0031a24c2887fb6ddc173?d=identicon&s=25 christian (Guest)
on 2013-09-26 18:14
(Received via mailing list)
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.
2d1b64aaf61046ad166db3009fa8c7dc?d=identicon&s=25 Charles Monteiro (Guest)
on 2013-09-27 03:25
(Received via mailing list)
but does it have the option of compiling the app's ruby source to .class
files ?

thanks

Charles Monteiro
jruby@smallruby.com
C37cb1a6a19e23f067aae6ccb2d0de4b?d=identicon&s=25 Manuel Ramos (Guest)
on 2013-09-27 10:18
(Received via mailing list)
As i said before to get easily a class... Jrubyc
https://github.com/jruby/jruby/wiki/JRubyCompiler

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 Monteiro" <jruby@smallruby.com> escribi:
B05d3cbc64b0031a24c2887fb6ddc173?d=identicon&s=25 christian (Guest)
on 2013-09-27 11:21
(Received via mailing list)
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 ;)
0c1520038e7f70997042b0c9e721df76?d=identicon&s=25 James Britt (Guest)
on 2013-09-27 16:58
(Received via mailing list)
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

http://www.neurogami.com

james@neurogami.com
B05d3cbc64b0031a24c2887fb6ddc173?d=identicon&s=25 christian (Guest)
on 2013-09-27 17:14
(Received via mailing list)
just pushed a jbundler-0.5.3 which can compile the ruby classes before
packing them into the exectuable jar
B05d3cbc64b0031a24c2887fb6ddc173?d=identicon&s=25 christian (Guest)
on 2013-09-27 17:28
(Received via mailing list)
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
2d1b64aaf61046ad166db3009fa8c7dc?d=identicon&s=25 Charles Monteiro (Guest)
on 2013-10-02 20:15
(Received via mailing list)
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 Monteiro
jruby@smallruby.com
2d1b64aaf61046ad166db3009fa8c7dc?d=identicon&s=25 Charles Monteiro (Guest)
on 2013-10-02 23:18
(Received via mailing list)
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 :)



Charles Monteiro
jruby@smallruby.com
C983ad33b47479f17a28e083e1bb3d8b?d=identicon&s=25 Eric West (edubkendo)
on 2013-10-03 04:25
(Received via mailing list)
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](
http://neurogami.com/blog/getting-started-with-rawr.html)

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](
https://github.com/jruby/jruby/wiki/Packaging-Nati...
)

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.
2d1b64aaf61046ad166db3009fa8c7dc?d=identicon&s=25 Charles Monteiro (Guest)
on 2013-10-03 12:06
(Received via mailing list)
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 Monteiro
jruby@smallruby.com
Please log in before posting. Registration is free and takes only a minute.
Existing account

NEW: Do you have a Google/GoogleMail, Yahoo or Facebook account? No registration required!
Log in with Google account | Log in with Yahoo account | Log in with Facebook account
No account? Register here.