How does require work with jars and the classpath?

Fellow Rubyists!

I am working with Apache Accumulo, which uses ProcessBuilder to launch a
separate JVM that hosts a mini-cluster. The Accumulo code uses the
“java.class.path” System property to propagate dependencies to the child

As part of my code I require all of the necessary jars however they are
added to the System property “java.class.path”, which results in me
to add them explicitly:

full_classpath = [[‘java.class.path’],
File.join(File.expand_path(’…/…/vendor/jars-test’, FILE), ‘*’)][‘java.class.path’] =

Is there a better way to do this?

Ariel V.
e-mail: [email protected]
skype: ariel.s.valentin
twitter: arielvalentin

You can add those from the command line and they should work, like this:

$ jruby -J-cp .:/home/eric/installs/hawtio/hawtio-app-1.2.1.jar -S pry


=> “.:/home/eric/installs/hawtio/hawtio-app-1.2.1.jar:”

Or, you can set the CLASSPATH environment variable with the needed jars:

$ export CLASSPATH=".:/home/eric/installs/hawtio/hawtio-app-1.2.1.jar"

$ pry

[1] pry(main)>[“java.class.path”]

=> “.:/home/eric/installs/hawtio/hawtio-app-1.2.1.jar:”

Jars that get required from within a ruby file go to the $CLASSPATH
rubyvariable, while jars added to the classpath via the command line
or the
CLASSPATH environment variable get added directly to the
java.class.pathproperty. I dont know how it all works but this should
help you out. You
could set the environment var CLASSPATH in a bash script or something
gets used to start your app to make it a bit more portable.

Hope this was helpful.

It was very helpful thank you.

Ariel V.
e-mail: [email protected]
skype: ariel.s.valentin
twitter: arielvalentin

*simplicity *communication
*feedback *courage *respect

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs