Search code examples
eclipsebuildaspectjpde

How to enable AspectJ Compiler in PluginExport/Build


My first Question is: Does the "Export deployable plug-ins and fragments" function use the same generic Build script as the Product Export Functionality ?

My primary Question is: Why does the Export deployable plug-ins and fragments generate a jar with no .class files ?

In my project we use load time weaving, and after successful export of the Project, weaving is not applied. The reason is because my exported aspectj plugins have no .class files.

After much research the way how to do a aspectj aware Export is to define the AspectJ Compiler Adapter. It seems this Compiler is loaded and executed, but as result there are no .class files.

Someone has an idea whats missing ?

build.properties:

compilerAdapter=org.eclipse.ajdt.core.ant.AJDT_AjcCompilerAdapter
sourceFileExtensions=*.java, *.aj
source.. = src/
output.. = bin/
bin.includes = META-INF/,\
           .

Edit: If I rightklick on the Project an if I press "Generate Ant File" it generates sth like this in the @dot target:

<javac destdir="${build.result.folder}/@dot" failonerror="${javacFailOnError}" verbose="${javacVerbose}" debug="${javacDebugInfo}" includeAntRuntime="no" bootclasspath="${bundleBootClasspath}" source="${bundleJavacSource}" target="${bundleJavacTarget}" compiler="org.eclipse.ajdt.core.ant.AJDT_AjcCompilerAdapter"       >
        <compilerarg line="${compilerArg}" compiler="${build.compiler}"/>
        <classpath refid="@dot.classpath" />
        <src path="src/"            />
        <exclude  name="META-INF/MANIFEST.MF        ."          />
        <compilerarg value="@${basedir}/javaCompiler...args" compiler="org.eclipse.ajdt.core.ant.AJDT_AjcCompilerAdapter"           />
        <compilerarg line="-log &apos;${build.result.folder}/@dot${logExtension}&apos;" compiler="org.eclipse.ajdt.core.ant.AJDT_AjcCompilerAdapter"            />
    </javac>

I would say this looks correct, AJDT Compiler is set. If "compilerAdapter=org.eclipse.ajdt.core.ant.AJDT_AjcCompilerAdapter" isnot set in the Properties File at this point there would be the eclipse compiler instead.

After running this generated buildskript (i think "Export deployable Plugin..." will do the same) the only javac output i have got is: test\TestAspect.aj skipped - don't know how to handle it


Solution

  • I found a solution to this problem. It seems the AspectJ Compiler isnt started. After putting a Dummy.java File in src/ the AspectJ Compiler tries to compile all *.aj Files. Without Dummy.java it does not!

    After this step I saw more javac loging. And I saw the jre/lib..*.jars where missing in the classpath of the target. So I added into the build.properties File:

    compilerArg=-aspectpath ${bootclasspath}
    

    bootclasspath is a variable in the generated build script that contains all this standard java jars.

    This strange behavior took me a lot of time, hope someone will benefit from this.