I am using JRuby in an eclipse plugin for my product. I have a bunch of
scripts that define a DSL and perform operations for me. I want to be
to dynamically reload these scripts whenever required. The scripts could
change themselves on file system and moreover the location of the
could also change. I could even have multiple copies on file system of
slightly modified/changed scripts. Each time I want scripts from a
location to be utilized.
As I have understood so far, using “load” instead of “require” should do
the job. So now if before calling any Ruby methods/functions I use “load
‘XXX.rb’”, it will reload the XXX.rb utilizing the new changes.
In my code I am using ScriptingContainer to run scriplets to access ruby
functions. I set load paths on this scripting container to indicate from
which locations the scripts should be loaded. However, the problem is
on subsequent calls and even with different instances of
ScriptingContainer, I have noticed that the scripts that were loaded the
first time are utilized every time. “load” reloads them, but after
those scripts once, the next time I might need to load similar scripts
a different location but its not happening.
My assumption was that utilizing a different scripting container
should have done the job but it seems that the load paths are globally
somewhere and calling “setLoadPath” on new ScriptingContainer instances
either does not modify existing paths or only appends. If the latter
is true then probably when searching for scripts they are always found
oldest paths set and newer load paths get ignored.