0

I am writing an Aspect in Mavenised project. PROJECT_A

Now I want to use the PROJECT_A.jar in PROJECT_B which is non mavenised.

And in PROJECT_B i want to use the annotaition which I have written using the aspect in PROJECT_A .

I tried exporting PROJECT_A.jar - with aspectJ Plugin as follows. But when i use it in PROJECT_B - my annotation does not works as expected.

  <plugin>
                    <groupId>org.codehaus.mojo</groupId>
                    <artifactId>aspectj-maven-plugin</artifactId>
                    <version>1.4</version>
                    <executions>
                        <execution>
                            <goals>
                                <goal>compile</goal>
                                <goal>test-compile</goal>
                            </goals>
                        </execution>
                    </executions>
                    <configuration>
                        <source>1.7</source>
                        <target>1.7</target>
                    </configuration>
                </plugin>

I am new to the use of AspectJ and I am not getting how to do it without maven in PROJECT_B.

Please help , any help is appreciated :)

Ashish Shetkar
  • 1,414
  • 2
  • 18
  • 35

1 Answers1

0

First of all, upgrade to AspectJ Maven 1.9.

Then mavenise project B! This enables you to you can use AspectJ Maven plugin to weave the aspects into your other module, even after compilation. This is called binary weaving. Please read the plugin documentation, especially the info about parameters aspectLibraries and weaveDependencies, depending on which approach you want to pursue.

Alternatively, start your JVM with -javaagent:/path/to/aspwctjweaver.jar and use the AspectJ weaving agent for load-time weaving (LTW). But do not forget then to also provide a LTW configuration via META-INF/aop.xml.

Either way, you have options. But both require you to read some documentation or at least search this site for examples.

kriegaex
  • 63,017
  • 15
  • 111
  • 202
  • Hello @kriegaex , i am trying to use this jar in several projects , what if my both PROJECT_A and PROJECT_B are non mavenised , i can not go for mavenising the projects as per you suggestion , – Ashish Shetkar Mar 08 '17 at 11:30
  • Use the alternative I mentioned. This is why I mentioned both options. It is always helpful to read the full answer. Oh, and BTW, AspectJ compilation or weaving can also be integrated into other build tools such as Gradle or Ant. The same applies to builds from IDEs such as IntelliJ IDEA or Eclipse. But hey, if you want to use a new tool, but not change anything in your build process, what do you expect? You want the tool, but are unwilling to adjust your build. It does not make sense. – kriegaex Mar 08 '17 at 11:47