Hi to everybody on the list,

I am forwarding the question I've asked on stackoverflow
http://stackoverflow.com/questions/15383099/ant-system-class-loader-does-not-honor-classpath-honors-localclasspath
as I did not have any feedback in several days. I hope I will find an
answer here.

Thanks in advance

------

I am implementing an ant task as a wrapper for another class, which
loads other several classes using the system class loader. Now, the
task is in the same jar of these other classes, so I wonder why it is
not finding them, since the task *is* running

Please notice that my classes are in the `$CLASSPATH` env variable.
The problem will not occur if I `export LOCALCLASSPATH=$CLASSPATH`

Minimal example:


    <taskdef name="mytask" classname="my.package.MyTask"  />

    <target name="compile">
        <mytask />
    </target>


you can easily see the problem here

    public class MyTask extends Task {
       public void execute() throws BuildException {
        try {
            ClassLoader cl = ClassLoader.getSystemClassLoader();

            // this will only print the ant jar file path
            for(URL url: ((URLClassLoader)cl).getURLs()){
                log(url.getFile());
            }

            cl.loadClass("my.package.OtherClass"); // throws an exception

        } catch (Exception ex) {
            throw new BuildException(ex);
        }
      }

    }

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscr...@ant.apache.org
For additional commands, e-mail: user-h...@ant.apache.org

Reply via email to