8

It seems that one has to choose between "AspectJ project" which uses some Eclipse-specific configuration or "Maven project" and then trying to get the XML configuration for AspectJ right.

Is there some Eclipse feature that I'm missing or is there a "pre-made"/tutorial project which I can use as a start?

PS: I'm using Eclipse 3.7 (Indigo).

soc
  • 27,983
  • 20
  • 111
  • 215
  • If you're using Indigo, there's a new secret decoder ring and handshake necessary to use AspectJ. Basically, the m2e guys decided to break everything that generates code in Indigo, in order to make it better. I have an attitude problem on this - can you tell? Search here for AspectJ/Indigo/m2e-or-m2eclipse for more info - I don't want to link to anything in particular because it's evolving. – Ed Staub Jul 27 '11 at 13:19

1 Answers1

9

Here is the pom file I used to learn AspectJ.

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">

    <modelVersion>4.0.0</modelVersion>
    <groupId>com.kowsercse</groupId>
    <artifactId>hello-aop</artifactId>
    <version>0.0.1-SNAPSHOT</version>

    <properties>
        <java-version>1.6</java-version>
        <org.aspectj-version>1.6.9</org.aspectj-version>
    </properties>

    <dependencies>
        <!-- AspectJ -->
        <dependency>
            <groupId>org.aspectj</groupId>
            <artifactId>aspectjrt</artifactId>
            <version>${org.aspectj-version}</version>
        </dependency>
        <!-- Test -->
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.7</version>
            <scope>test</scope>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <configuration>
                    <source>${java-version}</source>
                    <target>${java-version}</target>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-dependency-plugin</artifactId>
                <executions>
                    <execution>
                        <id>install</id>
                        <phase>install</phase>
                        <goals>
                            <goal>sources</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>aspectj-maven-plugin</artifactId>
                <!--
                    Have to use version 1.2 since version 1.3 does not appear to work
                    with ITDs
                -->
                <version>1.2</version>
                <dependencies>
                    <!--
                        You must use Maven 2.0.9 or above or these are ignored (see
                        MNG-2972)
                    -->
                    <dependency>
                        <groupId>org.aspectj</groupId>
                        <artifactId>aspectjrt</artifactId>
                        <version>${org.aspectj-version}</version>
                    </dependency>
                    <dependency>
                        <groupId>org.aspectj</groupId>
                        <artifactId>aspectjtools</artifactId>
                        <version>${org.aspectj-version}</version>
                    </dependency>
                </dependencies>
                <executions>
                    <execution>
                        <goals>
                            <goal>compile</goal>
                            <goal>test-compile</goal>
                        </goals>
                    </execution>
                </executions>
                <configuration>
                    <outxml>true</outxml>
                    <source>${java-version}</source>
                    <target>${java-version}</target>
                </configuration>
            </plugin>
        </plugins>
    </build>
</project>
Kowser
  • 8,123
  • 7
  • 40
  • 63
  • Will this work with Eclipse 3.7? – soc Jul 27 '11 at 13:28
  • I am using eclipse helios with eclipse AJDT plugin. I don's see any specific issue, which will raise any problem to work with eclipse 3.7. I am going to upload the project after a while. – Kowser Jul 27 '11 at 15:30
  • I think you are just using eclipse to build your AspectJ maven project. If so, it wont be helpful, you must be needed the plugin. https://bitbucket.org/kowsercse/hello-aop – Kowser Jul 27 '11 at 16:28
  • 1
    Also be sure to do [Right-Click project] -> Configure -> Convert to AspectJ Project. You can have multiple project types operate concurrently, so doing this to an existing maven project is fine. Likewise an AspectJ project may be converted to a maven project via the equivalent process. – KomodoDave Aug 24 '12 at 19:59
  • 1
    I initially tried this POM but ran into problems, and the specific version amendments put me off. Now the docs have improved, it's better to use one of the example POMs provided by AspectJ Maven Plugin site, here's what I used successfully: http://mojo.codehaus.org/aspectj-maven-plugin/usingTogetherWithAJDT.html . Note you can `Right-Click project -> AspectJ Tools -> Configure AspectJ Build Path` to generate the necessary `build.properties` file referenced in the example POM entries at link. – KomodoDave Sep 02 '12 at 11:37
  • @KomodoDave broken link bro – MarcioB Oct 12 '16 at 15:41
  • non-broken link http://www.mojohaus.org/aspectj-maven-plugin/examples/usingTogetherWithAJDT.html – Joel Pearson Apr 13 '18 at 14:01