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 {
}
Related
I've been trying to setup a spring websocket server using the stat.spring.io generator which generates a pom file etc.
It seems that the generated pomfile is unparsable for some reason and i've spent hours trying to fix it.
I've tried using Java 1.7 with spring 2.. to no avail.
Please can someone help explain why it might not be parsing:
Here is my full pomfile:
<?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>ws-analytics-gateway</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>ws-analytics-gateway</name>
<description>Demo project for Spring Boot</description>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.0.3.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>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-websocket</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>
The pom.xml you have posted is not valid XML. it is missing a closing tag for project as mentioned above. Also, you mention using java 1.7 with spring 2.
https://github.com/spring-projects/spring-boot/wiki/Spring-Boot-2.0-Release-Notes#java-8-baseline-and-java-9-support states:
Spring Boot 2.0 requires Java 8 as a minimum version.
I checked your XMl by pasting it here: https://www.xmlvalidation.com/index.php?id=1&L=0 you may wish to have that check pass first.
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>
I am restructuring a projects and wonder why i need to specify the version of an artifact in a child when it should be known...
Just to give an overview before i get into the details.
I have the following:
A library called generalUtils.
It has a parent, bom and a few 'other' artifacts.
In it, each of the 'other' artifacts parent, is the parent artifact, whose parent is the bom artifact
A library called web.
It depends on the generalUtils library.
it has a parent, bom, and a few 'other' artifacts.
In it, each of the 'other' artifacts parent, is the parent artifact, whose parent is the bom artifact.
In the DependencyManagement.Dependencies section of the parent artifact, I import the generalUtils bom artifact
I don't have to specify the version of any of the generalUtils artifacts in project web. Everything is fine.
However...
I also have a library called monitor.
It depends on both the generalUtils and web libraries.
it has a parent, bom, and a few 'other' artifacts.
In it, each of the 'other' artifacts parent, is the parent artifact, whose parent is the bom artifact.
In the DependencyManagement.Dependencies section of the parent artifact, I import both the generalUtils and web bom artifacts.
I don't have to specify the version of any of the generalUtils artifacts in any of the project monitor artifacts. However, if i don't specify the version of any of the web project artifacts. i get an error message.
webApi is one of the artifacts in the web library project and i'm getting this error message:
[INFO] Scanning for projects...
[ERROR] The build could not read 2 projects -> [Help 1]
[ERROR]
[ERROR] The project com.retx.monitor:eventCollector:1.0.6.InSync (C:\TFSROOT\Monitor_1.0.6.In\EventCollector\pom.xml) has 1 error
[ERROR] 'dependencies.dependency.version' for com.retx.web:webAPI:jar is missing. # line 74, column 15
[ERROR]
[ERROR] The project com.retx.monitor:eventNotifier:1.0.6.In (C:\TFSROOT\Monitor_1.0.6.In\EventNotifier\pom.xml) has 1 error
[ERROR] 'dependencies.dependency.version' for com.retx.web:webAPI:jar is missing. # line 78, column 15
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
...
It's complaining that in two of the 'other' artifacts in the monitor project (eventCollector and eventNotifier) i have not specified a version for a web library artifact (webAPI)
Why is it complaining only about the web artifact and not about the generalUtils artifacts even though they are import exactly in the same way?
I'm using maven 2.0.11 for generalUtils and web libraries, but the monitor library is built using maven 3.0.3.
Now the actual pom files:
Project library generalUtils bom artifact's 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.retx.general.utils</groupId>
<artifactId>bom</artifactId>
<version>1.0.3-SNAPSHOT</version>
<packaging>pom</packaging>
<name>bom</name>
<description>Bill of Materials for general utils</description>
<properties>
<generalUtils.version>1.0.3-SNAPSHOT</generalUtils.version>
<!-- wildfly third-party dependencies versions -->
</properties>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>com.retx.general.utils</groupId>
<artifactId>configuration</artifactId>
<version>${generalUtils.version}</version>
</dependency>
<!-- a few others similar to the above -->
</dependencies>
</dependencyManagement>
</project>
Project library web bom artifact's 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.retx.web</groupId>
<artifactId>bom</artifactId>
<version>3.0.0-SNAPSHOT</version>
<packaging>pom</packaging>
<name>bom</name>
<description>Bill of Materials for Web</description>
<properties>
<webRoot.version>3.0.0-SNAPSHOT</webRoot.version>
<!-- bring in needed boms from other streams -->
<generalUtils.version>1.0.3-SNAPSHOT</generalUtils.version>
</properties>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>com.retx.web</groupId>
<artifactId>webApi</artifactId>
<version>${webRoot.version}</version>
</dependency>
<!-- a few others similar to the above -->
</dependencies>
</dependencyManagement>
</project>
Finally the monitor library artifacts, from parent down...
monitor library bom artifact 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.retx.monitor</groupId>
<artifactId>bom</artifactId>
<version>1.0.6.In</version>
<packaging>pom</packaging>
<name>bom</name>
<description>Bill of Materials for Monitor Modules</description>
<properties>
<!-- this stream -->
<monitor.version>1.0.6.In</monitor.version>
<!-- bring in needed boms from other streams -->
<webRoot.version>3.0.0-SNAPSHOT</webRoot.version> <!-- wildfly changed from 2.7.0.1-SNAPSHOT -->
<generalUtils.version>1.0.3-SNAPSHOT</generalUtils.version> <!-- wildfly changed from 1.0.2-SNAPSHOT -->
<!-- wildfly third-party dependencies versions -->
<!-- ... -->
</properties>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>com.retx.monitor</groupId>
<artifactId>eventCollector</artifactId>
<version>${monitorRoot.version}</version>
<type>ejb</type>
</dependency>
<dependency>
<groupId>com.retx.monitor</groupId>
<artifactId>eventNotifier</artifactId>
<version>${monitorRoot.version}</version>
<type>ejb</type>
</dependency>
</dependencies>
</dependencyManagement>
</project>
monitor library parent artifact pom.xml:
<?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>com.retx.monitor</groupId>
<artifactId>bom</artifactId>
<version>1.0.6.In</version>
<relativePath>bom/pom.xml</relativePath>
</parent>
<artifactId>monitor-root</artifactId>
<packaging>pom</packaging>
<name>monitor-root</name>
<description>Monitor Modules</description>
<dependencyManagement>
<dependencies>
<!-- import the generalUtils library bom -->
<dependency>
<groupId>com.retx.general.utils</groupId>
<artifactId>bom</artifactId>
<version>${generalUtils.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
<!-- import the web library pom -->
<dependency>
<groupId>com.retx.web</groupId>
<artifactId>bom</artifactId>
<version>${webRoot.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
<dependency>
<groupId>xalan</groupId>
<artifactId>xalan</artifactId>
<version>${xalan.version}</version>
</dependency>
<!-- other third part dependencies ->
</dependencies>
</dependencyManagement>
<!-- the rest is not relevant ->
</project>
pom.xml of the eventCollector artifact in the monitor library:
<?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>com.retx.monitor</groupId>
<artifactId>monitor-root</artifactId>
<version>1.0.6.In</version>
<relativePath>..</relativePath>
</parent>
<groupId>com.retx.monitor</groupId>
<artifactId>eventCollector</artifactId>
<packaging>ejb</packaging>
<name>EventCollector</name>
<dependencies>
<!-- dependency from the generalUtils library ->
<dependency>
<groupId>com.retx.general.utils</groupId>
<artifactId>utils</artifactId>
</dependency>
<!-- dependency from the web library ->
<dependency>
<groupId>com.retx.web</groupId>
<artifactId>webAPI</artifactId>
</dependency>
<!-- third party artifacts-->
<dependency>
<groupId>org.jboss.spec.javax.jms</groupId>
<artifactId>jboss-jms-api_2.0_spec</artifactId>
</dependency>
<!-- other third party artifacts-->
</dependencies>
<!-- the rest is not important -->
</project>
The relevant error message disappears if i just add the version to the webApi dependency in the above xml, like:
<!-- dependency from the web library ->
<dependency>
<groupId>com.retx.web</groupId>
<artifactId>webAPI</artifactId>
<version>${webRoot.version}</version>
</dependency>
Shouldn't maven be able to deduce the version of webAPI from the info in the parent artifact?
(Note that the generalUtils dependency does not need the version to be specified here... )
I think what you need is:
parent 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.greg</groupId>
<artifactId>ear-example</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>pom</packaging>
<name>ear-example</name>
<modules>
<module>module1</module>
<module>module2</module>
<module>module3</module>
</modules>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
</dependency>
</dependencies>
</dependencyManagement>
</project>
Then in each of the children/modules you have a dependency with no version, i.e. the version is inherited from the parent :
<?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>com.greg</groupId>
<artifactId>ear-example</artifactId>
<version>1.0-SNAPSHOT</version>
</parent>
<artifactId>module1</artifactId>
<packaging>war</packaging>
<name>example-war Maven Webapp</name>
<url>http://maven.apache.org</url>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<finalName>example-war</finalName>
</build>
</project>
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.
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>