Hi. First, sorry my English, it's not my native languaje.
Second, after hours trying, I managed to compile with AspectJ in NetBeans 6.9.1
Now I'll show the way to make it possible. But I want to clarify that I wont install a NetBeans's plugin, but it is the way to make it possible to compile aspects in netbeans with AspectJ. Now, let's go on the steps:
1) Download the AspectJ Latest Stable Release, on this page.
2) Unzip de ".jar" file in the directory you like to put your libraries. It should not be in the proyect's lib directory, because you may want to use it in other projects too. You will unzip about 4 ".jar" files.
3) Create a project in netbeans, just a simple "Java Project".
Now listen, you have to follow the next steps in every new project you make:
4) Go to the project's propierties and in the libraries panel, select the "Add Jar/Folder". Now, select this files from the unzipped file:
- aspectjrt.jar
- aspectjtools.jar
- org.aspectj.matcher.jar
5) Once this files were added, you must edit the build.xml file created inside you project directory.
6) Between the tags <project> and </project> paste this code:
<taskdef classpath="/home/ignacio/NetBeansProjects/lib/aspectj/aspectjtools.jar"
resource="org/aspectj/tools/ant/taskdefs/aspectjTaskdefs.properties"/>
<target name="aspectj">
<echo level="info">--- aspectj (start) ---</echo>
<iajc destDir="${build.classes.dir}">
<inpath>
<pathelement location="/home/ignacio/NetBeansProjects/lib/aspectj/aspectjrt.jar"/>
<pathelement location="${build.classes.dir}" />
</inpath>
<sourceroots>
<pathelement location="${src.dir}"/>
</sourceroots>
<classpath>
<pathelement location="${javac.classpath}"/>
<pathelement location="${j2ee.platform.classpath}"/>
</classpath>
</iajc>
<echo level="info">--- build.xml by Ignacio Rigoni email: {name}.{lastname}@gmail.com ---</echo>
</target>
<target name="-post-compile" depends="aspectj"></target>
So the complete build.xml file can be like this:
<?xml version="1.0" encoding="UTF-8"?>
<project name="pruebaAspectJ_nb6.9.1" default="default" basedir=".">
<description>Builds, tests, and runs the project pruebaAspectJ_nb6.9.1.</description>
<import file="nbproject/build-impl.xml"/>
<taskdef classpath="/home/ignacio/NetBeansProjects/lib/aspectj/aspectjtools.jar"
resource="org/aspectj/tools/ant/taskdefs/aspectjTaskdefs.properties"/>
<target name="aspectj">
<echo level="info">--- aspectj (start) ---</echo>
<iajc destDir="${build.classes.dir}">
<inpath>
<pathelement location="/home/ignacio/NetBeansProjects/lib/aspectj/aspectjrt.jar"/>
<pathelement location="${build.classes.dir}" />
</inpath>
<sourceroots>
<pathelement location="${src.dir}"/>
</sourceroots>
<classpath>
<pathelement location="${javac.classpath}"/>
<pathelement location="${j2ee.platform.classpath}"/>
</classpath>
</iajc>
<echo level="info">--- build.xml by Ignacio Rigoni email: {name}.{lastname}@gmail.com ---</echo>
</target>
<target name="-post-compile" depends="aspectj"></target>
</project>
7) Now, modify the lines 7 and 14. In line 7 you must specify the "aspectjtools.jar" with the full path. This is where you unzipped aspectj. In line 14 you must do the same, but pointing to the "aspectjrt.jar" file.
8) That's all.
Considerations
1) Use the aspect{version}.jar file, no the aspectj{version}-src.jar file.
2) Be careful with the paths, it always cause problems!
3) I'm not shure, but may be possible that the other lines you added in build.xml could have errors. It worked fine for me, but may be it depends on the project, so if that causes a problem, you should check the dirs, and other possible error sources.
I wish this helps you! Please, come back and comment or suggest if you think this could be improved in any way.
I also struggled with this. Your solution worked on the first try. Muchos gracias!
ResponderEliminar