2011-11-16 96 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