Forum: JRuby Dynamically Adding Properties Files To Classpath

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
Tom E Purl (Guest)
on 2009-01-06 23:29
(Received via mailing list)
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
in the shell before I run the jruby executable, but it would be much
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
Johnny P (Guest)
on 2009-01-07 08:52
(Received via mailing list)
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/*.jar"]).each { |jar| $CLASSPATH << jar }

Hope this helps.

That should work.

On Tue, Jan 6, 2009 at 1:27 PM, Tom E Purl 
<removed_email_address@domain.invalid> wrote:
> Tom Purl
To unsubscribe from this list, please visit:
Tom E Purl (Guest)
on 2009-01-07 20:34
(Received via mailing list)
"Johnny P" <removed_email_address@domain.invalid> wrote on 01/07/2009 12:51:50 

> 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 :)  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
This topic is locked and can not be replied to.