Can't you just update the iajc compilation target to use the new jar in the classpath?
It is not possible to make classloader prefer a given jar file over another. If you need to apply to multiple versions of the same class, you should consider OSGI.
The simplest solution would be to simply use the libraries from a project or Maven / Ivy repository and ignore the libraries in the global ant folder.
Example:
<taskdef resource="org/aspectj/tools/ant/taskdefs/aspectjTaskdefs.properties"> <classpath> <pathelement location="${basedir.dir}/lib/aspectjtools.jar"/> </classpath> </taskdef> <target name="compile" > <iajc outjar="demo.jar"> <sourceroots> <pathelement location="src" /> </sourceroots> <aspectpath> <pathelement location="aspects_to_be_weaved_with_classes_in_sourceroots.jar" /> </aspectpath> <classpath> <pathelement location="${basedir}/lib/aspectjrt.jar"/> </classpath> </iajc> </target>
Updated: You must also use a different Ant. If you are using Eclipse, try linking it directly from the ant view.
You also have another option, but it's a little trickier. This means that you should use AspectJ weaving instead. If you move on to this option, you can compile it with a normal compilation task, but at startup you need to do the binding using the JVM agent. You can learn more about this here .
Hope this helps!
Espen source share