ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Rainer Noack <rai...@noacks.net>
Subject Re: Ant System Class Loader does not honor $CLASSPATH, honors $LOCALCLASSPATH
Date Tue, 26 Mar 2013 22:43:31 GMT
Hi Edoardo,

if you're launching ant via shell script, it is using 
oata.launcher.Launcher.java

This class reorganises the classpath a bit.
The env variable CLASSPATH and the classpath commandline argument are 
stripped and replaced by the minimum classpath used to launch ant.
A child classloader of the system classloader is created with the 
original CLASSPATH entries.
The oata.Project is then loaded with this classloader.

Hope that helps

Rainer


Am 26.03.2013 18:25, schrieb Edoardo Vacchi:
> 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-unsubscribe@ant.apache.org
> For additional commands, e-mail: user-help@ant.apache.org
>


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


Mime
View raw message