I have my Storm application (maven) project structured as follow:
parent-project/
├── pom.xml
├── storm-application/
└── pom.xml
├── utils/
└── pom.xml
I structured my pom.xml files as follow:
parent-project:pom.xml
<modelVersion>4.0.0</modelVersion>
<groupId>my.project</groupId>
<artifactId>parent-project</artifactId>
<packaging>pom</packaging>
<version>1.0-SNAPSHOT</version>
<modules>
<module>utils</module>
<module>storm-application</module>
</modules>
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
</pluginManagement>
</build>
storm-application:pom.xml
<parent>
<groupId>my.project</groupId>
<artifactId>parent-project</artifactId>
<version>1.0-SNAPSHOT</version>
</parent>
<groupId>my.project.parent-project</groupId>
<artifactId>storm-application</artifactId>
<packaging>jar</packaging>
<dependencies>
<dependency>
<groupId>my.project.parent-project</groupId>
<artifactId>utils</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
<dependency> ...storm dependency... </dependency>
</dependencies>
<build>
<sourceDirectory>src/main/java</sourceDirectory>
<testSourceDirectory>src/test/java</testSourceDirectory>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<version>3.1.1</version>
<configuration>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
<executions>
<execution>
<id>make-assembly</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
utils:pom.xml
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>my.project</groupId>
<artifactId>parent-project</artifactId>
<version>1.0-SNAPSHOT</version>
</parent>
<groupId>my.project.parent-project</groupId>
<artifactId>utils</artifactId>
<packaging>jar</packaging>
<dependencies>
... some project related dependencies ...
</dependencies>
<build>
<sourceDirectory>src/main/java</sourceDirectory>
<testSourceDirectory>src/test/java</testSourceDirectory>
</build>
My objective would be to include the sibling module utilsin storm-application.
I need to include the module utils directly in the jar package of the storm-applicationmodule.
In fact, if I run the main function directly from IntelliJ it works, because it recognize the project structure, but if I try to deploy the application with Storm I get this error:
Exception in thread "main" java.lang.NoClassDefFoundError: my/project/parent-project/utils/MyClass
at my.project.parent-project.storm-application.MainClass.main(MainClass.java:116)
Caused by: java.lang.ClassNotFoundException: my.project.parent-project.utils.MyClass
at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:338)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
... 1 more
I even tried to use the maven-assembly-plugin to include all the dependency in the package but I still get the same error.
Update
So what I was missing was that the assembly creates a second jar on the form name-version-jar-with-dependencies.
Plus, the storm dependency should be of <scope>provided</scope> otherwise it complains.
Still, I'm wondering if there would be an easier way to achieve this inter-module dependency.
I found a cleaner way to do so. Instead of using the assembly plugin, I use the shade plugin, so that the fat jar keeps the standard name.
Finally, this is the storm-application/pom.xml that, for me, works:
<parent>
<groupId>my.project</groupId>
<artifactId>parent-project</artifactId>
<version>1.0-SNAPSHOT</version>
</parent>
<groupId>my.project.parent-project</groupId>
<artifactId>storm-application</artifactId>
<packaging>jar</packaging>
<dependencies>
<dependency>
<groupId>my.project.parent-project</groupId>
<artifactId>utils</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
<dependency> ...storm dependency... </dependency>
</dependencies>
<build>
<sourceDirectory>src/main/java</sourceDirectory>
<testSourceDirectory>src/test/java</testSourceDirectory>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>3.2.1</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
Related
I need to install a custom plugin (mojo) first and then execute the goal. I would want this to happen in one go but as of now using below code i am getting build errors. Not sure if i'm going right in below code so that i can install plugin first and then code inside mojo would get executed.
ParentProject:
<groupId>com.io</groupId>
<artifactId>Parent</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>Parent</name>
<description>ThisisParent</description>
<packaging>pom</packaging>
<modules>
<module>Child1Plugin</module>
<module>ChildFramework</module>
</modules>
Child1Plugin-pom.xml
<parent>
<groupId>com.io</groupId>
<artifactId>Parent</artifactId>
<version>0.0.1-SNAPSHOT</version>
</parent>
<artifactId>Child1Plugin</artifactId>
<packaging>maven-plugin</packaging>
<name>Child</name>
<description>ThisisChild</description>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-plugin-plugin</artifactId>
<version>3.4</version>
</plugin>
<plugin>
<groupId>com.parent.module</groupId>
<artifactId>ChildFramework</artifactId>
<version>0.0.1-SNAPSHOT</version>
<executions>
<execution>
<goals>
<goal>mydata</goal>
</goals>
</execution>
</executions>
<configuration>
<scope>test</scope>
</configuration>
</plugin>
</plugins>
</build>
</project>
ChildFramework-pom.xml
<parent>
<groupId>com.io</groupId>
<artifactId>Parent</artifactId>
<version>0.0.1-SNAPSHOT</version>
</parent>
<artifactId>ChildFramework</artifactId>
<packaging>maven-plugin</packaging>
<name>Childtwo</name>
<description>Thisischildtwo</description>
<dependencies>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-plugin-api</artifactId>
<version>3.6.3</version>
</dependency>
<dependency>
<groupId>org.apache.maven.plugin-tools</groupId>
<artifactId>maven-plugin-annotations</artifactId>
<version>3.6.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-project</artifactId>
<version>2.2.1</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-plugin-plugin</artifactId>
<version>3.4</version>
</plugin>
<plugin>
<groupId>com.io</groupId>
<artifactId>ChildFramework</artifactId>
<version>0.0.1-SNAPSHOT</version>
<executions>
<execution>
<goals>
<goal>mydata</goal>
</goals>
</execution>
</executions>
<configuration>
<scope>test</scope>
</configuration>
</plugin>
</plugins>
</build>
The below mojo is inside src/main/java folder of ChildFramework module.
#Mojo(name = "mydata", defaultPhase = LifecyclePhase.COMPILE)
public class Feat extends AbstractMojo {
#Override
public void execute() throws MojoExecutionException, MojoFailureException {
System.out.println("%%%%%%%%%%%%%%%%%%%%%% MyMOJO");
}
ChildFramework can't use itself as a plugin (because that's a circular dependency). I think the changes you need are these:
Child1Plugin: remove the ChildFramework plugin element
ChildFramework: change <packaging> to jar and change the <artifactId> of the plugin to Child1Plugin
move the mojo code from the ChildFramework module to the Child1Plugin module
I am trying to add a global version property to my multi-module
Maven project, so that I can easily update the version of all
modules by updating a single property rather than several pom
files. The problems is that this property is breaking maven-
assembly-plugin that collects the compile module jars into a zip
folder for distribution. When the version was hard-coded in all
the pom files, everything worked swimmingly. When I converted to
a property, however, the individual module jars still compiled,
but the maven-assembly-plugin step failed after the following
warning: "[WARNING] The following patterns were never triggered
in this artifact inclusion filter"
The assembly filters seem to be missing the modules, I just can't
explain why this happens when I use the global property, or how
to fix it.
Project structure:
MyProject
--ModuleA
pom.xml
--ModuleB
pom.xml
--Distribution
src\main\assembly\distribution-assembly.xml
pom.xml
pom.xml
MyProject/pom.xml:
<groupId>com.mycompany</groupId>
<artifactId>MyProject</artifactId>
<packaging>pom</packaging>
<version>${global.version}</version>
<properties>
<global.version>1.0.1-SNAPSHOT</global.version>
</properties>
ModuleA/pom.xml:
<parent>
<artifactId>MyProject</artifactId>
<groupId>com.mycompany</groupId>
<version>${global.version}</version>
</parent>
<artifactId>ModuleA</artifactId>
ModuleB/pom.xml:
<parent>
<artifactId>MyProject</artifactId>
<groupId>com.mycompany</groupId>
<version>${global.version}</version>
</parent>
<artifactId>ModuleB</artifactId>
Distribution/pom.xml:
<parent>
<artifactId>MyProject</artifactId>
<groupId>com.mycompany</groupId>
<version>${global.version}</version>
</parent>
<packaging>pom</packaging>
<artifactId>Distribution</artifactId>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.4</version>
<configuration>
<descriptors>
<descriptor>
src/main/assembly/distribution-assembly.xml
</descriptor>
</descriptors>
</configuration>
<executions>
<execution>
<id>make-assembly</id>
<phase>package</phase>
<goals>
<goal>
single
</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
Distribution/src/main/assembly/distribution-assembly.xml:
<id>bin</id>
<formats>
<format>zip</format>
</formats>
<includeBaseDirectory>false</includeBaseDirectory>
<moduleSets>
<moduleSet>
<useAllReactorProjects>true</useAllReactorProjects>
<includes>
<include>com.mycompany:ModuleA</include>
<include>com.mycompany:ModuleB</include>
</includes>
<binaries>
<outputDirectory>MyBuildFolder</outputDirectory>
<outputFileNameMapping>mycompany${module.artifactId}.${module.extension}</outputFileNameMapping>
<unpack>false</unpack>
</binaries>
</moduleSet>
<moduleSets>
Warning:
[WARNING] The following patterns were never triggered in this artifact
inclusion filter:
o 'com.mycompany:ModuleA'
o 'com.mycompany:ModuleB'
Error:
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-assembly-
plugin:2.4:single (make-assembly) on project Distribution:
Failed to create assembly: Error creating assembly archive bin: You must
set at least one file. -> [Help 1]
Try to add your ModuleA and ModuleB as a depenedency of the distribution pom.
the Dstibution/pom.xml should look like this :
<parent>
<artifactId>MyProject</artifactId>
<groupId>com.mycompany</groupId>
<version>${global.version}</version>
</parent>
<packaging>pom</packaging>
<artifactId>Distribution</artifactId>
<dependencies>
<dependency>
<groupId>com.mycompany</groupId>
<artifactId>ModuleA</artifactId>
<version>${global.version}</version>
</dependency>
<dependency>
<groupId>com.mycompany</groupId>
<artifactId>ModuleB</artifactId>
<version>${global.version}</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.4</version>
<configuration>
<descriptors>
<descriptor>
src/main/assembly/distribution-assembly.xml
</descriptor>
</descriptors>
</configuration>
<executions>
<execution>
<id>make-assembly</id>
<phase>package</phase>
<goals>
<goal>
single
</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
I'm getting the following error when trying to run my jar file on the command line:
$ java -jar target/Controller-0.0.1-SNAPSHOT.jar
Exception in thread "main" java.lang.NoClassDefFoundError: org/springframework/boot/SpringApplication
at com.vismark.Controller.App.main(App.java:11)
Caused by: java.lang.ClassNotFoundException: org.springframework.boot.SpringApplication
at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:349)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
... 1 more
The project runs just fine on eclipse, but this error shows up when running it via commandline.
Below is my pom file:
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.vismark</groupId>
<artifactId>Controller</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>Controller</name>
<url>http://maven.apache.org</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<version>2.0.4.RELEASE</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>2.4</version>
<configuration>
<archive>
<manifest>
<mainClass>com.vismark.Controller.App</mainClass>
</manifest>
</archive>
</configuration>
</plugin>
</plugins>
</build>
</project>
I'm likely missing something in my pom, I;m just not sure what it is. Where did I go wrong?
You most likely want to package an executable JAR. Since you are using Spring Boot you should follow chapter 71. Spring Boot Maven Plugin which explains how to do it using Spring Boot Maven Plugin.
Normally this is done by adding following build configuration to your pom.xml which be trigger during package phase.
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<version>2.0.4.RELEASE</version>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
As a note you are using ancient JUnit 3.8.1, you really should upgrade.
The simplified setup of my project is as follows:
root
|--parent
|--service-1
|--service-2
|--service-aggregator
I need to assemble the 'service-1' & 'service-2' modules in 'service-aggregator'. I am using maven-assembly-plugin for the same and it works fine, however I foresee a maintenance issue wherein whenever the version of either of service-1 or service-2 will change, I will need to update the service-aggregator pom.xml also.
Hence, I am looking for a way to prevent writing the version of the service-1 / -2 in the service-aggregator pom.xml i.e. I just need service-aggregator to simply pick the latest version of service-1 / -2.
I have gone through the examples provided in maven-assembly-plugin documentation but those contain the version being mentioned in the assembly module (service-aggregator in my example).
Please let me know if any detail is missing & I will add it.
Here is the key contents of service-aggregator pom.xml:
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.company.project</groupId>
<artifactId>parent</artifactId>
<version>0.0.1</version>
</parent>
<groupId>com.company.project.parent</groupId>
<artifactId>service-aggregator</artifactId>
<name>service-aggregator</name>
<dependencies>
<dependency>
<groupId>com.company.project.parent</groupId>
<artifactId>service-1</artifactId>
<version>0.0.1</version> <!-- this is the line troubling me -->
</dependency>
<dependency>
<groupId>com.company.project.parent</groupId>
<artifactId>service-2</artifactId>
<version>0.0.1</version> <!-- this is the line troubling me -->
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.6</version>
<configuration>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
<skipAssembly>${skip.assembly}</skipAssembly>
</configuration>
<executions>
<execution>
<id>make-assembly</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
<properties>
<skip.assembly>false</skip.assembly>
</properties>
The best thing is to use properties like this:
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.company.project</groupId>
<artifactId>parent</artifactId>
<version>0.0.1</version>
</parent>
<groupId>com.company.project.parent</groupId>
<artifactId>service-aggregator</artifactId>
<name>service-aggregator</name>
<dependencies>
<dependency>
<groupId>com.company.project.parent</groupId>
<artifactId>service-1</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>com.company.project.parent</groupId>
<artifactId>service-2</artifactId>
<version>${project.version}</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.6</version>
<configuration>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
<skipAssembly>${skip.assembly}</skipAssembly>
</configuration>
<executions>
<execution>
<id>make-assembly</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
I am trying get the AspectJ weaving working in a simple Maven project, and not sure where it is going wrong :
when I run the code using "mvn exec:java", I dont see expected output.
I am sure the code is working, because I tried the same in STS, where it works fine. I just wanted to get the AspectJ working in a Maven project.
Any hints to how to debug this kind of issues will be much appreciated.
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.aop</groupId>
<artifactId>aop1</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>aop1</name>
<url>http://maven.apache.org</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjrt</artifactId>
<version>1.7.3</version> <!-- specify your version -->
</dependency>
</dependencies>
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>aspectj-maven-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>compile</goal>
</goals>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</execution>
</executions>
<configuration>
<outxml>true</outxml>
</configuration>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.1</version>
<configuration>
<mainClass>com.aop.aop1.App</mainClass>
</configuration>
</plugin>
</plugins>
</pluginManagement>
</build>
Aspect file in same folder as code :
package com.aop.aop1;
public aspect aspect {
pointcut secureAccess()
: execution(* *.foo(..));
before() : secureAccess() {
System.out.println("BEHOLD the power of AOP !!!");
}
}
Java file :
package com.aop.aop1;
public class App
{
public static void main( String[] args )
{
System.out.println( "Hello World!" );
foo();
}
public static void foo() {
System.out.println(" IN FOO.");
}
}
There are several problems with your configuration:
The aspect should be named Aspect with a capital "A" instead of aspect which is a reserved keyword.
The POM is missing a closing </project> tag.
The POM has a <pluginManagement> section, but no separate <plugins> section, i.e. you provide defaults for your plugins, but do not actually declare that you want to use them. So either you use a stand-alone <plugins> section without <pluginManagement> or you redeclare the plugins in an additional <plugins> section.
The aspectj-maven-plugin needs a <version>. You forgot to specify one.
The aspectj-maven-plugin also needs a <complianceLevel> configuration.
You use compile-time weaving, so you do not need the <outxml> setting. It is only needed for load-time weaving.
The aspectjrt dependency needs at least version 1.7.4 in order to be compatible with the version used in aspectj-maven-plugin 1.6 by default in order to compile your sources.
In addition to that, I recommend to use newer versions of Maven plugins and dependencies such as JUnit and exec-maven-plugin if you do not have any compelling reasons to use older ones. I also recommend to use the latest AspectJ version 1.8.2 and also specify to use that one internally in aspectj-maven-plugin.
Working pom.xml with minimal changes:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.aop</groupId>
<artifactId>aop1</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>aop1</name>
<url>http://maven.apache.org</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjrt</artifactId>
<version>1.7.4</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>aspectj-maven-plugin</artifactId>
<version>1.6</version>
<configuration>
<complianceLevel>1.7</complianceLevel>
</configuration>
<executions>
<execution>
<goals>
<goal>compile</goal>
</goals>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.1</version>
<configuration>
<mainClass>com.aop.aop1.App</mainClass>
</configuration>
</plugin>
</plugins>
</build>
</project>
Working pom.xml with recommended changes:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.aop</groupId>
<artifactId>aop1</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>AOP Sample</name>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<aspectj.version>1.8.2</aspectj.version>
<java.source-target.version>1.7</java.source-target.version>
</properties>
<build>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>${java.source-target.version}</source>
<target>${java.source-target.version}</target>
<!-- IMPORTANT -->
<useIncrementalCompilation>false</useIncrementalCompilation>
</configuration>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>aspectj-maven-plugin</artifactId>
<version>1.6</version>
<configuration>
<showWeaveInfo>true</showWeaveInfo>
<source>${java.source-target.version}</source>
<target>${java.source-target.version}</target>
<Xlint>ignore</Xlint>
<complianceLevel>${java.source-target.version}</complianceLevel>
<encoding>UTF-8</encoding>
<verbose>true</verbose>
</configuration>
<executions>
<execution>
<!-- IMPORTANT -->
<phase>process-sources</phase>
<goals>
<goal>compile</goal>
<goal>test-compile</goal>
</goals>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjtools</artifactId>
<version>${aspectj.version}</version>
</dependency>
</dependencies>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.3</version>
<configuration>
<mainClass>com.aop.aop1.App</mainClass>
</configuration>
</plugin>
<plugin>
<groupId>org.dstovall</groupId>
<artifactId>onejar-maven-plugin</artifactId>
<version>1.4.4</version>
<executions>
<execution>
<configuration>
<onejarVersion>0.96</onejarVersion>
<mainClass>com.aop.aop1.App</mainClass>
<attachToBuild>true</attachToBuild>
</configuration>
<goals>
<goal>one-jar</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
<pluginRepositories>
<pluginRepository>
<id>OneJAR googlecode.com</id>
<url>http://onejar-maven-plugin.googlecode.com/svn/mavenrepo</url>
</pluginRepository>
</pluginRepositories>
<dependencies>
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjrt</artifactId>
<version>${aspectj.version}</version>
<!--<scope>runtime</scope>-->
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>
BTW, the onejar-maven-plugin is just a goodie which I like to use in order to build a stand-alone uber JAR (a.k.a. fat JAR) containing everything you need to run the software, i.e. your classes/aspects plus the AspectJ runtime. You can just run the program with
java -jar aop1-0.0.1-SNAPSHOT.one-jar.jar
The output should be similar to mvn exec:java just without the Maven stuff:
Hello World!
BEHOLD the power of AOP !!!
IN FOO.