Converting a jRuby main.rb file to an exe file

First of, let me introduce myself as a complete noob at JRuby… and
software development. I somehow managed to figure out how to use jruby
using NetBeans and downloaded some gems for Excel and MS Access related
work, but now I"m stuck with a problem that I cannot seem to find a
solution to - converting my JRuby code (which is a main.rb file) to an
exe file that can be executed on any Windows machine.

I did install warble and tried to figure it out but from what I
understand, it’s used for only converting rails projects, and all I have
is a standalone main.rb file written using JRuby. There were some pretty
easy solutions for regular Ruby, though I’d prefer to stick to JRuby as
I can have the freedom of moving between Java or Swing and Ruby if I
need to.

I’m not familiar with the command line, so if there isn’t a one-click
exe installer or something, please do let me know what I need to do. If
I can do it all from NetBeans, that would be great, but if I need to
move out of my shell (and though ironic, I’m not referring to Linux
terminology here), it’s going to need some detailed directions (I
just figured out how to navigate between directories using the CD
command today)!

Any help would be greatly appreciated.

I didnt read it all but searching for ruby to exe will provide you some
results…

regards
Peter

2012/1/31 Farsheed B. [email protected]

Peter Lamber wrote in post #1043242:

I didnt read it all but searching for ruby to exe will provide you some
results…

regards
Peter

2012/1/31 Farsheed B. [email protected]

Yeah, I did search for that and a number of other things but those
converters only work for Ruby, not for JRuby.

There are some tools that can turn Java (or JRuby) applications into
.exe files. But I’m not familiar with them because most Java (and
JRuby) applications are not delivered to customers as .exe files.

One of the big advantages of Java (and JRuby) is that it runs pretty
much the same on lots of Operating Systems. So the most common way to
deliver a program is as an executable .jar file. You can create one of
these with Warbler (without Rails). The command is something like this:

C:> warble executeable jar

And it can be run by double-clicking (i think) or with this command:

C:> java -jar myapp.jar

You’ll have to do some reading on Warbler to set this up:

Hope that helps.

Joe K. wrote in post #1043300:

There are some tools that can turn Java (or JRuby) applications into
.exe files. But I’m not familiar with them because most Java (and
JRuby) applications are not delivered to customers as .exe files.

One of the big advantages of Java (and JRuby) is that it runs pretty
much the same on lots of Operating Systems. So the most common way to
deliver a program is as an executable .jar file. You can create one of
these with Warbler (without Rails). The command is something like this:

C:> warble executeable jar

And it can be run by double-clicking (i think) or with this command:

C:> java -jar myapp.jar

You’ll have to do some reading on Warbler to set this up:
GitHub - jruby/warbler: Warbler chirpily constructs .war files of your Ruby applications.

Hope that helps.

Thanks for the response. I tried what you suggested and received an
error saying “warbler is not recognized as an internal or external
command”

I then visited the site you linked me to (I had been there earlier as
well) and it read, “Warbler’s warble command is just a small wrapper
around Rake with internally defined tasks.” I have never used rake, so
I’m not sure about how to proceed.

I understand that most professional developers would already be familiar
with most of these concepts, but for a complete non-programmer like me,
there’s nothing less productive than spending a couple of weeks just
setting up stuff to allow me to get started on something I could have
done in less than half an hour with Java.

To be honest, all I was really looking for was a simple easy-to-learn
programming language that would let me make some very simple, basic
programs requiring Excel manipulation and distribute them as exe files.
I decided to select jRuby as my language of choice as I was told it’s
the simplest and fastest to use.
Who told you this? Honestly, if you know neither Ruby nor Java, JRuby is
not necessarily going to be the best starting point. Also, I’m not sure
what kind of Excel manipulation you mean; if you are talking about
controlling the application with Win32::OLE then you’ll certainly want
Ruby as opposed to JRuby.

I disagree.

C:\Users\Jon>jruby --version
jruby 1.6.6 (ruby-1.8.7-p357) (2012-01-30 5673572) (Java HotSpot™
Client VM 1.7.0_02) [Windows 7-x86-java]

C:\Users\Jon>jruby -S gem install jruby-win32ole
Fetching: jruby-win32ole-0.8.5.gem (100%)
Successfully installed jruby-win32ole-0.8.5
1 gem installed

C:\Users\Jon>jirb
irb(main):001:0> require ‘win32ole’
=> true
irb(main):002:0> xls = WIN32OLE.new “Excel.Application”
=> #WIN32OLE:0x83e733
irb(main):003:0> xls.visible = true
=> true
irb(main):004:0> wb = xls.workbooks.add()
=> #WIN32OLE:0x78e1b5
irb(main):005:0> ws = wb.worksheets(1)
=> #WIN32OLE:0x16eb456
irb(main):006:0> (1…4).each { |i| ws.columns(1).cells(1).value = i }
=> (1…4)

But going by what this and other past
experiences have shown me, Ruby is a lot more complex to set up and get
started with than any other popular language out here. There doesn’t
appear to be any simple, straightforward single-click installer or tool
for anything, and almost everything in Ruby needs command line usage,
which really just beats the whole purpose of a simple easy-to-use tool
for a noob like me. :frowning: There’s no such thing as a single exe installer
that sets everything up for you. I need to manually set up the whole
thing, starting from gems, the ruby installation, a rails framework
perhaps and now even rake.

I think you’re discounting your ability learn and make progress.

It’s true that the RubyInstaller (http://rubyinstaller.org) Mike
mentions is an easy way to install Ruby on Windows, but you still need
to customize your environment by installing gems and other things
specific to what you’re trying to do. The JRuby team also makes
easy-to-use Windows installers for 32/64bit and with and without an
embedded JRE.

Take small steps, keep your initial expectations in check, read the
existing documentation at Home · jruby/jruby Wiki · GitHub use this
ML and Ruby - Ruby-Forum and remember search engines
are your friends.

And always first try things out on your own, but don’t struggle too long
before asking for help by providing specifics of your setup and sample
code.

I think you’ll be pleasantly surprised how quickly you become skilled
with the command line. And who knows, you may actually start to love the
simplicity and power of CLI’s :wink:

Step 1 → http://jruby.org/download
Step 2 → play…

Jon


Fail fast. Fail often. Fail publicly. Learn. Adapt. Repeat.
http://thecodeshop.github.com | http://jonforums.github.com/
twitter: @jonforums

On 01/31/2012 03:40 PM, Farsheed B. wrote:

To be honest, all I was really looking for was a simple easy-to-learn
programming language that would let me make some very simple, basic
programs requiring Excel manipulation and distribute them as exe files.
I decided to select jRuby as my language of choice as I was told it’s
the simplest and fastest to use.
Who told you this? Honestly, if you know neither Ruby nor Java, JRuby is
not necessarily going to be the best starting point. Also, I’m not sure
what kind of Excel manipulation you mean; if you are talking about
controlling the application with Win32::OLE then you’ll certainly want
Ruby as opposed to JRuby.
But going by what this and other past
experiences have shown me, Ruby is a lot more complex to set up and get
started with than any other popular language out here. There doesn’t
appear to be any simple, straightforward single-click installer or tool
for anything, and almost everything in Ruby needs command line usage,
which really just beats the whole purpose of a simple easy-to-use tool
for a noob like me. :frowning: There’s no such thing as a single exe installer
that sets everything up for you. I need to manually set up the whole
thing, starting from gems, the ruby installation, a rails framework
perhaps and now even rake.
Now that you’re mentioning Ruby as opposed to JRuby, I can tell you this
is simply not true. I assume you’re on Windows? Install Ruby with
RubyInstaller (www.rubyinstaller.org). If you want to make a
distributable .exe use OCRA (http://ocra.rubyforge.org/)

Via a simple editor that can execute Ruby scripts like Scite, or a more
sophisticated IDE (RubyMine) you don’t have to use a command line often,
although I highly recommend you learn how to interact with a command
line.

Given your use case, I’m not sure why you even want to mess around with
a web framework like Rails at all.

I understand that most professional developers would already be familiar
with most of these concepts, but for a complete non-programmer like me,
there’s nothing less productive than spending a couple of weeks just
setting up stuff to allow me to get started on something I could have
done in less than half an hour with Java.
LOL. Certain developer concepts will have to be learned, no matter the
language you decide to take on. One book I recommend is Learn to Program
by Chris P… It is a great introduction to programming in general,
using Ruby as the implementation language. It’s an easy read.

Good luck,

– Mark.

Thanks a million for all your answers, Jon and Mark! As you can see in
some of the posts above, there were people who advised me to go for
JRuby over Ruby and some that said otherwise. I had most of my stuff set
up with NetBeans, so it was pretty simple and straightforward to get
started with learning basic coding.

I got pretty comfortable with JRuby recently and hit a wall when it came
to making deployable exe files with it. As some mentioned, Ruby is the
easier option here. If only JRuby had the same tools, my experience with
it would have probably been a lot more pleasant. In fact, if I had an
easy way of creating an exe file to distribute my code (without rake),
I’d be happier than ever with JRuby right now.

I’ve made a note of the material you’ve told me about and will look it
up.
Thanks for the answers! :slight_smile:

On Wed, Feb 1, 2012 at 8:15 PM, Farsheed B. [email protected]
wrote:

it would have probably been a lot more pleasant. In fact, if I had an
easy way of creating an exe file to distribute my code (without rake),
I’d be happier than ever with JRuby right now.

My 2 cents on how we’re using jruby at my day job…

Mixing jruby with java libraries (like http://poi.apache.org) would
reveal its true power…

We’ve been making executable by:

  • using jruby-complete.jar (it’s a zip: next lines tweak the content)
  • adding our ruby app
  • tweak manifest.mf to point to our main app class
  • include/merge poi library and any gem needed on top of the zip
  • use launch4j to convert this into an exe

It’s a very dirty approach, which could be scripted using jruby itself.

But with this approach we managed to deliver a neat app connecting to
SQL databases and report metrics using excel. The only drawback is the
app size, bigger than original jruby-complete.jar, but the end users
don’t even need to install jruby.

I doubt I could have ever done this as efficiently and as quickly with
ruby MRI.


Christian

SUCCESS! :smiley:

I finally managed to get this to work. I went back to the basics (thanks
for the advice, Jon) and read up on what rake is and what build tools
are for. I had no idea as to what rake was all about before that. I
found a rake file in my project folder that was created automatically by
my IDE (NetBeans), so I tried to run warbler in the same directory.

At first, it failed. A little looking around online led me to an article
wherein the author mentioned that warbler expects the JRuby code to be
in a bin folder. My IDE had created the .rb file in a lib folder
instead. I manually created a new bin folder and copied the .rb file
into it and ran warbler again. It worked! :slight_smile:

I’m able to run the JAR files in the command prompt window, either using
the command line editor or by using an application I downloaded that
converts the JAR file into an EXE. However, I had a GUI-ased file that I
made using JRuby and Swing that did not work in either the CLE or the
converter app when I tried launching it. The command line editor would
just freeze indefinitely, while the EXE file would show the initial
splash screen and then disappear. Would anyone be able to guide me as to
why this is happening and what I should be doing to correct this?

Just an update - apart from a basic hello world kind of program, none of
the other programs seem to work at all with warbler converted JARs or
the equivalent EXEs. I tried to run an MS Access and Excel manipulation
program I wrote and tested successfully in NetBeans and it did not work
at all. In fact, I even copied the Access and Excel files to the
corresponding folder so that the relative positions of the files would
be the same as before it was converted, but it still didn’t work. :frowning: Any
idea what the issue could be? It seems to work normally within the IDE,
but doesn’t do the same once it’s packaged.

On 02/01/2012 05:33 PM, Christian MICHON wrote:

  • use launch4j to convert this into an exe

It’s a very dirty approach, which could be scripted using jruby itself.

But with this approach we managed to deliver a neat app connecting to
SQL databases and report metrics using excel. The only drawback is the
app size, bigger than original jruby-complete.jar, but the end users
don’t even need to install jruby.

I doubt I could have ever done this as efficiently and as quickly with ruby MRI.

That’s really neat. I hadn’t heard of Launch4j. And you’re right–that’s
a pretty nice way to boil it all down to a .exe that is completely
self-contained.

One thing that I’m not sure I saw mentioned here is that JRuby has a
compiler. jrubyc some.rb will compile your ruby code to java class file
some.class Then you could just jar it it up to an executable jar file.
A good book for JRuby is on the Pragmatic Programmers web site named
Using JRuby. The details are in there. Hope that this will help someone
interested in Java and Ruby. You may go either way with your code. Run
Ruby from Java or run Java from Ruby.

I have shifted the new issue I described in the above posts to a new
thread dedicated to it. Please post any responses related to the
related issue here:

http://www.ruby-forum.com/topic/3567279#1043771

I’m sure there’s a jrubyc compiler and you can get a jar from it then
using Jruby complete jar at your classpath you can create an exe using
tools as Lauch4j or similars… I have used this proceed and works for
me free time project…

You can see a example here…

on windows installer only of course…

Reggards

El 24/04/14 02:04, Douglas Allen escribi??: