Note that there are some explanatory texts on larger screens.

plurals
  1. POLoad jar with root loader
    primarykey
    data
    text
    <p>I develop a library and one of its methods has the following form: </p> <pre><code>void setVars(def script) { // script parameter is an instance of groovy.lang.Script loaded by Rootoader // MyBinding is part of the lib and extends groovy.lang.Binding script.setBinding(new MyBinding()) } </code></pre> <p>Now, if the library is used as a jar file I get undefined method exception, as the script object is passed from the main application and is loaded by a RootLoader while MyBinding is loaded by <code>sun.misc.Launcher$AppClassLoader</code>, which is its child. Is there any way to load the whole jar using RootClass Loader? For some reason, <code>rootLoader.loadClass("MyBinding")</code> returns a class loaded by AppClassLoader and does not reload it.</p> <p>UPDATE with an example:</p> <p>S.script (created by a user):</p> <pre><code>println 1 </code></pre> <p>Main.groovy (created by the user):</p> <pre><code>class Main { static void main(String[] args) { Lib.setVars(S) } } </code></pre> <p>My lib.jar added by the user to a classpath:</p> <pre><code>class MyBinding extends Binding { //... } class Lib { static void setVars(Class scriptClass) { def script = scriptClass.newInstance() //Exception as MyBinding is loaded by MyBinding //while script class is loaded by RootLoaded script.setBinding(new MyBinding()) } } </code></pre> <p>Main.groovy is the file that is ran. I do it from eclipse where lib.jar is added to a project's classpath in a Java Build Path -> Libraries section (I expect users to use the library in this way or via maven).</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload