如何让 AspectJ 和 Maven 参与 War 项目?

发布于 2024-12-24 21:35:43 字数 2401 浏览 1 评论 0原文

我有一个 Maven 项目,它编译为 webapp,具有标准 Maven war 布局。 我正在尝试向同一个项目添加方面,但当部署为 Tomcat 上的战争时,这些方面不会被触发。如果我将项目部署为 jar,方面就会启动。

这是我的 pom.xml 的样子

```

<groupId>in.sheki</groupId>
<artifactId>abc-service</artifactId>
<packaging>war</packaging>
<name>abc-service</name>

<properties>
    <aspectj.version>1.6.12</aspectj.version>
</properties>

<build>
    <finalName>abc-service</finalName>

    <plugins>
        <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>aspectj-maven-plugin</artifactId>
            <version>1.4</version>
            <configuration>
                <complianceLevel>1.6</complianceLevel>
            </configuration>
            <executions>
                <execution>
                    <phase>process-sources</phase>
                    <goals>
                        <goal>compile</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>2.3.2</version>
            <configuration>
                <source>1.6</source>
                <target>1.6</target>
                <encoding>UTF-8</encoding>
            </configuration>
        </plugin>
    </plugins>
</build>
<dependencies>
   <dependency>
        <groupId>org.aspectj</groupId>
        <artifactId>aspectjrt</artifactId>
        <version>${aspectj.version}</version>
    </dependency>
    <dependency>
        <groupId>org.aspectj</groupId>
        <artifactId>aspectjweaver</artifactId>
        <version>${aspectj.version}</version>
    </dependency> 
   ....
 </dependencies>
 </project>

```

方面在项目的包之一中定义为带有 @Aspect 注释的 JavaClass。

我可能做错了什么?

为了创建一个战争,我执行mvn clean install并将战争移动到webapps目录。 为了创建 Jar,我使用带有主类的程序集插件,这不会启动 HTTP 服务,而是启动代码中的其他进程。

I have a single maven project, which compiles to webapp, with the standard Maven war layout.
I am trying to add aspects to the same project but the aspects are not triggered when deployed as a war on Tomcat. If I deploy the project as a jar, the aspects kick in.

Here is how my pom.xml looks like

```

<groupId>in.sheki</groupId>
<artifactId>abc-service</artifactId>
<packaging>war</packaging>
<name>abc-service</name>

<properties>
    <aspectj.version>1.6.12</aspectj.version>
</properties>

<build>
    <finalName>abc-service</finalName>

    <plugins>
        <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>aspectj-maven-plugin</artifactId>
            <version>1.4</version>
            <configuration>
                <complianceLevel>1.6</complianceLevel>
            </configuration>
            <executions>
                <execution>
                    <phase>process-sources</phase>
                    <goals>
                        <goal>compile</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>2.3.2</version>
            <configuration>
                <source>1.6</source>
                <target>1.6</target>
                <encoding>UTF-8</encoding>
            </configuration>
        </plugin>
    </plugins>
</build>
<dependencies>
   <dependency>
        <groupId>org.aspectj</groupId>
        <artifactId>aspectjrt</artifactId>
        <version>${aspectj.version}</version>
    </dependency>
    <dependency>
        <groupId>org.aspectj</groupId>
        <artifactId>aspectjweaver</artifactId>
        <version>${aspectj.version}</version>
    </dependency> 
   ....
 </dependencies>
 </project>

```

The aspect is defined in one of the packages of the project as a JavaClass with @Aspect annotation.

What could be I doing wrong?

To create a war, I do mvn clean install and move the war to the webapps directory.
For creating a Jar, I use the assembly plugin with a Main Class, this does not start the HTTP services but starts the other processes in my code.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

看轻我的陪伴 2024-12-31 21:35:43

确保您有一个名为 war.bundle

true 的

属性,请查看 http:// /maven.apache.org/maven-1.x/plugins/aspectj/

如果您在没有 spring 的情况下运行,那么您可能需要 aop.xml,如中所述
http://ganeshghag.blogspot.in/2012/10 /demystifying-aop-getting-started-with.html

Make sure you have a property called war.bundle

true

Have a look on http://maven.apache.org/maven-1.x/plugins/aspectj/

If you are running without spring then you may require aop.xml as described in
http://ganeshghag.blogspot.in/2012/10/demystifying-aop-getting-started-with.html

难理解 2024-12-31 21:35:43

部署在 Tomcat(或据我所知的任何其他 Web 容器)上的 Wars 通过重新选择过程调用其方法,并且这种方式不会触发“call()”切入点。
尝试将您的“call()”切换为“execution()”,它在 Jonas 上为我工作,maven 通过货物处理部署。

Wars deployed on Tomcat (or any other web container as far as I know) have their methods called through the relection process, and that way does not trigger the "call()" pointcut.
Try switching your "call()" to "execution()", worked for me on a Jonas with maven handling the deployment via cargo.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文