I have the following hierarchy:
my-app
\__ pom.xml
\__ jar-module
\__ pom.xml
\__ webapp-module
\__ pom.xml
\__ core-module
\__ pom.xml
Where core-module acts as a library providing common code for webapp-module and jar-module.
webapp-module works just fine, it's generating a war as expected and the code from core-module is being used.
The problem is with jar-module. I have no idea why, but jar-module isn't outputting a jar, even when I select to run (in IntelliJ IDEA) a simple main with a println() it does run, but there's no jar on the target folder.
How can I solve this and make the jar-module output a jar?
I am not very experienced with Maven, my goal is to be able to use the same Jersey code on a local Glassfish and in a jar to be deployed at AWS Lambda Serverless Java Container so I can easily test it locally before deployment.
I would appreciate any corrections on my hierarchy and on pom errors as well.
my-app pom.xml has a packaging of pom, but core-module and jar-module have a packaging of jar and webapp-module has a packaging of war.
here are the POMs:
my-app 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/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.example.myapp</groupId>
<artifactId>myapp</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>pom</packaging>
<modules>
<module>core-module</module>
</modules>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>
</project>
core-module POM:
(I also tried it with <packaging>pom</packaging> and no jar skip properties, it didn't work)
<?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>
<parent>
<artifactId>myapp</artifactId>
<groupId>com.example.myapp</groupId>
<version>1.0-SNAPSHOT</version>
</parent>
<artifactId>webservice-core</artifactId>
<packaging>jar</packaging>
<modules>
<module>../jar-module</module>
<module>../webapp-module</module>
</modules>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<maven.deploy.skip>true</maven.deploy.skip>
<jar.skipIfEmpty>true</jar.skipIfEmpty>
<maven.install.skip>true</maven.install.skip>
<javax-ws-rs-version.version>2.1</javax-ws-rs-version.version>
<jersey.version>2.26</jersey.version>
</properties>
<dependencies>
<dependency>
<groupId>javax.ws.rs</groupId>
<artifactId>javax.ws.rs-api</artifactId>
<version>${javax-ws-rs-version.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.media</groupId>
<artifactId>jersey-media-json-jackson</artifactId>
<version>${jersey.version}</version>
</dependency>
</dependencies>
</project>
webapp-module 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/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<artifactId>core-module</artifactId>
<groupId>com.example.myapp</groupId>
<version>1.0-SNAPSHOT</version>
</parent>
<artifactId>webapp-module</artifactId>
<packaging>war</packaging>
<name>webapp Maven Webapp</name>
<url>http://maven.apache.org</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<jersey.version>2.26</jersey.version>
</properties>
<dependencies>
<dependency>
<artifactId>core-module</artifactId>
<groupId>com.example.myapp</groupId>
<version>1.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.containers</groupId>
<artifactId>jersey-container-servlet</artifactId>
<version>${jersey.version}</version>
<scope>provided</scope>
</dependency>
</dependencies>
<build>
<finalName>webapp</finalName>
</build>
</project>
jar-module 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/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<artifactId>core-module</artifactId>
<groupId>com.example.myapp</groupId>
<version>1.0-SNAPSHOT</version>
</parent>
<artifactId>jar-module</artifactId>
<packaging>jar</packaging>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<jersey.version>2.26</jersey.version>
<maven-shade-plugin.version>3.1.0</maven-shade-plugin.version>
</properties>
<dependencies>
<dependency>
<artifactId>core-module</artifactId>
<groupId>com.example.myapp</groupId>
<version>1.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>com.amazonaws.serverless</groupId>
<artifactId>aws-serverless-java-container-jersey</artifactId>
<version>0.8</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>${maven-shade-plugin.version}</version>
<configuration> <createDependencyReducedPom>false</createDependencyReducedPom>
</configuration>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
my-app is your parent module and rest are child so provide a dependencies order in parent project pom so that when you build the project ,maven will provide the dependencies as you provided in parent module.
<modules>
<module>core-module</module>
</modules>
Provide the proper ordering like parent and child modules to understand the maven for building.
my-app
<modules>
<module>core-module</module>
<module>jar-module</module>
<module>web-module</module>
</modules>
core-module
no <modules>
This is a clean hierarchy, mirrored by the directory hierarchy.
There is a difference between modules and there container and the parent relation, and other subtleties. So maybe this helps.
Related
I have a maven project with two modules : core and webapp.
The webapp module is a war file to be deployed to wildfly. It has a dependency to the core module.
I can run mvn clean package in the parent directory of my modules. I am able to deploy de war file manually to wildfly and it works. Unfortunately if I run mvn wildfly:deploy in the webapp directory I get :
Failed to execute goal on project webapp: Could not resolve dependencies for project gbt:webapp:war:1.0-SNAPSHOT: Could not find artifact gbt:core:jar:1.0-SNAPSHOT
What shall I do to deploy the war file with the wildfly plugin ?
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>gbt</groupId>
<artifactId>unite_compte</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>pom</packaging>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<maven.compiler.source>11</maven.compiler.source>
<maven.compiler.target>11</maven.compiler.target>
<version.server.bom>25.0.1.Final</version.server.bom>
<version.microprofile.bom>25.0.1.Final</version.microprofile.bom>
<jakartaee.version>8.0.0</jakartaee.version>
<version.wildfly.maven.plugin>2.1.0.Final</version.wildfly.maven.plugin>
<failOnMissingWebXml>false</failOnMissingWebXml>
</properties>
<dependencyManagement>
<dependencies>
<!-- importing the jakartaee8-with-tools BOM adds specs and other useful artifacts as managed dependencies -->
<dependency>
<groupId>org.wildfly.bom</groupId>
<artifactId>wildfly-jakartaee8-with-tools</artifactId>
<version>${version.server.bom}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<dependency>
<groupId>jakarta.platform</groupId>
<artifactId>jakarta.jakartaee-api</artifactId>
<version>${jakartaee.version}</version>
<scope>provided</scope>
</dependency>
</dependencies>
<build>
<finalName>${project.artifactId}</finalName>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.wildfly.plugins</groupId>
<artifactId>wildfly-maven-plugin</artifactId>
<version>${version.wildfly.maven.plugin}</version>
</plugin>
</plugins>
</pluginManagement>
</build>
<modules>
<module>core</module>
<module>webapp</module>
</modules>
</project>
webapp 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>gbt</groupId>
<artifactId>unite_compte</artifactId>
<version>1.0-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>
<groupId>gbt</groupId>
<artifactId>webapp</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>war</packaging>
<dependencies>
<dependency>
<groupId>gbt</groupId>
<artifactId>core</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
</dependencies>
<build>
<!--finalName>${project.artifactId}</finalName-->
<finalName>unite_compte</finalName>
<plugins>
<plugin>
<groupId>org.wildfly.plugins</groupId>
<artifactId>wildfly-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
core 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>gbt</groupId>
<artifactId>unite_compte</artifactId>
<version>1.0-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>
<groupId>gbt</groupId>
<artifactId>core</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>
<dependencies>
</dependencies>
<build>
<finalName>${project.artifactId}</finalName>
</build>
</project>
You need to run mvn install, or the artifact for the core module is built but never installed into the local repository and cannot be resolved when building the webapp module.
I have one. Parent-module and two Child. One of the child is a plugin I wrote for sending mail to email(mail parameters, themes, text are set in pom.xml), which should be sent during the compilation phase of the parent-module. The second child is just a class with "Hello World".
My question. How do I do in the parent module: install maven plugin before the compilation phase?
p.s. I can not correctly form a question, because a huge request to clarify the nuances in the comments or add the missing information.
upd:
this is child-plugin
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://maven.apache.org/POM/4.0.0"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>maven-parent</artifactId>
<groupId>com.live.hello</groupId>
<version>1.0.0</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<packaging>maven-plugin</packaging>
<artifactId>child-plugin</artifactId>
<dependencies>
<dependency>
<groupId>com.sun.mail</groupId>
<artifactId>javax.mail</artifactId>
<version>1.6.2</version>
</dependency>
<dependency>
<groupId>org.apache.maven.plugin-tools</groupId>
<artifactId>maven-plugin-annotations</artifactId>
<version>3.6.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-plugin-api</artifactId>
<version>3.6.3</version>
</dependency>
</dependencies>
</project>
this is child-app
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://maven.apache.org/POM/4.0.0"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>maven-parent</artifactId>
<groupId>com.live.hello</groupId>
<version>1.0.0</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<packaging>jar</packaging>
<artifactId>child-app</artifactId>
</project>
and parent
<?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.live.hello</groupId>
<artifactId>maven-parent</artifactId>
<version>1.0.0</version>
<modules>
<module>child-plugin</module>
<module>child-app</module>
</modules>
<packaging>pom</packaging>
<properties>
<maven.compiler.target>1.8</maven.compiler.target>
<maven.compiler.source>1.8</maven.compiler.source>
</properties>
<build>
<plugins>
<plugin>
<groupId>com.live.hello</groupId>
<artifactId>test1-send</artifactId>
<version>1.0.0</version>
<executions>
<execution>
<id>my-exe-plugin</id>
<phase>compile</phase>
<goals>
<goal>sendEmail</goal>
</goals>
<configuration>
<loginSeander>my.test#gmail.com</loginSeander>
<passwordSender>11111111</passwordSender>
<mailRecipient>mymail#gmail.com</mailRecipient>
<subject>My first messege</subject>
<text>Hello!</text>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
I have a project structure which has a core tool and a REST API to interact and configure that tool.
I have a package structure like this:
com.example.api -> contains API definitions
com.example.commons -> contains module common to both core and api
com.exmaple.core -> contains the core module
This is primarily a Spring Boot application and both will run in different containers. So the API and the Core jar will be different.
How do I create a multi-module project with this structure so that I can also use the commons module in both the sub packages(core & api).
Suggestions on how to configure Maven and IntelliJ in such an environment?
Is my pattern right? Are there other well known patterns for this kind of project structure?
You can have a multi Maven module project as you wish. Here's an example on how you should configure your modules:
Create a parent pom.xml as follows (note that I am not adding spring-boot-starter-parent as a parent to the project, I am bringing in the Spring Boot dependencies with spring-boot-dependencies):
<?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.example</groupId>
<artifactId>parent</artifactId>
<packaging>pom</packaging>
<version>1.0.0-SNAPSHOT</version>
<modules>
<module>example-commons</module>
<module>example-core</module>
<module>example-api</module>
</modules>
<dependencyManagement>
<dependencies>
<!-- https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-dependencies -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-dependencies</artifactId>
<version>1.5.3.RELEASE</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<!-- https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter-web -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<version>1.5.3.RELEASE</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter-test -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<version>1.5.3.RELEASE</version>
</dependency>
</dependencies>
</project>
And a non executable module's pom.xml would be 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/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>parent</artifactId>
<groupId>com.example</groupId>
<version>1.0.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>example-commons</artifactId>
</project>
whereas an executable module's pom.xml would be like (note the spring-boot-maven-plugin is present only here for this dependency):
<?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">
<parent>
<artifactId>parent</artifactId>
<groupId>com.example</groupId>
<version>1.0.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>example-core</artifactId>
<build>
<plugins>
<!-- https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-maven-plugin -->
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<version>1.5.3.RELEASE</version>
<configuration>
<executable>true</executable>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>com.example</groupId>
<artifactId>example-commons</artifactId>
<version>1.0.0-SNAPSHOT</version>
</dependency>
</dependencies>
</project>
This application was built 15 years ago, I guess. The client has sought an upgrade/modification of this app, which I am not aware of.
I have built some POM.xml scripts. When I tried to upload it in development server, it was expecting a .WAR file inside the .EAR that I had uploaded.
Here is my pom.xml script. Please suggest some modifications.
<groupId>itaras</groupId>
<artifactId>itaras</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>ear</packaging>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>1.0</version>
<type>war</type>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.2</version>
</plugin>
<plugin>
<artifactId>maven-ear-plugin</artifactId>
<version>2.3.2</version>
<configuration>
<finalName>MyEarFile</finalName>
<version>5</version>
<generatedDescriptorLocation>$D:/itaras/ITARAS_Branch_3Aug2017/itaras/WebContent</generatedDescriptorLocation>
<modules>
<webModule>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<uri>appITARAS.war</uri>
<bundleFileName>appITARAS.war</bundleFileName>
<contextRoot>/ITARAS</contextRoot>
</webModule>
</modules>
</configuration>
</plugin>
</plugins>
</build>
You need a parent pom like this :
<?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>itaras</groupId>
<artifactId>itaras</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>pom</packaging>
<modules>
<module>itaras-ear</module>
<module>itaras-war</module>
</modules>
</project>
Then you will have a war project which is a child/module of the parent. This will be your existing project like:
<?xml version="1.0"?>
<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>
<parent>
<groupId>itaras</groupId>
<artifactId>itaras</artifactId>
<version>1.0-SNAPSHOT</version>
</parent>
<artifactId>itaras-war</artifactId>
<packaging>war</packaging>
.....
Then you will have an ear project which will include the war project as a dependency, something like:
<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>
<parent>
<groupId>itaras</groupId>
<artifactId>itaras</artifactId>
<version>1.0-SNAPSHOT</version>
</parent>
<artifactId>itaras-ear</artifactId>
<packaging>ear</packaging>
<dependencies>
<dependency>
<groupId>itaras</groupId>
<artifactId>itaras-war</artifactId>
<version>${project.version}</version>
</dependency>
</dependencies>
I have a maven project with 4 subprojects, let's say the following structure:
Main
|- core (jar)
|- webapp1 (war)
|- webapp2 (war)
|- webapp3 (war)
The three webapp subprojects depends on core subproproject. So the poms are like:
Main (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>myGroup</groupId>
<artifactId>MyArtifact</artifactId>
<version>1.0</version>
<packaging>pom</packaging>
<properties>
</properties>
<repositories>
</repositories>
<modules>
<module>core</module>
<module>webapp1</module>
<module>webapp2</module>
<module>webapp3</module>
</modules>
...
</project>
Core (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>
<artifactId>core</artifactId>
<packaging>jar</packaging>
<parent>
<groupId>MyGroup</groupId>
<artifactId>MyArtifact</artifactId>
<version>1.0</version>
</parent>
...
</project>
And web app poms are like this:
<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>webapp1</artifactId>
<version>1.1.0-A1</version>
<packaging>war</packaging>
<parent>
<groupId>MyGroup</groupId>
<artifactId>MyArtifact</artifactId>
<version>1.0</version>
</parent>
<dependencies>
<dependency>
<groupId>MyGroup</groupId>
<artifactId>core</artifactId>
<version>1.0</version>
</dependency>
</dependencies>
...
</project>
Everything worked fine during months when i execute 'mvn package' on the project's root folder and deploy the wars being generated.
But now i want to deploy an Ear instead of separate War files so i added a subproject called earproject. With the following 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>
<artifactId>earproject</artifactId>
<packaging>ear</packaging>
<parent>
<groupId>MyGroup</groupId>
<artifactId>MyArtifact</artifactId>
<version>1.0</version>
</parent>
<build>
<pluginManagement>
<plugins>
<plugin>
<artifactId>maven-ear-plugin</artifactId>
<version>2.10.1</version>
<configuration>
<finalName>EarName</finalName>
<version>5</version>
<generatedDescriptorLocation>${basedir}/src/main/applicatio/META-INF</generatedDescriptorLocation>
<modules>
<webModule>
<groupId>MyGroup</groupId>
<artifactId>webapp1</artifactId>
<bundleFileName>webapp1.war</bundleFileName>
<contextRoot>/webapp1</contextRoot>
</webModule>
<webModule>
<groupId>MyGroup</groupId>
<artifactId>webapp2</artifactId>
<bundleFileName>webapp2.war</bundleFileName>
<contextRoot>/webapp2</contextRoot>
</webModule>
<webModule>
<groupId>MyGroup</groupId>
<artifactId>webapp3</artifactId>
<bundleFileName>webapp3.war</bundleFileName>
<contextRoot>/webapp3</contextRoot>
</webModule>
</modules>
</configuration>
</plugin>
</plugins>
</pluginManagement>
</build>
<dependencies>
<dependency>
<groupId>MyGroup</groupId>
<artifactId>core</artifactId>
<version>1.0</version>
</dependency>
<dependency>
<groupId>MyGroup</groupId>
<artifactId>webapp1</artifactId>
<type>war</type>
<version>1.0</version>
</dependency>
<dependency>
<groupId>MyGroup</groupId>
<artifactId>webapp2</artifactId>
<type>war</type>
<version>1.0</version>
</dependency>
<dependency>
<groupId>MyGroup</groupId>
<artifactId>webapp3</artifactId>
<type>war</type>
<version>1.0</version>
</dependency>
</dependencies>
</project>
Whith this configuration when i run 'mvn clean' and 'mvn package' the ear file is generated but the war files inside the ear file contains an invalid old version of the core.jar.
If i check target directories on webapp projects the War files has a right core.jar version. It seems like EAR packaging uses an old version of the jar that is in my mvn repository, but i don't know why, because on the separate war files maven puts the recently created core.jar.
Why is this happening? Do i need to specify anything more on earproject's pom.xml?
I think the problem you are describing can be solved easily. In appearance Maven ear plugin is getting the core jar file from the repository instead of the new compiled one. I don't know the reason of this plugin's behaviour but I found this issue long time ago.
You should install your jar libraries in the local repository by using the following command
mvn clean install
instead of
mvn package
which only generates the artifacts