Maven mulit-module dependencies, - package does not exist (maven plugin classloader) - java

I have a multi module maven project with the following setup.
/root/pom.xml
/root/core/proj1/pom.xml
/root/core/proj2/pom.xml
/root/support
/root/support/proj3/pom.xml
Parent pom is as follows (including only the relevant parts)
<groupId>com.mycompany.abc</groupId>
<artifactId>platform</artifactId>
<version>1.0</version>
<packaging>pom</packaging>
<name>platform-parent</name>
<modules>
<module>support/proj3-service</module>
<module>core/proj1-service</module>
<module>core/proj2-service</module>
</modules>
proj1/pom.xml is as follows,
<artifactId>proj1</artifactId>
<version>1.0</version>
<packaging>jar</packaging>
<parent>
<groupId>com.mycompany.abc</groupId>
<artifactId>platform</artifactId>
<version>1.0</version>
<relativePath>../../pom.xml</relativePath>
</parent>
proj2/pom.xml is as follows,
<artifactId>proj2</artifactId>
<version>1.0</version>
<packaging>jar</packaging>
<parent>
<groupId>com.mycompany.abc</groupId>
<artifactId>platform</artifactId>
<version>1.0</version>
<relativePath>../../pom.xml</relativePath>
</parent>
Now, in proj3/pom.xml, im adding proj1 and proj2 as dependencies,
<artifactId>proj3</artifactId>
<version>1.0</version>
<packaging>jar</packaging>
<parent>
<groupId>com.mycompany.abc</groupId>
<artifactId>platform</artifactId>
<version>1.0</version>
<relativePath>../../pom.xml</relativePath>
</parent>
<dependencies>
<dependency>
<groupId>com.mycompany.abc</groupId>
<artifactId>proj1</artifactId>
<version>1.0</version>
</dependency>
<dependency>
<groupId>com.mycompany.abc</groupId>
<artifactId>proj2</artifactId>
<version>1.0</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
...
</plugin>
</plugins>
</build>
The plugin in project 3 wants to query classes belonging to proj1 and proj2.
As per the plugin classloader documentation,
Please note that the plugin classloader does neither contain the dependencies of the current project nor its build output.
When a build plugin is executed, the thread's context classloader is set to the plugin classloader.
is there a way to make the plugin classloader aware of the other modules?

The problem is in the modules tag of the parent pom.
Instead of :
<modules>
<module>support/proj3-service</module>
<module>core/proj1-service</module>
<module>core/proj2-service</module>
</modules>
It should be :
<modules>
<module>support/proj3</module>
<module>core/proj1</module>
<module>core/proj2</module>
</modules>

If you want to add additional .jars for maven plugins to use/see, you can add dependencies to plugins.
Something like that:
<build><plugins><plugin>
<!-- other plugin option -->
<dependencies>
<dependency>
<groupId>com.mycompany.abc</groupId>
<artifactId>proj1</artifactId>
<version>1.0</version>
</dependency>
<dependency>
<groupId>com.mycompany.abc</groupId>
<artifactId>proj2</artifactId>
<version>1.0</version>
</dependency>
</dependencies>
</plugin></plugins></build>

Related

Spring boot deployments could not see .class file

In my project i build a multi modules dependency application , it is running perfectly in compilation/development mode , but when packaging it in a war file , it gives me NoClassDefFound for entity class which I used in Controller module.
The project structure is as follow :
1. Project root
1.1 Controller dependency module
1.2 Model dependency module
1.3 Core dependency module
and the root pom file is packaging as pom and all others are Jar except Controller module which is packaging as War file; as a test I tried to build only Controller with Model dependency only and the pom file for both are attached here :
Root 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.egabi.fatca</groupId>
<artifactId>fatca</artifactId>
<version>1.0.0</version>
<packaging>pom</packaging>
<name>fatca</name>
<url>http://maven.apache.org</url>
<description>Structure project for FATCA</description>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.10.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
</properties>
<modules>
<module>model</module>
<module>common</module>
<module>core</module>
<module>api</module>
</modules>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
<!--<distributionManagement>-->
<!--<repository>-->
<!--<id>releases</id>-->
<!--<url>http://10.3.1.73:9990/content/repositories/releases</url>-->
<!--</repository>-->
<!--</distributionManagement>--></project>
The Model 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>
<artifactId>fatca-model</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<url>http://maven.apache.org</url>
<name>model</name>
<description>Model layer for fatca</description>
<parent>
<groupId>com.egabi.fatca</groupId>
<artifactId>fatca</artifactId>
<version>1.0.0</version>
</parent>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>com.oracle</groupId>
<artifactId>ojdbc7</artifactId>
<version>12.1.0.1</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
and finally the Controller 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>
<artifactId>fatca-api</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>war</packaging>
<name>api</name>
<description>Controller layer for fatca</description>
<parent>
<groupId>com.egabi.fatca</groupId>
<artifactId>fatca</artifactId>
<version>1.0.0</version>
</parent>
<properties>
<start-class>com.egabi.fatca.FatcaApplication</start-class>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>com.egabi.fatca</groupId>
<artifactId>fatca-model</artifactId>
<version>0.0.1-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
<version>2.5</version>
<scope>provided</scope>
</dependency>
</dependencies>
<!--<repositories>-->
<!--<repository>-->
<!--<id>spring-snapshots</id>-->
<!--<name>Spring Snapshots</name>-->
<!--<url>http://repo.spring.io/snapshot</url>-->
<!--<snapshots>-->
<!--<enabled>true</enabled>-->
<!--</snapshots>-->
<!--</repository>-->
<!--<repository>-->
<!--<id>spring-milestones</id>-->
<!--<name>Spring Milestones</name>-->
<!--<url>http://repo.spring.io/milestone</url>-->
<!--<snapshots>-->
<!--<enabled>false</enabled>-->
<!--</snapshots>-->
<!--</repository>-->
<!--</repositories>-->
<!--<pluginRepositories>-->
<!--<pluginRepository>-->
<!--<id>spring-snapshots</id>-->
<!--<name>Spring Snapshots</name>-->
<!--<url>http://repo.spring.io/snapshot</url>-->
<!--<snapshots>-->
<!--<enabled>true</enabled>-->
<!--</snapshots>-->
<!--</pluginRepository>-->
<!--<pluginRepository>-->
<!--<id>spring-milestones</id>-->
<!--<name>Spring Milestones</name>-->
<!--<url>http://repo.spring.io/milestone</url>-->
<!--<snapshots>-->
<!--<enabled>false</enabled>-->
<!--</snapshots>-->
<!--</pluginRepository>-->
<!--</pluginRepositories>-->
<!--<build>-->
<!--<plugins>-->
<!--<plugin>-->
<!--<groupId>org.springframework.boot</groupId>-->
<!--<artifactId>spring-boot-maven-plugin</artifactId>-->
<!--</plugin>-->
<!--</plugins>-->
<!--</build>-->
</project>
Also note i figured out that the model jar is exist in the final generated war ; and after investigating i found that parent module like api cannot see the packages defined in its child modules like Model , Core ,etc.
I tried to use #ComponentScan and it worked between 2 modules only, so my issue now is to make api parent see all his child modules .
I searched for my question in some solution here but it did not solve my issue , so your help is appreciated.
A few things:
In your child project the dependency should be
<dependency>
<groupId>com.egabi.fatca</groupId>
<artifactId>fatca-model</artifactId>
<version>${project.version}</version>
</dependency>
Also your child projects needs only an artifactId, they will get their groupId and version from the parent, take those tags out (version and groupId) from the children.
Build the whole thing as one multi project from the root:
mvn clean install
i think you need to use this annotations
#EnableJpaRepositories(basePackages = "your.path.to.module.data.dao")
#EntityScan(basePackages = "your.path.to.module.data.entity")
you have set the #ComponentScan with the right path to find the file.
something like this.
#Configuration
#ComponentScan("com.your.path")
public class ContextWithJavaConfig {
}
or for multiple paths,
something like this.
#Configuration
#ComponentScan(basePackages={"com.firstpackage","com.secondpackage"})
public class ContextWithJavaConfig {
}

EAR with WARs containing different versions of dependencies

Here is my requirement
EAR
WAR (Code)
----Dependency A v1
WAR (Code same as WAR above)
----Dependency A v2
AS the code for WAR project is same I don't want to create multiple code base for WAR project. So I'm looking for EAR pom.xml in such a way that maven builds the WAR with dependency A v1 which can be passed as some property while building WAR.
EAR pom.xml
...
(modules)
(webmodule)
(artifact)WAR(/artifact)
dependency version v1
(content-path)/warwithv1(/content-path)
(/webmodule)
(webmodule)
(artifact)WAR(/artifact)
dependency version v2
(content-path)/warwithv2(/content-path)
(/webmodule)
...
Thanks
Sorry for the XML Tags
EDIT: Answer changed after clarification in comments.
The question as I now understand it is: How does one use a single POM to create 2 WAR files that both have the same source code but different dependencies.
The solution I propose is to create a parent POM that will specify one module per WAR. One of the modules will contain the source code for the war and specify one version of dependencies. The second module will refer to the first module for its source code and will specify a second version of dependencies.
Here is my high level project structure:
Here is the top level (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>maven-war-diff-depend</groupId>
<artifactId>maven-war-diff-depend</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>pom</packaging>
<modules>
<module>module1</module>
<module>module2</module>
</modules>
</project>
Module1 will specify v2.3 of log4j2, here is its 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>
<parent>
<groupId>maven-war-diff-depend</groupId>
<artifactId>maven-war-diff-depend</artifactId>
<version>0.0.1-SNAPSHOT</version>
</parent>
<artifactId>module1</artifactId>
<packaging>war</packaging>
<dependencies>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
<version>2.3</version>
</dependency>
</dependencies>
</project>
Module2 will specify v2.8.1 of log4j2 and point to module1 for its source code and web.xml file. Note that you may need to do additional work to refer to any other resources in module1 such as adding more maven plugins and configuration.
Here is the module2 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>
<parent>
<groupId>maven-war-diff-depend</groupId>
<artifactId>maven-war-diff-depend</artifactId>
<version>0.0.1-SNAPSHOT</version>
</parent>
<artifactId>module2</artifactId>
<packaging>war</packaging>
<build>
<sourceDirectory>../module1/src/main/java</sourceDirectory>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.2</version>
<configuration>
<webXml>../module1/src/main/webapp/WEB-INF/web.xml</webXml>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
<version>2.8.1</version>
</dependency>
</dependencies>
</project>
Note that I only have a single Java class in module1 just to show that in fact this class is compiled and included in both module1 and module2:
Here are the results of a simple clean install build:
Once you have the two WAR files built it's fairly simple to add another module (this would be your EAR) which will include both of the WAR files - I believe that is your final goal.
So, create a third module:
Add the new module to your root level (parent) POM:
<module>module3</module>
Create the necessary configuration in your new module's POM. This involves adding dependencies on the other two artifacts you create with module1 and module2 and configuring the ear plugin as needed.
<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>maven-war-diff-depend</groupId>
<artifactId>maven-war-diff-depend</artifactId>
<version>0.0.1-SNAPSHOT</version>
</parent>
<artifactId>module3</artifactId>
<packaging>ear</packaging>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-ear-plugin</artifactId>
<version>2.10</version>
<configuration>
<applicationXml>${basedir}/target/application.xml</applicationXml>
<modules>
<webModule>
<groupId>maven-war-diff-depend</groupId>
<artifactId>module1</artifactId>
</webModule>
<webModule>
<groupId>maven-war-diff-depend</groupId>
<artifactId>module2</artifactId>
</webModule>
</modules>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>maven-war-diff-depend</groupId>
<artifactId>module1</artifactId>
<version>0.0.1-SNAPSHOT</version>
<type>war</type>
</dependency>
<dependency>
<groupId>maven-war-diff-depend</groupId>
<artifactId>module2</artifactId>
<version>0.0.1-SNAPSHOT</version>
<type>war</type>
</dependency>
</dependencies>
</project>
Now when you build it will create an EAR that includes the 2 WARs generated by module1 and module2. The ear in this example is simply called module3:
EDIT: Original answer re-added per request in comments.
Here is the POM from the original proposal - using two profiles to specify different dependency versions. As before please note that it's not a good idea to include servlet api inside of a WAR file, it's just being used here as a visual example to show how common dependencies are specified.
<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>maven-war-diff-depend</groupId>
<artifactId>maven-war-diff-depend</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>pom</packaging>
<dependencies>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>3.1.0</version>
</dependency>
</dependencies>
<profiles>
<profile>
<id>v2.3</id>
<dependencies>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
<version>2.3</version>
</dependency>
</dependencies>
</profile>
<profile>
<id>v2.8.1</id>
<dependencies>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
<version>2.8.1</version>
</dependency>
</dependencies>
</profile>
</profiles>
</project>

Add a common folder to both of my modules using Maven

I have a Maven build that has two modules (Server / Client) and I wish to create a folder containing shared methods by both of them.
What should I add to my pom.xml(s) in order to have a successful build?
I have 3 poms, a parent one in the root of the project, and two other ones respectively in the server folder and the client one.
Here is my 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>com.christopher.kade</groupId>
<artifactId>jcoinche</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>pom</packaging>
<name>jcoinche</name>
<url>http://maven.apache.org</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<modules>
<module>client</module>
<module>server</module>
</modules>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.netty</groupId>
<artifactId>netty-all</artifactId> <!-- Use 'netty-all' for 4.0 or above -->
<version>4.1.6.Final</version>
<scope>compile</scope>
</dependency>
</dependencies>
</project>
You should place the classes you in client and server in a third module.
and then add a dependency to that in the client and server modules.
You can do something similar to this. Within your main(parent) pom.xml, add the module and its dependency.
<modules>
<module>client</module>
<module>server</module>
<module>jcoinche-common</module>
</modules>
<dependencies>
..
..
<dependency>
<groupId>com.christopher.kade</groupId>
<artifactId>jcoinche-common</artifactId>
<version>${project.version}</version>
<!-- ^=== assumes same version as project -->
</dependency>
..
..
Then, in your submodules that require the jcoinche-common module, just add a dependency there as well:
<dependency>
<groupId>com.christopher.kade</groupId>
<artifactId>jcoinche-common</artifactId>
</dependency>
Thats it.

maven cannot build child module from child directory

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>

maven-ear-plugin, Cannot find 'version' in class org.apache.maven.plugin.ear.EjbModule

Desperatley trying to create a EAR bundle with some modules, using the maven EAR plugin version 2.10.1 with Maven 3. There is a problem with the generate-application-xml goal, I´m getting the error:
Failed to execute goal org.apache.maven.plugins:maven-ear-plugin:2.10.1:generate-application-xml (default-generate-application-xml) on project wineapp-ear: Unable to parse configuration of mojo org.apache.maven.plugins:maven-ear-plugin:2.10.1:generate-application-xml for parameter version: Cannot find 'version' in class org.apache.maven.plugin.ear.EjbModule -> [Help 1]
here is the pom.xml snippet:
<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>
<artifactId>wineapp-parent</artifactId>
<groupId>com.jueggs</groupId>
<version>1.0.0</version>
</parent>
<artifactId>wineapp-ear</artifactId>
<packaging>ear</packaging>
<name>wineapp-ear</name>
<dependencies>
<dependency>
<groupId>com.jueggs</groupId>
<artifactId>wineapp-ejb</artifactId>
<version>1.0.0</version>
<type>ejb</type>
</dependency>
<dependency>
<groupId>com.jueggs</groupId>
<artifactId>wineapp-web</artifactId>
<version>1.0.0</version>
<type>war</type>
</dependency>
<dependency>
<groupId>com.jueggs</groupId>
<artifactId>wineapp-jpa</artifactId>
<version>1.0.0</version>
</dependency>
<dependency>
<groupId>com.jueggs</groupId>
<artifactId>wineapp-common</artifactId>
<version>1.0.0</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-ear-plugin</artifactId>
<version>2.10.1</version>
<configuration>
<!--<version>6</version>-->
<!--<applicationXml>/src/main/application/META-INF/</applicationXml>-->
<modules>
<ejbModule>
<groupId>com.jueggs</groupId>
<artifactId>wineapp-ejb</artifactId>
<version>1.0.0</version>
<bundleFileName>ejb.jar</bundleFileName>
</ejbModule>
<webModule>
<groupId>com.jueggs</groupId>
<artifactId>wineapp-web</artifactId>
<version>1.0.0</version>
<bundleFileName>web.war</bundleFileName>
</webModule>
<jarModule>
<groupId>com.jueggs</groupId>
<artifactId>wineapp-common</artifactId>
<version>1.0.0</version>
<bundleDir>lib</bundleDir>
<bundleFileName>common.jar</bundleFileName>
</jarModule>
<jarModule>
<groupId>com.jueggs</groupId>
<artifactId>wineapp-jpa</artifactId>
<version>1.0.0</version>
<bundleDir>lib</bundleDir>
<bundleFileName>jpa.jar</bundleFileName>
</jarModule>
</modules>
</configuration>
</plugin>
</plugins>
</build>
what the hack is wrong here? or is it just a f.. typo in the xml? inside the configuration element, the automatic tag detection by IDE (how is the word for that..) also not working, but i compared it with examples nearly a thousand times. don´t know what else matters for error finding, there´s also a parent pom
An module did not have a version tag see modules. The version is already defined by the dependency blog and the module blog is just use for renaming the artifacts in the ear file (since you define a new bundleFileName). So try to remove all version tags in your modules like this:
<modules>
<ejbModule>
<groupId>com.jueggs</groupId>
<artifactId>wineapp-ejb</artifactId>
<bundleFileName>ejb.jar</bundleFileName>
</ejbModule>
<webModule>
<groupId>com.jueggs</groupId>
<artifactId>wineapp-web</artifactId>
<bundleFileName>web.war</bundleFileName>
</webModule>
<jarModule>
<groupId>com.jueggs</groupId>
<artifactId>wineapp-common</artifactId>
<bundleDir>lib</bundleDir>
<bundleFileName>common.jar</bundleFileName>
</jarModule>
<jarModule>
<groupId>com.jueggs</groupId>
<artifactId>wineapp-jpa</artifactId>
<bundleDir>lib</bundleDir>
<bundleFileName>jpa.jar</bundleFileName>
</jarModule>
</modules>
Or better remove the complete modules blog because I do not think its important for you to rename the dependencies in the ear and it is OK to use the Maven default names.

Categories

Resources