Pergunta

I've configured weaving third party jar with maven plugin aspectj-maven-plugin.

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

There is a problem with references to missing java classes. Quartz jar has some integration with JMS but my application doesn't use JMS so those quartz files are never loaded.

I've found a crutch with proceedOnError = true but I think due errors spring injection into aspect annotated class stops workings.

shade-maven-plugin doesn't fit here because it could be triggered by package phase only and aspectj launches on compile one.

[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]
Foi útil?

Solução

Any Maven coordinate listed in weaveDependencies must also be mentioned as a normal dependency. Based on the download page, you will need to have the following dependencies defined under <build>:

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

Then under your configuration section for the aspectj-maven-plugin plugin, you can reference the JAR file that contains the aspects that you want to weave:

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

You may also need to use the 1.2 version of the aspectj-maven-plugin. Supposedly there is a bug in 1.4 about "declare parents" (but not sure if that's been fixed), and early versions of 1.3 suffered from the bug known as MASPECTJ-90.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top