Focus on Java, this Tuesday


This Tuesday is JFokus in Stockholm, where I will talk about Java, JRuby and RSpec and how to combine these in exciting ways. Let me tell you, I look forward to speaking about this. I believe there is something incredibly useful in combining technologies like this.

Of course, it would also have been great fun to take about where JRuby is at right now, since there is so much cool stuff going on at the moment. When the 0.9.3 release comes along, I bet many people will be surprised and as excited as I am about this. I will get back with more information what has happened in the codebase lately quite soon.

If you’re going to JFokus, please say hi if you see me!



Executing YARV (in JRuby)


I guess the title says it all. Oh, it doesn’t? You want what? A tutorial on how to play with this? Well, alright then.

What you will need to get started is first and foremost JRuby trunk. Download and build that. You will also need either a very recent version of YARV or Ruby trunk. Download either and build that too. I have the source in $YARV_SRC and $RUBY_TRUNK_SRC. I’ve also installed them with suffixes, so I have ruby-yarv and ruby-trunk globally available. That’s a quite good setup.

Before compiling some Ruby, we need to change the change the compile-script slightly. So open up the file in $YARV_SRC/tool/compile.rb and disable the peephole_optimization and inline_const_cache, since JRuby doesn’t really support these features yet. If you use Ruby trunk, you also need to do a global search-and-replace in this file, from YARVCore to VM.

Now you’re finished to compile something. The goal for this execution have been to get an iterative fibonacci sequence running, so save this code in a file called fib.rb:

def fib_iter_ruby(n)
i = 0
j = 1
cur = 1
while cur <= n
k = i
i = j
j = k + j
cur = cur + 1
end
i
end

puts fib_iter_ruby(5000)

Next, compile this file:

ruby-yarv $YARV_SRC/tool/compile.rb -o fib.rbc fib.rb

Modify as needed if you use Ruby trunk instead. Now, how to run this? With the y-flag to JRuby:

jruby -y fib.rbc

As you can see, simple files like this just work. Of course, there are much missing yet, but basic interpretation works really nice. Some more additions to the YARV machine will come quite soon, probably. But the next step will be to implement a compiler for YARV too. From that point it should be possible to execute Ruby-files in JRuby in several different ways; by regular interpretation, YARV compilation, YARV interpretation, Java bytecode AOT compiling, Java bytecode JIT compiling and also possibly Rubinius interpretation. The future is, as always, interesting.



I will present at JFokus


A few weeks ago I noted that Sun in Sweden announced on the JavaForum meetup that they were going to have a full day Java conference in January. This conference is called JFokus and will have 4 different tracks with 4 speakers on each track. I will feature in one of these tracks, talking about testing Java code with JRuby and RSpec, and also how to build a DSL for doing database integration testing using Ruby. I believe it will be very interesting, and the rest of the day looks incredible nice too.

So, if you’re in Sweden, Jan 30:th, look into it!

More information can be found at the official site: http://www.jfokus.se/.



Profile support in JRuby trunk


As noted a few posts ago, Sandbox has been ported and run in JRuby. You did need to use a special version, only available from a branch in the JRuby source tree. But now this support has been added to trunk. This means you can check out the latest version of JRuby trunk, gem install javasand, and everything will work.

For more info, see my previous post on this: here.



The Curse of Camping: The story continued


It’s time for another installment in the Camping saga. The last time I wrote about 1.5, and some things that didn’t work properly in JRuby. This time, the announcement is once again this: Camping 1.5 works in JRuby. It works very well, actually. To show this, I will make it very easy for you to follow along in how to achieve it.

First, have JRuby installed, either from trunk or version 0.9.2 if that version has been released when you read this.

Secondly, gem install ActiveRecord, Camping and all their requirements.

Thirdly, gem install ActiveRecord-JDBC.

Fourth, put you MySQL JDBC driver on your classpath (or any other JDBC driver you care to use).

Download blog.rb from the Camping examples here. Modify it by adding the line

require ‘jdbc_adapter’

after the other require’s at the head of the file.

Finally, you need to create a database file, since JRuby doesn’t support the standard choice of camping (which is SQLite3). To do this, create a file that’s named (on Linux) $HOME/.campingrc, or on Win32 %APPDATA%/Campingrc. (%APPDATA% is on most Win32-boxes something like c:\Documents and Settings\olagus\Application Data). This file should contain your database definition in standard ActiveRecord fare. My example looks like this:


database:
adapter: jdbc
driver: com.mysql.jdbc.Driver
url: jdbc:mysql://localhost:3306/blog
username: blog
password: blog

Of course, you should use your own individual settings and driver information.

Camping does only require that the database exists. It will add migrate the blog application automatically, and as soon as you’ve started the application by doing:

jruby $JRUBY_HOME/bin/camping blog.rb


it will listen on 3301 and be ready to serve an example blog application.

Have fun and enjoy!



Freaky freaky Sandbox has come to JRuby


I would like to announce the first release of JavaSand, which brings _why’s spooky Sandbox to JRuby.

For those of you who hasn’t played with Sandbox, it allows you to create a new area for executing Ruby where you have control on which classes are loaded and available. It’s good for lots of things. It can be made very secure, for example. Or you can load several applications in different Sandboxes and they won’t interfere with each other in any way.

Now, in MRI, this is done through some fairly involved swapping of symbol tables. In JRuby things are quite a lot easier. Actually, it’s only a matter of loading the right classes and remove all methods not allowed.

So, how do you get to use sandbox from JRuby? First of all, you need a special JRuby, that can be checked out and compiled from svn://svn.codehaus.org/jruby/branches/sandbox. This functionality will come to regular JRuby to, but not until after 0.9.2 has been released. So, when you have this special version downloaded, you just install the RubyGem called javasand, and you’re set to go. If you would like a fun example to try out, you can download sandbox_server directly from _why’s code repository http://code.whytheluckystiff.net/svn/sandbox/trunk/bin/sandbox_server. To run it:

jruby -rubygems sandbox_server

and you can connect to your machine at port 5000, press enter, and you have an IRB session. Wow!

So, the project JavaSand is part of JRuby-extras and the source is in that repository, at RubyForge! Go ahead and test it now!



The FINAL OpenSSL post?


Possibly.

I’ve checked in all functionality I will add to OpenSSL support in JRuby at this point. Of course, there will be more, but not concentrated in a spurt like this. Tomorrow I will modify the build process and then merge everything I’ve done into trunk.

Let’s back up a little. What have I accomplished? This: All OpenSSL tests from MRI run (except PKCS#7). That includes tests of SSL server and SSL client. Simple https-request also works. This is sweet. Everything else there is tests for in Ruby works. But… this is also the problem. Roughly half of Ruby’s OpenSSL library is not tested at all. And since the current OpenSSL initiative from my part is based on tests, I haven’t done anything that isn’t tested for.

So, some things won’t work. There is no support for Diffie-Hellman keys right now, for example. Will be easy to add when the time comes, but there isn’t any testing so I haven’t felt the need.

The only thing not there, as I said, is PKCS#7. That was just too involved. I’ll take care of that some other time, when someone says they want it… Or someone else can do it? =)

So, what this boils down too is that JRuby trunk will have OpenSSL support sometime tomorrow. Hopefully it will be useful and I can get on to other JRuby things. I have a few hundred bugs I would like to fix, for example…

Oh yeah, that’s true. Tomorrow will also be YAML day. I’ll probably fix some bugs and cut a new release of JvYAML. It’s that time, the bug count is bigger than it was, and JRuby needs some fixes. So that’s the order of day for tomorrow. First OpenSSL and then YAML. Any comments on this, please mail or comment directly here.

G’night.



JavaForum: last night


And now it’s over. Last night was the last presentation for me in a while. Over 200 people where there and the place was packed. I must say I’m very pleased with how my part went. I felt really good, much flow and the demonstrations went perfect.

Rob Harrop and Adryan Colyer talked about Spring 2.0 and AOP. It was fairly interesting, but since I’ve done some work with AOP before I felt that the level was a bit to introductory. No real meat.

JavaForum announced a day focused on Java in January, with four tracks and some great speakers. Looks very nice.



JRuby in Stockholm, JavaForum on Tuesday


On Tuesday it’s time for the big JavaForum in Stockholm. I’m looking very much forward to it and have spent some hours today sharpening the presentation. Of course it will be very interesting to see Rob Harrop too.

In other news, something quite exciting is probably just around the corner…



JRuby presence at JavaOne 2007


The call for papers went out two days ago, and we already have several good proposals in line that will be submitted to JavaOne. Hopefully we will get many interesting talks this year. As far as I know, there are at least 5 JRuby-specific proposals submitted, and there will hopefully be more.

I am sending in two different proposals this year, one about JRubyEE (it’s called “Agile Enterprise Development with JRuby”). That will be interesting to do and I really believe there is much for Java enterprise development to use in JRuby.

The second proposal is for a BOF about several JVM languages called “Lambda on the JVM: JRuby, Jython and Lisp”. I’ll talk about how to utilize different JVM alternative languages to do interesting and useful things. Since this is my venue, I will specialize on languages that are derived from Lisp (implicitly or explicitly). (I include both Ruby and Python in this category).

Hopefully at least one of the proposals will get through.