How to configure aspectj in pom.xml? - java

In my project I use aspects for logging. When I use eclipse compiler, everything works OK, but I have some problems with Maven. No logs are displayed - aspects classes aren't "seen".
I've tried to google it, but apache tutorial isn't clear for me. Other tutorials are about spring.
What should I add to pom.xml?
<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>Agent</groupId>
<artifactId>Agent</artifactId>
<version>0.0.1-SNAPSHOT</version>
<build>
<sourceDirectory>src</sourceDirectory>
<resources>
<resource>
<directory>src</directory>
<excludes>
<exclude>**/*.java</exclude>
</excludes>
</resource>
</resources>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.2</version>
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>aspectj-maven-plugin</artifactId>
<version>1.3</version>
<configuration>
<complianceLevel>1.5</complianceLevel>
</configuration>
<executions>
</executions>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjrt</artifactId>
<version>1.7.0</version>
</dependency>
</dependencies>
</project>

Try this.If u don't need spring
<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/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>myproject</groupId>
<artifactId>aspectj-project</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<dependencies>
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjrt</artifactId>
<version>1.6.8</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>aspectj-maven-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>compile</goal>
</goals>
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>java</goal>
</goals>
</execution>
</executions>
<configuration>
<mainclass>myproject.Main</mainClass>
</configuration>
</plugin>
</plugins>
</build>
</project>

Related

JavaFX export without VM options

Let me start off by saying this question is very similar to this one:
JavaFX Export and VM arguments
I've seen this question and it has helped me a lot further. However, I am quite new to Maven.
I'm trying to export my maven project, which uses both JavaFX and JMTP, to an executeable jar file. However, after running mvn clean package, running the jar file (with dependecies) gives the following error:
Error: JavaFX runtime components are missing, and are required to run this application
This is my pom.xml 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/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.example</groupId>
<artifactId>TestMavenFX</artifactId>
<version>1.0-SNAPSHOT</version>
<repositories>
<repository>
<id>in-project</id>
<name>JMTP-in-project</name>
<url>file://${project.basedir}\libs</url>
<layout>default</layout>
</repository>
</repositories>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>11</maven.compiler.source>
<maven.compiler.target>11</maven.compiler.target>
</properties>
<dependencies>
<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-graphics </artifactId>
<version>14</version>
<classifier>win</classifier>
</dependency>
<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-controls</artifactId>
<version>14</version>
</dependency>
<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-fxml </artifactId>
<version>14</version>
<classifier>win</classifier>
</dependency>
<dependency>
<groupId>jmtp</groupId>
<artifactId>jmtp-sdk</artifactId>
<version>1.0.0</version>
</dependency>
</dependencies>
<build>
<sourceDirectory>src</sourceDirectory>
<resources>
<resource>
<directory>src</directory>
<excludes>
<exclude>*.java</exclude>
</excludes>
</resource>
</resources>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.0</version>
<configuration>
<release>12</release>
</configuration>
</plugin>
<plugin>
<groupId>org.openjfx</groupId>
<artifactId>javafx-maven-plugin</artifactId>
<version>0.0.1</version>
<configuration>
<mainClass>org.example.App</mainClass>
</configuration>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.6.0</version>
<executions>
<execution>
<goals>
<goal>java</goal>
</goals>
</execution>
</executions>
<configuration>
<mainClass>main.java.org.example.App</mainClass>
</configuration>
</plugin>
<plugin>
<artifactId>maven-jar-plugin</artifactId>
<configuration>
<archive>
<manifest>
<mainClass>
main.java.org.example.App
</mainClass>
</manifest>
</archive>
</configuration>
</plugin>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<version>3.1.1</version>
<executions>
<execution>
<id>make-jar-with-dependencies</id>
<phase>prepare-package</phase>
<goals>
<goal>single</goal>
</goals>
<configuration>
<archive>
<manifest>
<mainClass>main.java.org.example.App</mainClass>
</manifest>
</archive>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
Is there anyone who could help with this? I would like to use this instead of a .bat file to run a command to actually run the JAR file, but I'm quite stuck.

'No main manifest attribute' error with Maven

Here is my POM file
<?xml version="1.0" encoding="UTF-8"?>
<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.codetriage.scraper</groupId>
<artifactId>codetriagescraper</artifactId>
<version>1.0-SNAPSHOT</version>
<name>codetriagescraper</name>
<!-- FIXME change it to the project's website -->
<url>http://www.example.com</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.7</maven.compiler.source>
<maven.compiler.target>1.7</maven.compiler.target>
</properties>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jsoup</groupId>
<artifactId>jsoup</artifactId>
<version>1.11.3</version>
</dependency>
</dependencies>
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.Maven.plugins</groupId>
<artifactId>Maven-shade-plugin</artifactId>
<version>3.2.0</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<transformers>
<transformer
implementation="org.apache.Maven.plugins.shade.resource.ManifestResourceTransformer">
<mainClass>com.codetriage.scraper.App</mainClass>
</transformer>
</transformers>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<version>3.0.2</version>
</plugin>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.0</version>
</plugin>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.22.1</version>
</plugin>
<plugin>
<artifactId>maven-jar-plugin</artifactId>
<version>3.0.2</version>
</plugin>
<plugin>
<artifactId>maven-install-plugin</artifactId>
<version>2.5.2</version>
</plugin>
<plugin>
<artifactId>maven-deploy-plugin</artifactId>
<version>2.8.2</version>
</plugin>
<plugin>
<artifactId>maven-site-plugin</artifactId>
<version>3.7.1</version>
</plugin>
<plugin>
<artifactId>maven-project-info-reports-plugin</artifactId>
<version>3.0.0</version>
</plugin>
</plugins>
</pluginManagement>
</build>
</project>
Mvn package is okey, but when i try to java -jar target/codetriagescraper-1.0-SNAPSHOT.jar it returns me "no main manifest attribute, in target/codetriagescraper-1.0-SNAPSHOT.jar". I have tried to add different plugins to make jar executable, but they all didn't work. By the way, when i package the project console show only default plugins were compiled.

How do I work correctly with profiles, classifiers and modules in Maven?

I'm trying to create a Maven configuration that supports the same code for two different environments. One environment is Java 6 with Seam, the other is Java 7 with JEE.
My project is a multi module project with a parent pom where I've configured two profiles. The interesting parts in the parent pom:
<profiles>
<profile>
<id>JDK7</id>
<properties>
<jdk.version>1.7</jdk.version>
<profile.classifier>with-beans-xml</profile.classifier>
</properties>
<build>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.3</version>
<configuration>
<source>${jdk.version}</source>
<target>${jdk.version}</target>
<encoding>${project.build.sourceEncoding}</encoding>
</configuration>
</plugin>
<plugin>
<artifactId>maven-jar-plugin</artifactId>
<version>2.4</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>jar</goal>
</goals>
<configuration>
<classifier>${profile.classifier}</classifier>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
<profile>
<id>JDK6</id>
<properties>
<jdk.version>1.6</jdk.version>
<profile.classifier>without-beans-xml</profile.classifier>
</properties>
<!-- Identical parts left out for brevity -->
<build>
<plugins>
<plugin>
<artifactId>maven-jar-plugin</artifactId>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>jar</goal>
</goals>
<configuration>
<classifier>${profile.classifier}</classifier>
<excludes>
<exclude>src/main/resources/META-INF/beans.xml</exclude>
</excludes>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
</profiles>
In a sub module of this pom I need to reference specific versions of other modules to be sure they are all using the same build version of Java and should contain or not contain beans.xml.
This is how I've done that:
<parent>
<groupId>commons</groupId>
<artifactId>parent-pom</artifactId>
<version>0.0.1-SNAPSHOT</version>
</parent>
<artifactId>some-module</artifactId>
<dependencies>
<dependency>
<groupId>commons</groupId>
<artifactId>core</artifactId>
<version>${project.version}</version>
<classifier>${profile.classifier}</classifier>
</dependency>
</dependencies>
The properties decalared above resolves just fine, but the dependency called core above contains references to other modules that contain the core functionality of the entire project.
The dependencies in core doesn't resolve when I import that module into other modules.
This is the dependency hierarchy I'm expecting:
- some-module
- core
- some-other-module
However, after adding core as a dependency to another module, I explicitly need to add some-other-module for it to be available too, i.e. some-other-module is not transitive from referencing core.
Am I going about this the wrong way? It works just fine with the different versions, just that I have to add them explicitly which I'd rather not to avoid confusion when other users are going to use this.
Updated
By request, here is the full parent pom and one of the modules that are experiencing the problems with transitive dependencies.
parent pom.xml
<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>se.commons</groupId>
<artifactId>healthcheck-parent</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>pom</packaging>
<name>healthcheck-parent-pom</name>
<modules>
<module>healthcheck-core</module>
<module>healthcheck-xsd</module>
<module>healthcheck-jms</module>
<module>healthcheck-db</module>
<module>healthcheck-filesystem</module>
<module>healthcheck-http</module>
</modules>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<java.home>${JAVA_1_7_HOME}</java.home>
</properties>
<profiles>
<profile>
<id>JDK7</id>
<!-- <activation> -->
<!-- <activeByDefault>true</activeByDefault> -->
<!-- </activation> -->
<properties>
<!-- Build properties -->
<jdk.version>1.7</jdk.version>
<profile.classifier>with-beans-xml</profile.classifier>
<bom.version>2.0.0.R</bom.version>
</properties>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>se.commons</groupId>
<artifactId>bom</artifactId>
<version>${bom.version}</version>
<scope>import</scope>
<type>pom</type>
</dependency>
</dependencies>
</dependencyManagement>
<build>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.3</version>
<configuration>
<source>${jdk.version}</source>
<target>${jdk.version}</target>
<encoding>${project.build.sourceEncoding}</encoding>
</configuration>
</plugin>
<plugin>
<artifactId>maven-jar-plugin</artifactId>
<version>2.4</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>jar</goal>
</goals>
<configuration>
<classifier>${profile.classifier}</classifier>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>findbugs-maven-plugin</artifactId>
<version>3.0.1</version>
<configuration>
<effort>Default</effort>
<threshold>Default</threshold>
<xmlOutputDirectory>target/findbugs</xmlOutputDirectory>
<failOnError>true</failOnError>
<xmlOutput>true</xmlOutput>
<findbugsXmlOutput>true</findbugsXmlOutput>
<findbugsXmlWithMessages>true</findbugsXmlWithMessages>
<targetJdk>${jdk.version}</targetJdk>
<configuration>
<omitVisitors>FindReturnRef</omitVisitors>
</configuration>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.18.1</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
<version>2.15</version>
<executions>
<execution>
<goals>
<goal>checkstyle</goal>
</goals>
<phase>compile</phase>
</execution>
</executions>
<configuration>
<configLocation>${basedir}/../src/site/checkstyle.xml</configLocation>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
<version>2.2.1</version>
<executions>
<execution>
<id>attach-sources</id>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>2.8</version>
<executions>
<execution>
<id>attach-javadocs</id>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-site-plugin</artifactId>
<version>3.3</version>
<dependencies>
<dependency>
<!-- add support for ssh/scp -->
<groupId>org.apache.maven.wagon</groupId>
<artifactId>wagon-ssh</artifactId>
<version>2.4</version>
</dependency>
</dependencies>
<configuration>
<locales>sv</locales>
</configuration>
</plugin>
</plugins>
</build>
</profile>
<profile>
<id>JDK6</id>
<properties>
<!-- Build properties -->
<jdk.version>1.6</jdk.version>
<profile.classifier>without-beans-xml</profile.classifier>
<bom.version>2.0.0.R</bom.version>
</properties>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>se.commons</groupId>
<artifactId>bom</artifactId>
<version>${bom.version}</version>
<scope>import</scope>
<type>pom</type>
</dependency>
</dependencies>
</dependencyManagement>
<build>
<resources>
<resource>
<directory>src/main/resources/META-INF</directory>
<excludes>
<exclude>beans.xml</exclude>
</excludes>
</resource>
</resources>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.3</version>
<configuration>
<source>${jdk.version}</source>
<target>${jdk.version}</target>
<encoding>${project.build.sourceEncoding}</encoding>
</configuration>
</plugin>
<plugin>
<artifactId>maven-jar-plugin</artifactId>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>jar</goal>
</goals>
<configuration>
<classifier>${profile.classifier}</classifier>
<excludes>
<exclude>src/main/resources/META-INF/beans.xml</exclude>
</excludes>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>findbugs-maven-plugin</artifactId>
<version>3.0.1</version>
<configuration>
<effort>Default</effort>
<threshold>Default</threshold>
<xmlOutputDirectory>target/findbugs</xmlOutputDirectory>
<failOnError>true</failOnError>
<xmlOutput>true</xmlOutput>
<findbugsXmlOutput>true</findbugsXmlOutput>
<findbugsXmlWithMessages>true</findbugsXmlWithMessages>
<targetJdk>${jdk.version}</targetJdk>
<configuration>
<omitVisitors>FindReturnRef</omitVisitors>
</configuration>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.18.1</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
<version>2.15</version>
<executions>
<execution>
<goals>
<goal>checkstyle</goal>
</goals>
<phase>compile</phase>
</execution>
</executions>
<configuration>
<configLocation>${basedir}/../src/site/checkstyle.xml</configLocation>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
<version>2.2.1</version>
<executions>
<execution>
<id>attach-sources</id>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>2.8</version>
<executions>
<execution>
<id>attach-javadocs</id>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-site-plugin</artifactId>
<version>3.3</version>
<dependencies>
<dependency><!-- add support for ssh/scp -->
<groupId>org.apache.maven.wagon</groupId>
<artifactId>wagon-ssh</artifactId>
<version>2.4</version>
</dependency>
</dependencies>
<configuration>
<locales>sv</locales>
</configuration>
</plugin>
</plugins>
</build>
</profile>
</profiles>
<reporting>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-project-info-reports-plugin</artifactId>
<version>2.4</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-report-plugin</artifactId>
<version>2.18.1</version>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>findbugs-maven-plugin</artifactId>
<version>3.0.1</version>
<configuration>
<effort>Default</effort>
<threshold>Default</threshold>
<xmlOutputDirectory>target/findbugs</xmlOutputDirectory>
<failOnError>true</failOnError>
<xmlOutput>true</xmlOutput>
<findbugsXmlOutput>true</findbugsXmlOutput>
<findbugsXmlWithMessages>true</findbugsXmlWithMessages>
<targetJdk>${jdk.version}</targetJdk>
<configuration>
<omitVisitors>FindReturnRef</omitVisitors>
</configuration>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-pmd-plugin</artifactId>
<version>3.4</version>
<configuration>
<targetJdk>${jdk.version}</targetJdk>
</configuration>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>cobertura-maven-plugin</artifactId>
<version>2.7</version>
<reportSets>
<reportSet>
<reports>
<report>cobertura</report>
</reports>
</reportSet>
</reportSets>
<configuration>
<instrumentation>
</instrumentation>
<formats>
<format>xml</format>
<format>html</format>
</formats>
<instrumentation>
<includes>
<include>**/*.class</include>
</includes>
</instrumentation>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>2.8</version>
</plugin>
</plugins>
</reporting>
</project>
And here is one of the modules that use core as a dependency:
<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>
<parent>
<groupId>se.commons</groupId>
<artifactId>healthcheck-parent</artifactId>
<version>0.0.1-SNAPSHOT</version>
</parent>
<artifactId>healthcheck-jms</artifactId>
<dependencies>
<dependency>
<groupId>se.commons</groupId>
<artifactId>healthcheck-core</artifactId>
<version>${project.version}</version>
<classifier>${profile.classifier}</classifier>
</dependency>
<dependency>
<groupId>org.jboss.spec.javax.ejb</groupId>
<artifactId>jboss-ejb-api_3.1_spec</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.jboss.spec.javax.jms</groupId>
<artifactId>jboss-jms-api_1.1_spec</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax.enterprise</groupId>
<artifactId>cdi-api</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
</dependency>
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
</project>
And finally, here is the pom of core:
<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>
<parent>
<groupId>se.commons</groupId>
<artifactId>healthcheck-parent</artifactId>
<version>0.0.1-SNAPSHOT</version>
</parent>
<artifactId>healthcheck-core</artifactId>
<dependencies>
<dependency>
<groupId>se.commons</groupId>
<artifactId>healthcheck-xsd</artifactId>
<version>${project.version}</version>
<classifier>${profile.classifier}</classifier>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
</dependency>
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
</project>
I finally gave up on the above solution after finding similar questions that never got a clear answer.
It doesn't seem to be possible to resolve transitive dependencies using a classifier, only the standard GAV.
I settled on a different artifactId to differentiate the projects instead.

How to build multiple project in a single step using Maven

I have three projects. The WAR files of first two project are included in the EAR of the third project. Currently I am performing maven build for the three projects individually.
But my requirement is I need to build only the third project which should automatically build the first two projects (WAR files) and then it should build the third project's EAR.
Do any one know how to achieve it.
Below is the POM of the third project.
<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>au.com.mercury</groupId>
<artifactId>ReplenishmentR4</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>ear</packaging>
<build>
<plugins>
<plugin>
<artifactId>maven-ear-plugin</artifactId>
<version>2.6</version>
<configuration>
<applicationXML>src/main/application/META-INF/application.xml</applicationXML>
<generateApplicationXml>false</generateApplicationXml>
<encoding>UTF-8</encoding>
<defaultLibBundleDir>lib/</defaultLibBundleDir>
<filtering>true</filtering>
<modules>
<webModule>
<groupId>au.com.mercury</groupId>
<artifactId>Replenishment</artifactId>
<bundleFileName>Replenishment.war</bundleFileName>
</webModule>
<webModule>
<groupId>au.com.mercury</groupId>
<artifactId>ReplenishmentR3</artifactId>
<bundleFileName>ReplenishmentR3.war</bundleFileName>
</webModule>
</modules>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-toolchains-plugin</artifactId>
<version>1.1</version>
<executions>
<execution>
<goals>
<goal>toolchain</goal>
</goals>
</execution>
</executions>
<configuration>
<toolchains>
<jdk>
<version>1.6</version>
<vendor>sun</vendor>
</jdk>
</toolchains>
</configuration>
</plugin>
</plugins>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.eclipse.m2e</groupId>
<artifactId>lifecycle-mapping</artifactId>
<version>1.0.0</version>
<configuration>
<lifecycleMappingMetadata>
<pluginExecutions>
<pluginExecution>
<pluginExecutionFilter>
<groupId>
org.apache.maven.plugins
</groupId>
<artifactId>
maven-toolchains-plugin
</artifactId>
<versionRange>
[1.1,)
</versionRange>
<goals>
<goal>toolchain</goal>
</goals>
</pluginExecutionFilter>
<action>
<ignore></ignore>
</action>
</pluginExecution>
</pluginExecutions>
</lifecycleMappingMetadata>
</configuration>
</plugin>
</plugins>
</pluginManagement>
<finalName>ReplenishmentR4</finalName>
</build>
<dependencies>
<dependency>
<groupId>au.com.mercury</groupId>
<artifactId>Replenishment</artifactId>
<version>0.0.1-SNAPSHOT</version>
<type>war</type>
</dependency>
<dependency>
<groupId>au.com.mercury</groupId>
<artifactId>ReplenishmentR3</artifactId>
<version>0.0.1-SNAPSHOT</version>
<type>war</type>
</dependency>
</dependencies>
</project>
Thanks Guys,
I have created the fourth pom on top of all the projects. Below is the code.
<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>au.com.woolworths.mercury</groupId>
<artifactId>ReplenishmentR5</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>pom</packaging>
<modules>
<module>Replenishment</module>
<module>ReplenishmentR3</module>
<module>ReplenishmentR4</module>
</modules>
</project>
In the modulues, you can refer to other web project's pom.xml.
<module>../Replenishment</module>
This will work only if you have them in relative to the parent pom

Merge Java module dependencies resources into WAR using Maven

I have a multiplatform project which has several language-specific profiles. The HTML-platform-specific module depends on an "assets-core" module and if "en" profile is enabled, an "assets-en" module resources should also be included into WAR.
Assembling WAR works just fine with an exception that if "assets-core" module contains file with the same file name as "assets-en", it is not overwritten by the file from "assets-en" module.
I tried to use maven-resource-plugin:
<build>
<resources>
<resource>
<directory>${basedir}/assets-en/src/main/resources</directory>
<includes>
<include>**/*</include>
</includes>
</resource>
</resources>
</build>
with
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<version>2.3</version>
<executions>
<execution>
<id>copy-prod-resources</id>
<phase>process-resources</phase>
<goals>
<goal>copy-resources</goal>
</goals>
<configuration>
<overwrite>true</overwrite>
<outputDirectory>${basedir}/target/classes</outputDirectory>
<resources>
<resource>
<directory>${basedir}/assets-ar/src/main/resources</directory>
<includes>
<include>**/*</include>
</includes>
</resource>
</resources>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
and <maven.resources.overwrite>true</maven.resources.overwrite> enabled as other threads suggests, but nothing worked.
maven-war-plugin overlays could also be the solution but I can't have resource module to be packaged with <type>war</type> because the same module is also included in Java project.
Here are the relevant parts of my pom.xmls:
asssets-core/pom.xml
<?xml version="1.0" encoding="UTF-8"?>
<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/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.example</groupId>
<artifactId>example-parent</artifactId>
<version>1.0</version>
</parent>
<artifactId>assets-core</artifactId>
</project>
assets-en/pom.xml
<?xml version="1.0" encoding="UTF-8"?>
<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/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.example</groupId>
<artifactId>example-parent</artifactId>
<version>1.0</version>
</parent>
<artifactId>assets-en</artifactId>
</project>
example-html/pom.xml
<?xml version="1.0" encoding="UTF-8"?>
<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/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.example</groupId>
<artifactId>example-parent</artifactId>
<version>1.0</version>
</parent>
<artifactId>example-html</artifactId>
<packaging>war</packaging>
<dependencies>
<dependency>
<groupId>com.example</groupId>
<artifactId>example-core</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>com.example</groupId>
<artifactId>example-core</artifactId>
<version>${project.version}</version>
<classifier>sources</classifier>
</dependency>
<dependency>
<groupId>com.example</groupId>
<artifactId>assets-core</artifactId>
<version>${project.version}</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>gwt-maven-plugin</artifactId>
<version>${gwt.version}</version>
<executions>
<execution>
<phase>prepare-package</phase>
<goals>
<goal>compile</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<configuration>
<failOnMissingWebXml>false</failOnMissingWebXml>
</configuration>
</plugin>
</plugins>
</pluginManagement>
</build>
<profiles>
<profile>
<id>en</id>
<dependencies>
<dependency>
<groupId>com.example</groupId>
<artifactId>assets-en</artifactId>
<version>${project.version}</version>
</dependency>
</dependencies>
</profile>
</profiles>
</project>
OK, so I finally have found a solution. You need to get rid of dependencies to modules and copy the resources using maven-resources-plugin:
example-html/pom.xml
<?xml version="1.0" encoding="UTF-8"?>
<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/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.example</groupId>
<artifactId>example-parent</artifactId>
<version>1.0</version>
</parent>
<artifactId>example-html</artifactId>
<packaging>war</packaging>
<dependencies>
<dependency>
<groupId>com.example</groupId>
<artifactId>example-core</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>com.example</groupId>
<artifactId>example-core</artifactId>
<version>${project.version}</version>
<classifier>sources</classifier>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>gwt-maven-plugin</artifactId>
<version>${gwt.version}</version>
<executions>
<execution>
<phase>prepare-package</phase>
<goals>
<goal>compile</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<executions>
<execution>
<id>copy-assets-core</id>
<phase>process-resources</phase>
<goals>
<goal>copy-resources</goal>
</goals>
<configuration>
<outputDirectory>${project.build.directory}/${project.artifactId}-${project.version}/ExampleProject/</outputDirectory>
<resources>
<resource>
<directory>${project.parent.basedir}/assets-core/src/main/resources/assets</directory>
</resource>
</resources>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<configuration>
<failOnMissingWebXml>false</failOnMissingWebXml>
</configuration>
</plugin>
</plugins>
</pluginManagement>
</build>
<profiles>
<profile>
<id>en</id>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<executions>
<execution>
<id>copy-assets-en</id>
<phase>process-resources</phase>
<goals>
<goal>copy-resources</goal>
</goals>
<configuration>
<overwrite>true</overwrite>
<outputDirectory>${project.build.directory}/${project.artifactId}-${project.version}/ExampleProject/</outputDirectory>
<resources>
<resource>
<directory>${project.parent.basedir}/assets-en/src/main/resources/assets</directory>
</resource>
</resources>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
</profiles>
</project>

Categories