Forum: JRuby Dynamically Adding Properties Files To Classpath

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
22db9ef38f6c2301ef7fd667f18874d2?d=identicon&s=25 Tom E Purl (Guest)
on 2009-01-06 22: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
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
2e793cdf2d72aecd526a081ae2f1865b?d=identicon&s=25 Johnny P (Guest)
on 2009-01-07 07: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/"].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 <tep2@ntrs.com> wrote:
> Tom Purl
---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email
22db9ef38f6c2301ef7fd667f18874d2?d=identicon&s=25 Tom E Purl (Guest)
on 2009-01-07 19:34
(Received via mailing list)
"Johnny P" <jpywtora@gmail.com> 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 :)  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.