2011-11-16 83 views
1

我想用javac编译一组java文件到.class文件,然后使用iajc编译和编织所有方面。我的ant build.xml看起来像这样。将.aj文件编织到现有的javac编译源

的编译部分:

<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> 

的iajc部分:

<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> 

由错误信息来看,我没有得到这个正确的。源根错误! 如何使用aspectj编译.aj文件,然后编译类文件和编译的.aj文件?有可能没有重新编译所有原始的Java源代码?

回答

1

如果你想使用常规的编译器来编译.java文件和iajc建立.aj文件,你这样做:

<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> 

完美的作品通过构建包含.aj文件列表的文件,编译它们。然后可以使用运行时或二进制编织来完成该过程。

+0

你能帮助我,这个问题吗?http://stackoverflow.com/questions/38930247/when-run-ant-script-aspectj-not-import-aspect-source-folder-out-side-java-class – uma