gpt4 book ai didi

java - Maven AspectJ 编织 NullPointerException

转载 作者:行者123 更新时间:2023-11-30 07:21:18 27 4
gpt4 key购买 nike

我有一个用 MyEclipse 制作的 Spring MVC 应用程序,其中包含生成的源代码以及我自己的源代码,以及我在生成的类上定义的方面。一切都在 MyEclipse 中编译得很好,但我现在想切换到 Maven 以使用持续集成服务器。

我已经摆弄 pom.xml 很长一段时间了,但我碰了壁,似乎无法绕过。当 Maven 进入编织方面时,我得到以下异常(为简洁起见,仅前几行):

[INFO] [aspectj:compile {execution: default}]
[INFO] Showing AJC message detail for messages of types: [error, warning, fail]
[ERROR] ABORT
May 30, 2016 11:48:05 AM org.aspectj.weaver.tools.Jdk14Trace info
INFO: Dumping to /var/atlassian/application-data/bamboo/xml-data/build-dir/OW-BUIL-JOB1/./ajcore.20160530.114805.876.txt
[INFO] ------------------------------------------------------------------------
[ERROR] BUILD ERROR
[INFO] ------------------------------------------------------------------------
[INFO] AJC compiler errors:
abort ABORT -- (NullPointerException) null
null
java.lang.NullPointerException
at org.aspectj.org.eclipse.jdt.internal.compiler.apt.dispatch.AnnotationDiscoveryVisitor.resolveAnnotations(AnnotationDiscoveryVisitor.java:238)
at org.aspectj.org.eclipse.jdt.internal.compiler.apt.dispatch.AnnotationDiscoveryVisitor.visit(AnnotationDiscoveryVisitor.java:217)
at org.aspectj.org.eclipse.jdt.internal.compiler.ast.TypeDeclaration.traverse(TypeDeclaration.java:1348)
at org.aspectj.org.eclipse.jdt.internal.compiler.ast.CompilationUnitDeclaration.traverse(CompilationUnitDeclaration.java:748)
...

我的 pom.xml 太长,无法粘贴到此处,但构建部分如下(如果您想查看一些依赖项,请告诉我):

<build>
<directory>bin</directory>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<version>1.7</version>
<executions>
<execution>
<id>add-source</id>
<phase>generate-sources</phase>
<goals>
<goal>add-source</goal>
</goals>
<configuration>
<sources>
<source>src</source>
<source>generated</source>
<source>resources</source>
</sources>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.1</version>
<configuration>
<source>1.6</source>
<target>1.6</target>
<excludes>
<exclude>main/</exclude>
<exclude>test/</exclude>
</excludes>
<useIncrementalCompilation>true</useIncrementalCompilation>
</configuration>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>aspectj-maven-plugin</artifactId>
<version>1.8</version>
<configuration>
<showWeaveInfo>true</showWeaveInfo>
<source>1.6</source>
<target>1.6</target>
<Xlint>ignore</Xlint>
<complianceLevel>1.6</complianceLevel>
<encoding>UTF-8</encoding>
<verbose>true</verbose>
<aspectLibraries>
<aspectLibrary>
<groupId>org.springframework</groupId>
<artifactId>spring-aspects</artifactId>
</aspectLibrary>
</aspectLibraries>
</configuration>
<executions>
<execution>
<phase>process-sources</phase>
<goals>
<goal>compile</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<configuration>
<webXml>${project.basedir}/WebRoot/WEB-INF/web.xml</webXml>
<warName>oligoWorld</warName>
<outputDirectory>${project.basedir}</outputDirectory>
</configuration>
</plugin>
</plugins>
<pluginManagement>
<plugins>
<!--This plugin's configuration is used to store Eclipse m2e settings only. It has no influence on the Maven build itself. -->
<plugin>
<groupId>org.eclipse.m2e</groupId>
<artifactId>lifecycle-mapping</artifactId>
<version>1.0.0</version>
<configuration>
<lifecycleMappingMetadata>
<pluginExecutions>
<pluginExecution>
<pluginExecutionFilter>
<groupId>org.codehaus.mojo</groupId>
<artifactId>aspectj-maven-plugin</artifactId>
<versionRange>[1.8,)</versionRange>
<goals>
<goal>compile</goal>
</goals>
</pluginExecutionFilter>
<action>
<execute />
</action>
</pluginExecution>
</pluginExecutions>
</lifecycleMappingMetadata>
</configuration>
</plugin>
</plugins>
</pluginManagement>
</build>

有人发现任何错误或缺失可能导致该异常吗?仅供引用,我的aspectj依赖项(aspectjrt、aspectjtools和aspectjweaver)的版本是1.8.7。

最佳答案

我好像发现问题了。在 pom.xml 中,我列出了aspectjtools 的依赖项,以及pom 文件的依赖项部分中的所有其他依赖项,位于aspectj-maven-plugin 定义之外。相反,我将其移至插件内;另外,我将aspectj库的版本更改为1.8.9,因为1.8.7似乎表现出与我发现的类似的错误。此后,一切正常。所以这是我修改后的aspectj-maven-plugin定义供引用:

        <plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>aspectj-maven-plugin</artifactId>
<version>1.8</version>
<dependencies> <!-- The change that fixed it starts here... -->
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjtools</artifactId>
<version>1.8.9</version>
</dependency>
</dependencies> <!-- ...and ends here. -->
<configuration>
<showWeaveInfo>true</showWeaveInfo>
<source>1.6</source>
<target>1.6</target>
<Xlint>ignore</Xlint>
<complianceLevel>1.6</complianceLevel>
<encoding>UTF-8</encoding>
<verbose>true</verbose>
<aspectLibraries>
<aspectLibrary>
<groupId>org.springframework</groupId>
<artifactId>spring-aspects</artifactId>
</aspectLibrary>
</aspectLibraries>
</configuration>
</plugin>

关于java - Maven AspectJ 编织 NullPointerException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37523235/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com