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
process:
http://grepcode.com/file/repo1.maven.org/maven2/org.apache.accumulo/accumulo-minicluster/1.5.0/org/apache/accumulo/minicluster/MiniAccumuloCluster.java#MiniAccumuloCluster.exec(java.lang.Class%2Cjava.lang.String[])

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

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

Is there a better way to do this?

Thanks,
Ariel V.
e-mail: [email protected]
website: http://blog.arielvalentin.com
skype: ariel.s.valentin
twitter: arielvalentin
linkedin: http://www.linkedin.com/profile/view?id=8996534

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

pry(main)> java.lang.System.properties[“java.class.path”]

=> “.:/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.lang.System.properties[“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
that
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]
website: http://blog.arielvalentin.com
skype: ariel.s.valentin
twitter: arielvalentin
linkedin: http://www.linkedin.com/profile/view?id=8996534

*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