Dynamically Adding Properties Files To Classpath

I am writing a script that references a few Java libraries that expect
some “.properties” files to be in the classpath. I can set the
classpath
in the shell before I run the jruby executable, but it would be much
nicer
if I could dynamically reference the “.properties” files from my script.
Does anyone know how you can add a file that isn’t a class or a jar to
your classpath dynamically?
Thanks in advance!
Tom Purl

I just append to $CLASSPATH like so

$CLASSPATH << “path/to/properties”

or get fancier with something like

#!/usr/bin/env jruby

require ‘java’

[“#{File.dirname FILE}/…/build/”, “#{File.dirname
FILE}/…/lib/”].concat(Dir[“#{File.dirname
FILE}/…/lib/*.jar”]).each { |jar| $CLASSPATH << jar }

Hope this helps.

That should work.

On Tue, Jan 6, 2009 at 1:27 PM, Tom E Purl [email protected] wrote:

Tom Purl


To unsubscribe from this list, please visit:

http://xircles.codehaus.org/manage_email

“Johnny P” [email protected] wrote on 01/07/2009 12:51:50 AM:

I just append to $CLASSPATH like so

$CLASSPATH << “path/to/properties”

Thanks Johnny! That worked like a charm. I’m now able to add all of
the properties files to my app at runtime.

or get fancier with something like

#!/usr/bin/env jruby

require ‘java’

[“#{File.dirname FILE}/…/build/”, “#{File.dirname
FILE}/…/lib/”].concat(Dir[“#{File.dirname
FILE}/…/lib/*.jar”]).each { |jar| $CLASSPATH << jar }

Wow. That was a little scary :slight_smile: I also found the following line for
importing all of your jar files:

Dir['lib/java/*.jar'].each { |jar| require jar }

Thanks again!

Tom Purl