部分编译时编织第三方jar与maven

时间:2012-11-13 22:25:27

标签: java maven aspectj compile-time-weaving

我已经使用maven插件aspectj-maven-plugin配置编织第三方jar。

            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>aspectj-maven-plugin</artifactId>
                <version>1.4</version>
                <dependencies>
                    <dependency>
                        <groupId>org.aspectj</groupId>
                        <artifactId>aspectjrt</artifactId>
                        <version>${aspectj.version}</version>
                    </dependency>
                    <dependency>
                        <groupId>org.aspectj</groupId>
                        <artifactId>aspectjtools</artifactId>
                        <version>${aspectj.version}</version>
                    </dependency>
                </dependencies>
                <executions>
                    <execution>
                        <goals>
                            <goal>compile</goal>
                            <goal>test-compile</goal>
                        </goals>
                    </execution>
                </executions>
                <configuration>
                    <!--<proceedOnError>true</proceedOnError>-->
                    <weaveDependencies>
                        <weaveDependency>
                            <groupId>org.quartz-scheduler</groupId>
                            <artifactId>quartz</artifactId>
                        </weaveDependency>
                    </weaveDependencies>
                    <aspectLibraries>
                        <aspectLibrary>
                            <groupId>org.springframework</groupId>
                            <artifactId>spring-aspects</artifactId>
                        </aspectLibrary>
                    </aspectLibraries>
                    <source>1.6</source>
                    <target>1.6</target>
                </configuration>
            </plugin>

引用缺少的java类时出现问题。 Quartz jar与JMS有一些集成,但我的应用程序没有使用JMS,因此从不加载那些石英文件。

我发现了一个带有proceedOnError = true的拐杖,但我认为应该注意到弹出注入方面的注释类会停止工作。

shade-maven-plugin不适合这里,因为它只能由package阶段触发,而aspectj会在编译阶段启动。

[INFO] --- aspectj-maven-plugin:1.4:compile (default) @ aspectj-demo ---
[ERROR] can't determine implemented interfaces of missing type javax.servlet.ServletContextListener
when processing declare parents org.quartz.ee.servlet.QuartzInitializerListener
when processing type mungers 
when weaving 
when batch building BuildConfig[null] #Files=5 AopXmls=#0
 [Xlint:cantFindType]
[ERROR] can't determine implemented interfaces of missing type javax.servlet.http.HttpServlet
when processing declare parents org.quartz.ee.servlet.QuartzInitializerServlet
when processing type mungers 
when weaving 
when batch building BuildConfig[null] #Files=5 AopXmls=#0
 [Xlint:cantFindType]

1 个答案:

答案 0 :(得分:1)

weaveDependencies中列出的任何Maven坐标必须作为普通依赖项提及。根据下载页面,您需要在&lt; build&gt;:

下定义以下依赖项
<dependency>
    <groupId>org.quartz-scheduler</groupId>
    <artifactId>quartz</artifactId>
    <version>2.1.6</version>
</dependency>
<dependency>
    <groupId>org.quartz-scheduler</groupId>
    <artifactId>quartz-oracle</artifactId>
    <version>2.1.6</version>
</dependency>
    <dependency>
    <groupId>org.quartz-scheduler</groupId>
    <artifactId>quartz-weblogic</artifactId>
    <version>2.1.6</version>
</dependency>
<dependency>
    <groupId>org.quartz-scheduler</groupId>
    <artifactId>quartz-jboss</artifactId>
    <version>2.1.6</version>
</dependency>

然后在aspectj-maven-plugin插件的配置部分下,您可以引用包含您要编织的方面的JAR文件:

<weaveDependencies>
    <weaveDependency>
        <groupId>org.quartz-scheduler</groupId>
        <artifactId>quartz</artifactId>
    </weaveDependency>
</weaveDependencies>

您可能还需要使用1.2版本的aspectj-maven-plugin。据说1.4中有一个关于“声明父母”的错误(但不确定是否已经修复),1.3的早期版本遭受了MASPECTJ-90的错误。