I am trying to pull out the version number of the POM and all the dependencies to a environment variable. For example:
<project
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven- 4.0.0.xsd"
xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema- instance">
<modelVersion>4.0.0</modelVersion>
<artifactId>example-assembly</artifactId>
<name>example-assembly</name>
<properties>
<current.version>${env.CURRENTVERSION}</current.version>
</properties>
<dependencies>
<dependency>
<groupId>com.example.demo</groupId>
<artifactId>exceptions</artifactId>
<version>${current.version}</version>
</dependency>
<dependencies>
<packaging>war</packaging>
<version>${current.version}</version>
</project>
With the above setup, when I run mvn clean command I am getting following error:
dependencies.dependency.version for example-assembly:war must be a valid version but is '${env.CURRENTVERSION}'
Any idea about what could be the issue?
Note: I am running maven in windows OS
There is a better alternative for updating Versions in pom.xml than using environment variables inside pom.xml: Versions Maven Plugin. This allows you to change pom.xml using maven command line.
Sample scenario
Project Structure:
+ P (Parent - Version 1.0.0-SNAPSHOT)
-- C1 (Child Project 1 - Version 1.0.0-SNAPSHOT)
-- C2 (Child Project 2 - Version 1.0.0-SNAPSHOT also depends on C1)
Task
You want to change version in all pom.xml files to 1.0.1-SNAPSHOT
Parent pom.xml
<project>
<modelVersion>4.0.0</modelVersion>
<groupId>sample</groupId>
<artifactId>p</artifactId>
<version>1.0.0-SNAPSHOT</version>
<name>Parent</name>
<packaging>pom</packaging>
<modules>
<module>c1</module>
<module>c2</module>
</modules>
</project>
Child Project 1 pom.xml
<project>
<modelVersion>4.0.0</modelVersion>
<artifactId>c1</artifactId>
<name>Child Project 1</name>
<packaging>jar</packaging>
<parent>
<groupId>sample</groupId>
<artifactId>p</artifactId>
<version>1.0.0-SNAPSHOT</version>
</parent>
</project>
Child Project 2 pom.xml
<project>
<modelVersion>4.0.0</modelVersion>
<artifactId>c2</artifactId>
<name>Child Project 2</name>
<packaging>jar</packaging>
<parent>
<groupId>sample</groupId>
<artifactId>p</artifactId>
<version>1.0.0-SNAPSHOT</version>
</parent>
<dependencies>
<dependency>
<groupId>sample</groupId>
<artifactId>c1</artifactId>
<version>1.0.0-SNAPSHOT</version>
</dependency>
</dependencies>
</project>
Command
Command to set new version in all pom.xml files
mvn -B -DnewVersion=1.0.1-SNAPSHOT versions:set
In case new version is represented by environment variable CURRENTVERSION
mvn -B -DnewVersion=$CURRENTVERSION versions:set
Here -B means --batch-mode (so new version won't be prompted on console)
Resultant files would be
Parent pom.xml
<project>
<modelVersion>4.0.0</modelVersion>
<groupId>sample</groupId>
<artifactId>p</artifactId>
<version>1.0.1-SNAPSHOT</version>
<name>Parent</name>
<packaging>pom</packaging>
<modules>
<module>c1</module>
<module>c2</module>
</modules>
</project>
Child Project 1 pom.xml
<project>
<modelVersion>4.0.0</modelVersion>
<artifactId>c1</artifactId>
<name>Child Project 1</name>
<packaging>jar</packaging>
<parent>
<groupId>sample</groupId>
<artifactId>p</artifactId>
<version>1.0.1-SNAPSHOT</version>
</parent>
</project>
Child Project 2 pom.xml
<project>
<modelVersion>4.0.0</modelVersion>
<artifactId>c2</artifactId>
<name>Child Project 2</name>
<packaging>jar</packaging>
<parent>
<groupId>sample</groupId>
<artifactId>p</artifactId>
<version>1.0.1-SNAPSHOT</version>
</parent>
<dependencies>
<dependency>
<groupId>sample</groupId>
<artifactId>c1</artifactId>
<version>1.0.1-SNAPSHOT</version>
</dependency>
</dependencies>
</project>
The variable you define has the scope in the same pom.xml only and cannot be used in any other pom.
If you want to define the variable globally define it in settings.xml of maven.
Define the variable env.CURRENTVERSION somewhere in the the same pom, root pom or settings.xml
or else provide the exact version value in its place.
<properties>
<current.version>'your correct version'</current.version>
</properties>
e.g.
<properties>
<current.version>1.0.0</current.version>
</properties>
Related
I am trying to build multi module project using maven. following are the modules
1) base
2) common
3) client
4) service
pom.xml of base project is
<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>com.se</groupId>
<artifactId>base</artifactId>
<packaging>pom</packaging>
<version>0.1-SNAPSHOT</version>
<name>base Maven Webapp</name>
<url>http://maven.apache.org</url>
<modules>
<module>common</module>
<module>client</module>
<module>service</module>
</modules>
<dependencies>
...
</dependencies>
<build>
<finalName>base</finalName>
<plugins>
....
</plugins>
</build>
</project>
pom.xml of common module
<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>com.vdcommon</groupId>
<artifactId>common</artifactId>
<packaging>jar</packaging>
<version>0.1-SNAPSHOT</version>
<name>VDCommon Maven Webapp</name>
<url>http://maven.apache.org</url>
<parent>
<groupId>com.se</groupId>
<artifactId>base</artifactId>
<version>0.1-SNAPSHOT</version>
</parent>
<dependencies>
...
</dependencies>
<build>
<finalName>common</finalName>
<plugins>
...
</plugins>
</build>
</project>
pom.xml of client module
<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.se</groupId>
<artifactId>base</artifactId>
<version>0.1-SNAPSHOT</version>
</parent>
<groupId>com.vdclient</groupId>
<artifactId>client</artifactId>
<packaging>jar</packaging>
<version>0.1-SNAPSHOT</version>
<name>VDClient Maven Webapp</name>
<url>http://maven.apache.org</url>
<properties>
....
</properties>
<dependencies>
<dependency>
<groupId>com.vdcommon</groupId>
<artifactId>common</artifactId>
<version>0.1-SNAPSHOT</version>
</dependency>
....
</dependencies>
<build>
<finalName>client</finalName>
<plugins>
<plugin>
....
</plugin>
</plugins>
</build>
</project>
pom.xml of service module
<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.se</groupId>
<artifactId>base</artifactId>
<version>0.1-SNAPSHOT</version>
</parent>
<groupId>com.vdservice</groupId>
<artifactId>service</artifactId>
<packaging>war</packaging>
<version>0.0.1-SNAPSHOT</version>
<name>vdservcie Maven Webapp</name>
<url>http://maven.apache.org</url>
<properties>
....
</properties>
<dependencies>
....
<dependency>
<groupId>com.vdclient</groupId>
<artifactId>client</artifactId>
<version>0.1-SNAPSHOT</version>
</dependency>
....
</dependencies>
<build>
<finalName>service</finalName>
<plugins>
....
</plugins>
</build>
</project>
'service' module is a war file to deploy and test. I am able to do maven install for all the modules successfully and I am able to see the jar files of client and common modules in dependency tree.
[INFO] +- com.vdclient:client:jar:0.1-SNAPSHOT:compile
[INFO] | \- com.vdcommon:common:jar:0.1-SNAPSHOT:compile
But when I try to deploy the service war file into tomcat server I am getting ClassNotFoundException for a class which is present in client module
Caused by: java.lang.TypeNotPresentException: Type logical.lookuplogicalds_ws.PartyLookupDS not present
at sun.reflect.generics.factory.CoreReflectionFactory.makeNamedType(CoreReflectionFactory.java:117)
at sun.reflect.generics.visitor.Reifier.visitClassTypeSignature(Reifier.java:125)
at sun.reflect.generics.tree.ClassTypeSignature.accept(ClassTypeSignature.java:49)
at sun.reflect.generics.visitor.Reifier.reifyTypeArguments(Reifier.java:68)
at sun.reflect.generics.visitor.Reifier.visitClassTypeSignature(Reifier.java:138)
at sun.reflect.generics.tree.ClassTypeSignature.accept(ClassTypeSignature.java:49)
at sun.reflect.generics.repository.ConstructorRepository.getParameterTypes(ConstructorRepository.java:94)
at java.lang.reflect.Executable.getGenericParameterTypes(Executable.java:283)
at java.lang.reflect.Method.getGenericParameterTypes(Method.java:283)
at java.beans.FeatureDescriptor.getParameterTypes(FeatureDescriptor.java:387)
at java.beans.MethodDescriptor.setMethod(MethodDescriptor.java:116)
at java.beans.MethodDescriptor.<init>(MethodDescriptor.java:72)
at java.beans.MethodDescriptor.<init>(MethodDescriptor.java:56)
at java.beans.Introspector.getTargetMethodInfo(Introspector.java:1205)
at java.beans.Introspector.getBeanInfo(Introspector.java:426)
at java.beans.Introspector.getBeanInfo(Introspector.java:173)
at org.springframework.beans.CachedIntrospectionResults.<init>(CachedIntrospectionResults.java:277)
at org.springframework.beans.CachedIntrospectionResults.forClass(CachedIntrospectionResults.java:186)
at org.springframework.beans.BeanWrapperImpl.getCachedIntrospectionResults(BeanWrapperImpl.java:321)
at org.springframework.beans.BeanWrapperImpl.getPropertyDescriptors(BeanWrapperImpl.java:328)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.filterPropertyDescriptorsForDependencyCheck(AbstractAutowireCapableBeanFactory.java:1305)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.filterPropertyDescriptorsForDependencyCheck(AbstractAutowireCapableBeanFactory.java:1285)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1143)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:519)
... 33 more
Caused by: java.lang.ClassNotFoundException: logical.lookuplogicalds_ws.PartyLookupDS
at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1352)
at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1180)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:348)
at sun.reflect.generics.factory.CoreReflectionFactory.makeNamedType(CoreReflectionFactory.java:114)
... 56 more
can anyone please help me on fixing this issue?
You need to make sure that you're bundling all of the libraries into the war file. If it builds correctly but the war is missing the related libraries it will fail when you deploy it.
For example, at package time where are you putting the libraries you depend on? And how are you building your war to include those libraries?
Most likely you can solve your problem using the Maven War Plugin. It will help you package all of the libraries you need into your war.
https://maven.apache.org/plugins/maven-war-plugin/
That will setup your maven project to create your war with what you need.
We have a multi module project where we define several dependencies in parent pom under dependencyManagement tag to manage dependencies version.
It works fine for several modules but one.
Parent 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>my.org.product</groupId>
<artifactId>product-parent</artifactId>
<version>1.0.0-SNAPSHOT</version>
<packaging>pom</packaging>
<properties>
<parade-web.version>2.0.0</parade-web.version>
<!-- other properties -->
</properties>
<modules>
<module>../ProductWeb</module>
<!-- other modules -->
</modules>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>my.org.parade</groupId>
<artifactId>ParadeWeb</artifactId>
<version>${parade-web.version}</version>
</dependency>
<!-- other dependencies -->
</dependencies>
</dependencyManagement>
</project>
ProductWeb pom
<?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>my.org.product</groupId>
<artifactId>product-parent</artifactId>
<version>1.0.0-SNAPSHOT</version>
<relativePath>../productparent</relativePath>
</parent>
<artifactId>ProductWeb</artifactId>
<packaging>war</packaging>
<version>1.0.0-SNAPSHOT</version>
<dependencies>
<dependency> <!-- 'dependencies.dependency.version' for my.org.parade:ParadeWeb:jar is missing. -->
<groupId>my.org.parade</groupId>
<artifactId>ParadeWeb</artifactId>
<type>war</type>
</dependency>
<!-- other dependencies -->
</dependencies>
</project>
If I add <version>${parade-web.version}</version> in my ProductWeb pom, NetBeans warns me that
Overrides version defined in DependencyManagement. The managed version is 2.12.2-RELEASE.
The only difference between this dependency and the other is the war type, but I don't get why dependency management fails to sets its version.
UPDATE
I managed to omit version tag but I needed to add <type>war</type> on both parent and child.
I don't understand. Does parent try to resolve dependency version looking for a war but then doesn't pass it through its children?
Add <type>war</type> to the dependencyManagement. This should do the trick.
I have a maven project with a parent pom and child modules, structured like this:
root/pom.xml
root/parent/pom.xml
root/child1/pom.xml
root/child2/pom.xml
root/child2/child21/pom.xml
Every child pom and the root pom declare root/parent as their parent. child21 has child1 as a dependency.
When I try to execute mvn install from the child1 directory, maven successfully builds and installs the child1 jar. But when i execute mvn install from either the child2 or child21 directories, maven errors out with the following:
[ERROR] Failed to execute goal on project child21: Could not resolve dependencies for project groupId:child21:jar:0.0.1-SNAPSHOT: Failed to collect dependencies at groupId:child1:jar:0.0.1-SNAPSHOT: Failed to read artifact descriptor for groupId:child1:jar:0.0.1-SNAPSHOT: Could not find artifact groupId:parent:pom:0.0.1-SNAPSHOT in jme-repo (http://updates.jmonkeyengine.org/maven/) -> [Help 1]
I have tried googling for what might be wrong with my project structure with no luck. Can anyone help suggest ways to get child21 to build?
My poms contain:
Root
<parent>
<groupId>groupId</groupId>
<artifactId>parent</artifactId>
<version>0.0.1-SNAPSHOT</version>
<relativePath>./parent/pom.xml</relativePath>
</parent>
<artifactId>root</artifactId>
<packaging>pom</packaging>
<modules>
<module>child1</module>
<module>child2</module>
</modules>
Parent
<groupId>groupId</groupId>
<artifactId>parent</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>pom</packaging>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>groupId</groupId>
<artifactId>child1</artifactId>
<version>${project.version}</version>
</dependency>
...
</dependencies>
<dependencyManagement>
<repositories>
<repository>
<id>jme-repo</id>
<name>JME3 Official Maven Repo</name>
<url>http://updates.jmonkeyengine.org/maven/</url>
</repository>
</repositories>
<build>
<plugins>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.2</version>
<configuration>
<source>${java.source.version}</source>
<target>${java.target.version}</target>
</configuration>
</plugins>
</build>
Child 1
<parent>
<groupId>groupId</groupId>
<artifactId>parent</artifactId>
<version>0.0.1-SNAPSHOT</version>
<relativePath>../parent/pom.xml</relativePath>
</parent>
<artifactId>child1</artifactId>
<packaging>jar</packaging>
<dependencies>...</dependencies>
Child 2
<parent>
<groupId>groupId</groupId>
<artifactId>parent</artifactId>
<version>0.0.1-SNAPSHOT</version>
<relativePath>../parent/pom.xml</relativePath>
</parent>
<artifactId>child2</artifactId>
<packaging>pom</packaging>
<modules>
<module>child21</module>
</modules>
Child 21
<parent>
<groupId>groupId</groupId>
<artifactId>parent</artifactId>
<version>0.0.1-SNAPSHOT</version>
<relativePath>../../parent/pom.xml</relativePath>
</parent>
<artifactId>child21</artifactId>
<packaging>jar</packaging>
<dependencies>
<dependency>
<groupId>groupId</groupId>
<artifactId>child1</artifactId>
</dependency>
</dependencies>
UPDATE WITH SOLUTION
Based on the accepted answer below, I added the parent project as a module of the root pom:
<parent>
<groupId>groupId</groupId>
<artifactId>parent</artifactId>
<version>0.0.1-SNAPSHOT</version>
<relativePath>./parent/pom.xml</relativePath>
</parent>
<artifactId>root</artifactId>
<packaging>pom</packaging>
<modules>
<module>parent</module>
<module>child1</module>
<module>child2</module>
</modules>
Then when developers build the project for the first time, the parent pom is installed. Subsequently they will be able to build the child2 and child21 projects independently.
This is a pretty awkward module structure, but it can still work. The problem is that when you are building module child21 (or child2), the child1 dependency is not a part of the current build, but is looked up in the repository. So is the parent of that dependency, which is the parent module. However, I assume, parent was never installed there - if you run mvn clean install on root, it does not build the parent, which is only referenced in the child modules by relative paths.
To fix it you must first install the parent POM into the repository. Run mvn install in the parent module. After that, build child1 - it will be installed into the repository as well. Now everything what is needed for building module child21 is available in the repository.
Change child21 to inherit from its parent - child2, see below:
<parent>
<groupId>groupId</groupId>
<artifactId>child2</artifactId>
<version>0.0.1-SNAPSHOT</version>
</parent>
I have two modules(maven projects) in parent maven project: android-module and server-module. This two modules uses identical models(POJO - classes). So I want extract models from both modules and make new module in parent project.
So I whant this:
--Project
|--android-module
| -- pom.xml
|--server-module
| -- pom.xml
-- pom.xml
remake to this:
--Project
|--android-module
| -- pom.xml
|--server-module
| -- pom.xml
|--models-module
| -- pom.xml
-- pom.xml
At the same time I want to root pom.xml compiles and build jar from models-module and store jar in my local repository. Then child pom.xml's were taking it from the repository and included in the android and server modules.
Question: How to tell maven to build and store jar in my local repository automatically.
Is it possible? If no - please, give me some ideas.... Thnks
Just run mvn install. This will install the packaged jar into your local repo in ~/.m2
Make sure you run maven from the root pom
The solution is found. It was much easier.
parent pom.xml:
...
<groupId>com.lutshe</groupId>
<artifactId>doiter</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>pom</packaging>
<modules>
<module>doiter-android</module>
<module>doiter-server</module>
<module>doiter-model</module>
</modules>
...
child1 (android project) pom.xml:
...
<parent>
<groupId>com.lutshe</groupId>
<artifactId>doiter</artifactId>
<version>1.0-SNAPSHOT</version>
</parent>
<groupId>com.lutshe</groupId>
<artifactId>doiter-android</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>apk</packaging>
<dependencies>
<dependency>
<groupId>com.lutshe</groupId>
<artifactId>doiter-models</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
</dependencies>
...
child2 (server) pom.xml:
...
<parent>
<groupId>com.lutshe</groupId>
<artifactId>doiter</artifactId>
<version>1.0-SNAPSHOT</version>
</parent>
<groupId>com.doiter.server</groupId>
<artifactId>doiter-server</artifactId>
<version>0.1.0</version>
<packaging>jar</packaging>
<dependencies>
<dependency>
<groupId>com.lutshe</groupId>
<artifactId>doiter-models</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
</dependencies>
...
child3 (shared models) pom.xml:
...
<parent>
<groupId>com.lutshe</groupId>
<artifactId>doiter</artifactId>
<version>1.0-SNAPSHOT</version>
</parent>
<groupId>com.lutshe</groupId>
<artifactId>doiter-model</artifactId>
<version>1.0-SNAPSHOT</version>
...
Could anybody suggest me an solution with the following exception. I am going to create a multi-module project.
Parent Project name is LOGICBACKEND
child project name is DBAccess
I need to have ear file of LOGICBACKEND which should contain DBAccess prjoects jar file.
I am getting following exception when i run mav clean install -P Developer.
[ERROR]The project com.project1.Database:DBAccess:1.0-SNAPSHOT (C:\Project1\DBAccess\pom.xml) has 1 error
[ERROR]Invalid packaging for parent POM com.project1.logic:LOGIC:1.0-SNAPSHOT (C:\Project1\pom.xml), must be "pom" but is "ear" # com.project1.logic:LOGIC:1.0-SNAPSHOT, C:\Project1\pom.xml, line 6, column 13
This is how part of my parent pom.xml looks
<modelVersion>4.0.0</modelVersion>
<groupId>com.project1.logic</groupId>
<artifactId>LOGICBACKEND</artifactId>
<packaging>ear</packaging>
<version>1.0-SNAPSHOT</version>
This is how child pom.xml looks
<groupId>com.project1.logic</groupId>
<artifactId>DBAccess</artifactId>
<packaging>ejb</packaging>
<name>DBAccess</name>
<version>1.0-SNAPSHOT</version>
<parent>
<groupId>com.project1.logic</groupId>
<artifactId>DBAccess</artifactId>
<version>1.0-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>
Could anybody help me here to understand what is going wrong here.
Thanks in advance for any help
This simple setup is a good start.
.
├── pom.xml
├── services
| ├── pom.xml
| └── src
| └── main
| └── java
| └── com
| └── stackoverflow
| └── MyEjbService.java
└── application
└── pom.xml
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.stackoverflow.Q13330930</groupId>
<artifactId>parent</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>pom</packaging>
<name>${project.artifactId}-${project.version}</name>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<modules>
<module>services</module>
<module>application</module>
</modules>
<dependencies>
</dependencies>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>com.stackoverflow.Q13330930</groupId>
<artifactId>services</artifactId>
<version>${project.version}</version>
<type>ejb</type>
</dependency>
</dependencies>
</dependencyManagement>
<build>
<plugins>
<plugin>
<artifactId>maven-ejb-plugin</artifactId>
<version>2.3</version>
<configuration>
<ejbVersion>3.1</ejbVersion>
</configuration>
</plugin>
</plugins>
</build>
</project>
services/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>
<parent>
<groupId>com.stackoverflow.Q13330930</groupId>
<artifactId>parent</artifactId>
<version>1.0-SNAPSHOT</version>
</parent>
<groupId>com.stackoverflow.Q13330930</groupId>
<artifactId>services</artifactId>
<packaging>ejb</packaging>
<name>${project.artifactId}-${project.version}</name>
</project>
application/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>
<parent>
<groupId>com.stackoverflow.Q13330930</groupId>
<artifactId>parent</artifactId>
<version>1.0-SNAPSHOT</version>
</parent>
<groupId>com.stackoverflow.Q13330930</groupId>
<artifactId>application</artifactId>
<packaging>ear</packaging>
<name>${project.artifactId}-${project.version}</name>
<dependencies>
<dependency>
<groupId>com.stackoverflow.Q13330930</groupId>
<artifactId>services</artifactId>
<type>ejb</type>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<artifactId>maven-ear-plugin</artifactId>
<version>2.7</version>
<configuration>
<defaultLibBundleDir>lib</defaultLibBundleDir>
</configuration>
</plugin>
</plugins>
</build>
</project>
You are trying to give the parent pom two functions - that is serving as a parent pom (packaging pom) and being the wrapper ear (packaging ear) - at the same time. To solve your issue you should create another maven module under your parent pom that has packaging ear and uses the maven-ear-plugin to define the output.
I got the similar error:
[ERROR]
[ERROR] Invalid packaging for parent POM sandbox:parent:6.5-SNAPSHOT, must be "pom" but is "jar" # sandbox:parent:6.5-SNAPSHOT
I figured out that the root cause was in parent version defined through properties:
<version>${revision}${changelist}</version>
As soon as I set version without referencing the properties the issue gone:
<version>6.5-SNAPSHOT</version>
Might be a maven bug.