Reputation: 16002
I am trying to use javac to compile a set of java files to .class files and then subsequently use iajc to compile and weave all the aspects. My ant build.xml looks like this.
The compile part:
<target name="compile" depends="init" description="compile the source ">
<!-- Compile the java code from ${src} into ${target} -->
<javac srcdir="${src}" destdir="${target}" debug="true">
<classpath refid="project.class.path" />
</javac>
</target>
The iajc part:
<target name="aspects">
<mkdir dir="dist"/>
<iajc source="1.6" target="${asptarget}">
<inpath>
<pathelement location="${target}"/>
</inpath>
<sourceroots>
<fileset dir="${src}">
<include name="**/*.aj"/>
</fileset>
</sourceroots>
<classpath>
<pathelement location="${aspectj.home}/lib/aspectjrt.jar"/>
</classpath>
</iajc>
</target>
Judging by the error message, I am not getting this correct. The sourceroots are wrong! How can I compile just the .aj files with aspectj and then binary weave the class files and compiled .aj files? Is that possible without recompiling all the original java sources too?
Upvotes: 1
Views: 1938
Reputation: 16002
If you want to use the regular compiler for building .java files and iajc to build .aj files you do this:
<target name="aspects" depends="compile" description="build binary aspects">
<fileset id="ajFileSet" dir="${src}" includes="**/*.aj"/>
<pathconvert pathsep="${line.separator}" property="ajFiles" refid="ajFileSet"/>
<echo file="${src}/aj-files.txt">${ajFiles}</echo>
<iajc source="1.6" target="${asptarget}">
<argfiles>
<pathelement location="${src}/aj-files.txt"/>
</argfiles>
<classpath>
<pathelement path="${target}"/>
<fileset dir="lib" includes="**/*.jar"/>
</classpath>
<classpath>
<pathelement location="${aspectj.home}/lib/aspectjrt.jar"/>
</classpath>
</iajc>
</target>
Works perfectly by building a file containing a list of the .aj files and compiling them. You can then use runtime OR binary weaving to finish the process.
Upvotes: 1