maven EAR plugin packages war-file twice when using bundleFileName - maven

I want to package two .war files into an .ear file using the Maven EAR plugin:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-ear-plugin</artifactId>
<version>2.8</version>
<executions>
<execution>
<id>package-mae</id>
<phase>package</phase>
<configuration>
<version>6</version>
<modules>
<webModule>
<groupId>de.ast</groupId>
<artifactId>mae-mobile</artifactId>
<contextRoot>/mobile</contextRoot>
<bundleFileName>/mae-mobile.war</bundleFileName>
</webModule>
<webModule>
<groupId>de.ast</groupId>
<artifactId>mae-rest</artifactId>
<contextRoot>/api</contextRoot>
<bundleFileName>/mae-rest.war</bundleFileName>
</webModule>
</modules>
</configuration>
<goals>
<goal>generate-application-xml</goal>
<goal>ear</goal>
</goals>
</execution>
</executions>
</plugin>
It works nicely apart from the fact that the war files are packages twice each, i.e. the ear file contains:
mae-rest.war
mae-rest-0.0.1-SNAPSHOT.war
mae-mobile.war
mae-mobile-0.0.1-SNAPSHOT.war
How can I avoid this duplication?
Thanks,
Ronald

I would suggest to change the configuration which you have into the following:
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-ear-plugin</artifactId>
<version>2.8</version>
<configuration>
<version>6</version>
<modules>
<webModule>
<groupId>de.ast</groupId>
<artifactId>mae-mobile</artifactId>
<contextRoot>/mobile</contextRoot>
<bundleFileName>mae-mobile.war</bundleFileName>
</webModule>
<webModule>
<groupId>de.ast</groupId>
<artifactId>mae-rest</artifactId>
<contextRoot>/api</contextRoot>
<bundleFileName>mae-rest.war</bundleFileName>
</webModule>
</modules>
<generateApplicationXml>true</generateApplicationXml>
</configuration>
</plugin>
...
</plugins>
</build>
This should solve your problem.

Related

Maven: How to Add JPA Project in EAR using Pom.xml

How can I add JPA Project in the EAR pom.xml file? I don't see the JPA Module in the Maven.
<build>
<plugins>
<plugin>
<artifactId>maven-ear-plugin</artifactId>
<version>2.10</version>
<configuration>
<earSourceDirectory>EarContent</earSourceDirectory>
<generateApplicationXml>false</generateApplicationXml>
<version>6</version>
<defaultLibBundleDir>lib</defaultLibBundleDir>
<modules>
<jarModule>
<groupId>artifactGroupId</groupId>
<artifactId>artifactId</artifactId>
<bundleDir>APP-INF/lib</bundleDir>
</jarModule>
</modules>
</configuration>
</plugin>
</plugins>
</build>

maven release plugin with phase and jar-with-dependencies

I have a build set up to run a variety of tasks when I run mvn release:prepare and mvn:release:perform. Specifically, I have a phase set up so that my javadocs and source-plugins are run only when I release. This allows my build to avoid a lot of time for the common case of mvn clean install. I'd like to add to this my maven-assembly-plugin jar-with-dependencies so only when I release the assembly plugin is run.
Here's what my build looks like:
<?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>
<groupId>example</groupId>
<artifactId>example</artifactId>
<version>1.0.0-SNAPSHOT</version>
<packaging>jar</packaging>
<name>Example</name>
<build>
<plugins>
<plugin>
<artifactId>maven-release-plugin</artifactId>
<version>2.4.1</version>
<configuration>
<releaseProfiles>release</releaseProfiles>
<goals>deploy</goals>
</configuration>
</plugin>
</plugins>
</build>
<profiles>
<profile>
<id>release</id>
<activation>
<activeByDefault>false</activeByDefault>
</activation>
<build>
<plugins>
<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.9</version>
<executions>
<execution>
<id>attach-javadocs</id>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
<configuration>
<doclet>org.asciidoctor.Asciidoclet</doclet>
<docletArtifact>
<groupId>org.asciidoctor</groupId>
<artifactId>asciidoclet</artifactId>
<version>0.1.3</version>
</docletArtifact>
<linksource>true</linksource>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.4</version>
<configuration>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
<executions>
<execution>
<id>make-assembly</id>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
</profiles>
</project>
the maven-source-plugin and maven-javadoc-plugin both run during the release phase, but the maven-assembly-plugin does not. What do I have to do to make this plugin run during a maven release?
The single isn't bound to a default phase, so you have to specify it in the execution-block.
If you compare it with the javadoc:jar you'll see that this goal is by default bound to the package phase.

Maven build sub projects using root pom

I have different independent maven projects and want to build it with single pom. So I am using following pom
<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>a.b</groupId>
<artifactId>my-sdk</artifactId>
<name>my-sdk</name>
<version>1.0</version>
<packaging>pom</packaging>
<description>Generating SDK</description>
<modules>
<module>project1</module>
<module>project2</module>
<module>project3</module>
</modules>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.5.1</version>
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>2.9</version>
<executions>
<execution>
<id>process-sources</id>
<phase>process-classes</phase>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-antrun-plugin</artifactId>
<executions>
<execution>
<phase>process-classes</phase>
<configuration>
<tasks>
<ant antfile="build.xml" target="init" />
</tasks>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
<repositories>
<repository>
<id>jboss-repo</id>
<url>http://repository.jboss.org/maven2</url>
</repository>
</repositories>
I have the following questions:-
Javadoc is not generating, so where I am doing wrong. If I run "mvn javadoc:javadoc package" command it generates java doc. But if I run "mvn package" it doesn't.
In project2 there is assembly plugin to generate fat jar, it generates jar of project2 but unable to generate fat jar. If I build project2 independently it generate fat jar successfully.
Follwing section is from project2 pom to generate fat jar which works successfully if I run the build independently
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.5.1</version>
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<appendAssemblyId>false</appendAssemblyId>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
<executions>
<execution>
<id>make-assembly</id>
<phase>package</phase>
<configuration>
<archive>
<manifest>
<mainClass>[MAIN CLASS]</mainClass>
</manifest>
<manifestEntries>
<Class-Path>.</Class-Path>
</manifestEntries>
</archive>
</configuration>
<goals>
<goal>assembly</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
Any Suggestions.
I'd say check the documentation for both of your questions ;-)
javadoc (http://maven.apache.org/plugins/maven-javadoc-plugin/plugin-info.html)
javadoc:jar and javadoc:javadoc should not be used for an aggregator project, use javadoc:aggregate or (in your case) javadoc:aggregate-jar
assembly (http://maven.apache.org/plugins/maven-assembly-plugin/assembly-mojo.html)
first, assembly:assembly is deprecated and second, it should only be used on the command line. I guess using goal single will help.

Maven Web Project with Apache Felix Plugin

What's the best way to create a simple osgi (deploying into virgo server) project using maven, to create a war structure with pom.xml maven descriptor?
A Structure target is
*.jsp
*.html
META-INF
MANIFEST (OSGI-CONFIG)
WEB-INF
classes
lib
web.xml
Then when I create a project
This is my pom.xml
project properties
<groupId>com.aaaa</groupId>
<artifactId>first-maven-virgo-project</artifactId>
<version>1.0.0</version>
<packaging>war</packaging>
Felix Plugin
<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
<extensions>true</extensions>
<configuration>
<supportedProjectTypes>
<supportedProjectType>war</supportedProjectType>
</supportedProjectTypes>
<instructions>
<Export-Package>com.roshka.servlet</Export-Package>
<Bundle-SymbolicName>${project.artifactId}</Bundle-SymbolicName>
<Bundle-ClassPath>.,WEB-INF/classes,{maven-dependencies}</Bundle-ClassPath>
<Embed-Directory>WEB-INF/lib</Embed-Directory>
<Embed-Dependency>*;scope=compile|runtime;</Embed-Dependency>
<Embed-Transitive>true</Embed-Transitive>
<Web-ContextPath>/hello</Web-ContextPath>
<Webapp-Context>hello</Webapp-Context>
</instructions>
</configuration>
</plugin>
But, when I execute mvn install the package does not create the MANIFEST file, to package into METAINF folder.
What's the wrong with my felix project? What's is the typical pom.xml template to create an OSGI BUNDLE , and WAR OSGI BUNDLE?
p.s. if I change WAR TO BUNDLE into Packaging Maven descriptor, the JAR generated works OK, with MANIFEST generated OK. But it is not WEB Structure.
My question has been resolve with the next 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>com.aaaa</groupId>
<artifactId>first-maven-virgo-project</artifactId>
<version>1.0.0</version>
<packaging>war</packaging>
<description>http://localhost:8090/system/console/bundles</description>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>commons-lang</groupId>
<artifactId>commons-lang</artifactId>
<version>2.6</version>
</dependency>
<dependency>
<groupId>org.apache.tomcat</groupId>
<artifactId>tomcat-servlet-api</artifactId>
<version>7.0.42</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.osgi</groupId>
<artifactId>org.osgi.core</artifactId>
<version>4.2.0</version>
<scope>provided</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<configuration>
<archive>
<manifestFile>./src/main/webapp/META-INF/MANIFEST.MF</manifestFile>
</archive>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
<extensions>true</extensions>
<executions>
<execution>
<id>bundle-manifest</id>
<phase>process-classes</phase>
<goals>
<goal>manifest</goal>
</goals>
</execution>
</executions>
<configuration>
<supportedProjectTypes>
<supportedProjectType>war</supportedProjectType>
</supportedProjectTypes>
<manifestLocation>./src/main/webapp/META-INF</manifestLocation>
<instructions>
<Export-Package>com.roshka.servlet</Export-Package>
<Bundle-SymbolicName>${project.artifactId}</Bundle-SymbolicName>
<Bundle-ClassPath>.,WEB-INF/classes,{maven-dependencies}</Bundle-ClassPath>
<Embed-Directory>WEB-INF/lib</Embed-Directory>
<Embed-Dependency>*;scope=compile|runtime;</Embed-Dependency>
<Embed-Transitive>true</Embed-Transitive>
<Web-ContextPath>/hello</Web-ContextPath>
<Webapp-Context>hello</Webapp-Context>
</instructions>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<id>copy-dependencies</id>
<phase>package</phase>
<goals>
<goal>copy-dependencies</goal>
</goals>
<configuration>
<Import-Package>javax.servlet,javax.servlet.http,javax.servlet.*,javax.servlet.jsp.*,javax.servlet.jsp.jstl.*,*</Import-Package>
<outputDirectory>./src/main/resources/WEB-INF/lib</outputDirectory>
<overWriteReleases>false</overWriteReleases>
<overWriteSnapshots>false</overWriteSnapshots>
<overWriteIfNewer>true</overWriteIfNewer>
<actTransitively>true</actTransitively>
<excludeScope>provided</excludeScope>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<!-- Enable this plugin for all modules -->
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
</plugin>
</plugins>
</build>
There is an answer from IBM to be found here which describes the process step by step. A script could be developed to create a bundle given a war, I have written one in java, invoked as a build step.
One crucial difference is that the IBM steps leave the finished product as a jar, whereas jrey leaves his as a war file. This is possibly because the IBM steps might lead to further CICS bundling, which requires jars as far as I am aware, at least when using the RAD environment.

Maven ear plugin multiple artifacts content

Lets assume that I have a web project and several environments where it could be deployed. And I want Maven to build several artifacts at once (e.g. for dev an prod). I have an A-war module and an A-ear module (which contains A-war). Each war artifact could contain information which is related only to its environment.
First I configured a pom.xml file for A-war module:
<build>
<pluginManagement>
<plugins>
<plugin>
<artifactId>maven-war-plugin</artifactId>
<executions>
<execution>
<id>package-prod</id>
<phase>package</phase>
<configuration>
<classifier>prod</classifier>
<webappDirectory>${project.build.directory}/${project.build.finalName}-prod</webappDirectory>
<webResources>
<resource>
<directory>src/env/prod</directory>
</resource>
</webResources>
</configuration>
<goals>
<goal>war</goal>
</goals>
</execution>
<execution>
<id>package-dev</id>
<phase>package</phase>
<configuration>
<classifier>dev</classifier>
<webappDirectory>${project.build.directory}/${project.build.finalName}-dev</webappDirectory>
<webResources>
<resource>
<directory>src/env/dev</directory>
</resource>
</webResources>
</configuration>
<goals>
<goal>war</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</pluginManagement>
<finalName>A-war</finalName>
</build>
This works fine - 2 *war*s are created in target folder: A-war-prod and A-war-dev.
Now I want to build ear artifact for each of these war.
Here is the main content of pom.xml in A-ear module:
<dependencies>
<dependency>
<groupId>gr.id</groupId>
<artifactId>A-war</artifactId>
<version>0.0.1-SNAPSHOT</version>
<classifier>prod</classifier>
<scope>provided</scope>
<type>war</type>
</dependency>
<dependency>
<groupId>gr.id</groupId>
<artifactId>A-war</artifactId>
<classifier>dev</classifier>
<version>0.0.1-SNAPSHOT</version>
<scope>provided</scope>
<type>war</type>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-ear-plugin</artifactId>
<version>2.8</version>
<executions>
<execution>
<id>package-dev</id>
<phase>package</phase>
<configuration>
<classifier>dev</classifier>
<version>5</version>
<modules>
<webModule>
<groupId>gr.id</groupId>
<artifactId>A-war</artifactId>
<classifier>dev</classifier>
<contextRoot>/A-war</contextRoot>
<bundleFileName>/A-war.war</bundleFileName>
</webModule>
</modules>
</configuration>
<goals>
<goal>ear</goal>
</goals>
</execution>
<execution>
<id>package-prod</id>
<phase>package</phase>
<configuration>
<classifier>prod</classifier>
<version>5</version>
<modules>
<webModule>
<groupId>gr.id</groupId>
<artifactId>A-war</artifactId>
<classifier>prod</classifier>
<contextRoot>/A-war</contextRoot>
<bundleFileName>/A-war.war</bundleFileName>
</webModule>
</modules>
</configuration>
<goals>
<goal>ear</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
<finalName>A-ear</finalName>
</build>
It also builds 2 ear**s: A-ear-dev.ear and A-ear-prod.ear. And each of these *ear*s contains an A-war.war artifact. And everything would be fine except of one small detail: these **war files are the same. I mean A-ear-dev.ear contains A-war-dev.war (which is renamed to A-war.war) but A-ear-prod.ear contains the same A-war-dev.war instead of its own A-war-prod.war.
Moreover when I'd changed the order of executions (moved creating of prod higher than dev) then these *ear*s both contained A-war-prod.war.
As I can see from maven output, when starting building ear**s it copies the first war into the folder for the first **ear but for the second it does not:
[INFO] --- maven-ear-plugin:2.8:ear (package-dev) # A-ear
---
[INFO] Copying artifact [war:gr.id:A-war:dev:0.0.1-SNAPSHOT] to [/A-war.war]
[INFO] Including custom manifest ....
[INFO] Copy ear sources to ...
[INFO] Building jar: <location>\A-ear\target\A-ear-dev.ear
....
[INFO] --- maven-ear-plugin:2.8:ear (package-prod) # A-ear ---
[INFO] Copy ear sources to ...
[INFO] Including custom manifest file ...
[INFO] Building jar: <location>\A-ear\target\A-ear-prod.ear
So maybe anyone has an idea on how to force maven copy war file each time?
As I found out, when Maven is copying war file into the temp directory, it doesn't rewrite it - if there is a file with the same name, then it will not be replaced. So after the first artifact copying, it copied always the first artifact which is pointed in execution module.
All other artifacts were not copied. So this artifact was placed in all result ears.
So the solution for this issue is to specify working directory for each execution tag, like:
<execution>
<id>package-prod</id>
<phase>package</phase>
<configuration>
<workDirectory>target/prod</workDirectory>
<classifier>prod</classifier>
<version>5</version>
<modules>
<webModule>
<groupId>gr.id</groupId>
<artifactId>A-war</artifactId>
<classifier>prod</classifier>
<contextRoot>/A-war</contextRoot>
<bundleFileName>/A-war.war</bundleFileName>
</webModule>
</modules>
</configuration>
<goals>
<goal>ear</goal>
</goals>
</execution>

Resources