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

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>

Related

Intellij 2018.1.6 deploy glassfish application name contains .ear extension

Created a Run/Debug configuration to deploy to a payara glassfish server.
It is deploying the built .ear file MyApp.ear built with maven to the server but when you look at the application in the Admin console the name is MyApp.ear.
What am I missing that would deploy it with the application name of just MyApp?
If I deploy the MyApp.ear file using the admin console the application name defaults to MyApp, so what do I need to do so Intellij does the same?
Update 7-23-2018:
I already had finalName here in my ear pom.xml:
<build>
<finalName>MyApp</finalName>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-ear-plugin</artifactId>
<version>3.0.0</version>
<configuration>
<modules>
<webModule>
<groupId>com.example.myapp</groupId>
<artifactId>war-module</artifactId>
<contextRoot>/MyApp</contextRoot>
</webModule>
<ejbModule>
<groupId>com.example.myapp</groupId>
<artifactId>ejb-module</artifactId>
</ejbModule>
</modules>
</configuration>
</plugin>
</plugins>
</build>
So I tried moving it to with in configuration with same results:
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-ear-plugin</artifactId>
<version>3.0.0</version>
<configuration>
<finalName>MyApp</finalName>
<modules>
<webModule>
<groupId>com.example.myapp</groupId>
<artifactId>war-module</artifactId>
<contextRoot>/MyApp</contextRoot>
</webModule>
<ejbModule>
<groupId>com.example.myapp</groupId>
<artifactId>ejb-module</artifactId>
</ejbModule>
</modules>
</configuration>
</plugin>
</plugins>
</build>
This is something specific to Intellij when it deploys it, it's like it doesn't use these values and just uses the file name for the application name.

How to remove version number from war file

I have a Dependency in child pom like this.
<dependencies>
<dependency>
<groupId>sample-groupID</groupId>
<artifactId>sfint</artifactId>
<version>1.0.0-SNAPSHOT</version>
<type>war</type>
</dependency>
</dependencies>
And I am using maven-ear-plugin.
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven.ear.plugin</artifactId>
<version>2.10</version>
<configuration>
<modules>
<webModule>
<groupId>sample-gropuID</groupId>
<artifactId>sfint</artifactId>
<version>1.0.0-SNAPSHOT</version>
<moduleID>WebModule_sfint</moduleID>
<bundleFileName>sfint.war</bundleFileName>
</webModule>
</modules>
</configuration>
</plugin>
Now my problem is that I want my war file to be like this - sfint.war but I am getting it as - sfint.1.0.0-SNAPSHOT.war
Any help ??
Within the <build> tag specify the name that you need for the artifact as "finalName".
<build>
<finalName>${project.artifactId}</finalName>
</build>
You can configure maven-ear-plugin to omit the version information in the EAR file:
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-ear-plugin</artifactId>
<version>2.10.1</version>
<configuration>
[...]
<fileNameMapping>no-version</fileNameMapping>
</configuration>
</plugin>
</plugins>
</build>
Use the outputFileNameMapping option for the maven-ear-plugin plugin
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-ear-plugin</artifactId>
<version>3.0.0</version>
<configuration>
<outputFileNameMapping>#{artifactId}##{dashClassifier?}#.#{extension}#</outputFileNameMapping>
This will solve your problem:
<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>myEAR</groupId>
<artifactId>myEAR</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>ear</packaging>
<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>
<fileNameMapping>no-version</fileNameMapping>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>myWAR</groupId>
<artifactId>myWAR</artifactId>
<version>0.0.1-SNAPSHOT</version>
<type>war</type>
</dependency>
</dependencies>
</project>
your final EAR will be myEAR-0.0.1.SNAPSHOT.EAR that contains myWAR.war (without version number)
if you want to remove version number from EAR also than add myEar
If the war/ejb is part of an ear project, one should use bundleFileName to change the module names in the final ear artifact.
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-ear-plugin</artifactId>
<version>${version.ear.plugin}</version>
<configuration>
<modules>
<webModule>
<groupId>com.foo</groupId>
<artifactId>myapp-web</artifactId>
<contextRoot>/myapp</contextRoot>
<bundleFileName>myapp-web.war</bundleFileName>
</webModule>
<ejbModule>
<groupId>com.foo</groupId>
<artifactId>myapp-ejb</artifactId>
<bundleFileName>myapp-ejb.jar</bundleFileName>
</ejbModule>
</modules>
</configuration>
</plugin>

deployment of an ejb maven project from eclipse

I'm facing a weird problem and was not able to find somebody out there having the same behaviour creating a maven ear-ejb project in eclipse.
I have a parent pom that looks like this:
<modules>
<module>ear</module>
<module>ejb</module>
</modules>
<build>
<plugins>
<plugin>
<artifactId>maven-eclipse-plugin</artifactId>
<configuration>
<wtpversion>2.0</wtpversion>
</configuration>
</plugin>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
</plugins>
</build>
the pom.xml from the ejb project:
<build>
<sourceDirectory>ejbModule</sourceDirectory>
<resources>
<resource>
<directory>ejbResources</directory>
</resource>
<resource>
<directory>ejbModule</directory>
<excludes>
<exclude>**/*.java</exclude>
</excludes>
</resource>
</resources>
<plugins>
<plugin>
<artifactId>maven-ejb-plugin</artifactId>
<version>2.3</version>
<configuration>
<ejbVersion>3.1</ejbVersion>
<archive>
<manifest>
<addClasspath>true</addClasspath>
</manifest>
</archive>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>javax</groupId>
<artifactId>javaee-api</artifactId>
<version>6.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>3.2.4.RELEASE</version>
<scope>provided</scope>
</dependency>
</dependencies>
and finally the pom.xml of the ear project:
<build>
<plugins>
<plugin>
<artifactId>maven-ear-plugin</artifactId>
<version>2.8</version>
<configuration>
<version>6</version>
<defaultLibBundleDir>lib</defaultLibBundleDir>
<modules>
<ejbModule>
<groupId>com.coba.test</groupId>
<artifactId>jms-test-ejb</artifactId>
<uri>jms-test-ejb.jar</uri>
</ejbModule>
</modules>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>com.coba.test</groupId>
<artifactId>jms-test-ejb</artifactId>
<version>${project.version}</version>
<type>ejb</type>
</dependency>
</dependencies>
When running mvn eclipse:eclipse on the projects I am able to import them as existing projects and all natures and references are ok. When I run mvn clean package and deploy the ear to the server (tested on a websphere 8, jboss 7 and 8) the application (a single mdb) starts and acts as expected. BUT when I try to run the project from within eclipse no class from the shipped dependencies is found. When looking into the deployment assembly of the projects then (how it should be) all dependencies are listed in the ear project and the none of them appears in the ejb project. I had a look at the maven-eclipse-plugin and it does explicitly write the to deployed components to the ear project, so I think this is the way it should be. But when I manually add the classpath entries to the deployment assembly to the ejb project the application gets deployed and starts without any Problems.
Is this a Problem of my project setting or a maven-eclipse-plugin bug? Does anybody had this problem himself?
Thx for reading
Markus
EDIT:
I dot not use the m2eclipse plugin.

maven EAR plugin packages war-file twice when using bundleFileName

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.

Maven plugin inheritance from pluginManagement

there
I have a parent pom.xml which defines the the default configuration for maven-ear-plugin
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-ear-plugin</artifactId>
<version>2.8</version>
<configuration>
<modules>
<jarModule>
<groupId>com.test</groupId>
<artifactId>artifact1</artifactId>
</jarModule>
<jarModule>
<groupId>com.test</groupId>
<artifactId>artifact2</artifactId>
</jarModule>
</modules>
</configuration>
</plugin>
</plugins>
</pluginManagement>
In the child pom, I defined the maven-ear-plugin in the <plugins> section
<plugin>
<artifactId>maven-ear-plugin</artifactId>
<executions>
<execution>
<id>default-ear</id>
<phase>package</phase>
<goals>
<goal>ear</goal>
</goals>
<configuration>
<earSourceDirectory>EarContent</earSourceDirectory>
<defaultLibBundleDir>APP-INF/lib</defaultLibBundleDir>
<modules>
<jarModule>
<groupId>com.test</groupId>
<artifactId>artifact3</artifactId>
</jarModule>
</modules>
</configuration>
</execution>
</executions>
</plugin>
My intention is to include all 3 jar files artifact1, artifact2 and artifact3 in the ear. However, after the build, only artifact3 defined in child pom.xml is included. So it looks like by default the <modules> definition in the child pom.xml overwrites what's defined in the parent pom, instead of merge them together. In fact, if I remove the whole <modules> section in the child pom.xml, the artifact1 and artifact2 will be included after the build.
My question is whether there is a way to include all jar modules defined in parent pom and child pom. I have several ear projects and all of them need to include the same set of jar modules plus a few jar modules of their own. I am trying to move the common set of jar modules to the parent so that they are not repeated in each child pom.xml.
Update to clarify my projects relations:
parent pom.xml (define maven-ear-plugin in the pluginManagement section)
-- project1 pom.xml (multi-module project)
-- myJar-proj1
-- myWeb-proj1
-- myEar-proj1 (define maven-ear-plugin in the <build> section)
-- project2 pom.xml (multi-module project)
-- myJar-proj2
-- myWeb-proj2
-- myEar-proj2 (define maven-ear-plugin in the <build> section)
In order to achieve the merge behavior you should put the maven-ear-plugin under the plugins tag in the parent pom (rather than under pluginManagement).
Parent pom:
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-ear-plugin</artifactId>
<version>2.8</version>
<configuration>
<modules>
<jarModule>
<groupId>com.test</groupId>
<artifactId>artifact1</artifactId>
</jarModule>
<jarModule>
<groupId>com.test</groupId>
<artifactId>artifact2</artifactId>
</jarModule>
</modules>
</configuration>
</plugin>
</plugins>
</build>
EDIT
After OP's clarified projects structure: the attribute combine.children="append" on the modules element, in the child projects:
<modules combine.children="append">
<jarModule>
<groupId>com.test</groupId>
<artifactId>artifact3</artifactId>
</jarModule>
</modules>
The parent should still define the plugin only in pluginManagement.

Resources