如何使用AspectJ支持在Eclipse中创建Maven项目? [英] How to create a Maven project in Eclipse with AspectJ support?

查看:104
本文介绍了如何使用AspectJ支持在Eclipse中创建Maven项目?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

似乎必须在使用一些Eclipse特定配置或Maven项目的AspectJ项目之间进行选择,然后尝试获取AspectJ的XML配置。



是否有一些我缺少的Eclipse功能,还有一个预先制作的/教程项目可以作为一个开始?



PS :我正在使用Eclipse 3.7(Indigo)。

解决方案

这是我用来学习AspectJ的pom文件。 >

 < project xmlns =http://maven.apache.org/POM/4.0.0xmlns: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>

<依赖关系>
<! - AspectJ - >
<依赖关系>
< groupId> org.aspectj< / groupId>
< artifactId> aspectjrt< / artifactId>
< version> $ {org.aspectj-version}< / version>
< / dependency>
<! - Test - >
<依赖关系>
< 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>
<执行>
< 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>
<! -
必须使用版本1.2,因为1.3版本似乎没有工作
与ITDs
- >
< version> 1.2< / version>
<依赖关系>
<! -
您必须使用Maven 2.0.9或更高版本或这些被忽略(请参阅
MNG-2972)
- >
<依赖关系>
< groupId> org.aspectj< / groupId>
< artifactId> aspectjrt< / artifactId>
< version> $ {org.aspectj-version}< / version>
< / dependency>
<依赖关系>
< groupId> org.aspectj< / groupId>
< artifactId> aspectjtools< / artifactId>
< version> $ {org.aspectj-version}< / version>
< / dependency>
< / dependencies>
<执行>
< 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>


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

解决方案

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>

这篇关于如何使用AspectJ支持在Eclipse中创建Maven项目?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆