Jetty in 2 lines

So I built a wrapper for Maven’s Aether library (Naether) and then a
helper to access Jars (LockJar) and thought other JRubist might get a
kick out it.

To run the demo, you just need to gem install lock_jar and create a
index.html for Jetty in the dir you run IRB from.

Running Jetty in 2 lines In IRB (ok ok, 4 lines with requires):

require ‘rubygems’
require ‘lock_jar’
LockJar.load(nil) { jar
‘org.eclipse.jetty:example-jetty-embedded:jar:8.1.2.v20120308’ }
org.eclipse.jetty.embedded.FileServer.main([])

All the transitive dependencies will be downloaded from the Maven repos
and loaded into the classpath. The first time it runs Naether will chirp
about downloading the dependencies. Just have to start the demo Jetty
using FileServer and hit http://localhost:8080 to see the index.html you
created.

–M

That looks seriously cool – a jar equivalent of the Gemfile would go a
long way towards making my life a lot happier.

I am about to push a gem

-Kristian

where do I find you libs ? maybe we can share things between jbundler

  • somehow !

  • Kristian

Naether provides a wrapper for Maven’s Aether framework in Java and
Ruby.

LockJar is built on top of Naether to provide functionality to freeze
resolved jars and load them into the classpath

On Thu, Apr 19, 2012 at 8:02 AM, Michael Guymon
[email protected] wrote:

require ‘lock_jar/bundler’

where is this coming from ? it is not a “gem ‘lock_jar’” in Gemfile !

  • Kristian

So taking a look at jbundler inspired me to add Bundler support to
lock_jar. I went a more direct route, adding shims directly into Bundler
so that LockJar would shadow Bundler calls. You just have to set jar
dependencies using a lock_jar block in a Gemfile. Running bundle install
will create a Gemfile.lock and a Jarfile.lock (with transitive
dependencies). When Bundle.require is called, the Jarfile.lock will be
loaded to the classpath.

Gemfile:

This is what modifies Bundler to trigger LockJar

require ‘lock_jar/bundler’

gem “naether”

group :development do
gem “rspec”, “~> 2.9.0”
end

lockjar dsl that is used to create Jarfile.lock

lock_jar do
scope :test do
jar ‘junit:junit:jar:4.10’
end

 pom 'spec/pom.xml', :scope => :compile

end

Will produce a Gemfile.lock and Jarfile.lock for

bundle install

and to load the classpath when Bundler loads gems

require ‘rubygems’
require ‘bundler’

This is what modifies Bundler to trigger LockJar

require ‘lock_jar/bundler’

Bundler.require

The downside of this, all the shimming makes it brittle. It works for
the latest version of Bundler and future changes could break it.

–M

The lock_jar gem needs to be installed before you could use it with
Bundler