Home > Blockchain >  couldn't find aspectjrt.jar on classpath in intellij
couldn't find aspectjrt.jar on classpath in intellij

Time:09-15

I am working on multi module maven project. I am doing java upgrade from 8 to 11. I am facing below error when i do 'mvn clean install'.

[INFO] --- aspectj-maven-plugin:1.14.0:compile (default) @ module-1 ---
[INFO] Showing AJC message detail for messages of types: [error, warning, fail]
[WARNING] couldn't find aspectjrt.jar on classpath, checked: /usr/lib/jvm/java-11-openjdk-amd64/lib/jrt-fs.jar:/home/.m2/repository/org/motechproject/motech-platform-osgi-extender-fragment/0.27.8/motech-platform-osgi-extender-fragment-0.27.8.jar:/home/.m2/repository/javax/servlet/javax.servlet-api/3.1.0/javax.servlet-api-3.1.0.jar:

Even though 'aspectjrt-1.9.7.jar' is present in m2 folder(path: '/home/.m2/repository/org/aspectj/aspectjrt/1.9.7').

Here is aspectj-maven-plugin which i am using in every module.

<build>
...
<plugins>
...
 <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>aspectj-maven-plugin</artifactId>
                <version>1.14.0</version>
                <dependencies>
                    <dependency>
                        <groupId>org.aspectj</groupId>
                        <artifactId>aspectjrt</artifactId>
                        <version>1.9.7</version>
                    </dependency>
                    <dependency>
                        <groupId>org.aspectj</groupId>
                        <artifactId>aspectjtools</artifactId>
                        <version>1.9.7</version>
                    </dependency>
<!--                    <dependency>-->
<!--                        <groupId>com.sun</groupId>-->
<!--                        <artifactId>tools</artifactId>-->
<!--                        <version>8</version>-->
<!--                        <scope>system</scope>-->
<!--                        <systemPath>${project.basedir}/pom.xml</systemPath>-->
<!--                    </dependency>-->
                </dependencies>
                <executions>
                    <execution>
                        <goals>
                            <goal>compile</goal>
                            <goal>test-compile</goal>
                        </goals>
                    </execution>
                </executions>
                <configuration>
                    <source>11</source>
                    <target>11</target>
                    <complianceLevel>11</complianceLevel>
                </configuration>
            </plugin>
</plugins>
</build>

I could find the cause of this warning. Please help me.

Thanks.

CodePudding user response:

aspectjrt, as the "rt" (runtime) in the name implies, is a runtime library, which is necessary in order to run aspect-enhanced code. Therefore, you need to make it a regular compile dependency in your POM, not configure it as a dependency for the AspectJ Maven Plugin. The latter one has aspectjtools as a dependency already, which encapsulates both the compiler and the runtime. But your compiled code still needs this directly under project → dependencies on top level in the POM, not nested in project → build → plugins → plugin → dependencies.

<dependency>
  <groupId>org.aspectj</groupId>
  <artifactId>aspectjrt</artifactId>
  <version>${aspectj.version}</version>
</dependency>

Whatever ${aspectj.version} might be in your case.

  • Related