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.
Related
I am trying a simple spinoff of the MinimalWordCount example project for Apache Beam. I started a new project rather than downloading their archetpye. I'm running into an apparently common problem, that is not being solved by the common solution:
Exception in thread "main" java.lang.IllegalArgumentException: No Runner was specified and the DirectRunner was not found on the classpath.
Specify a runner by either:
Explicitly specifying a runner by providing the 'runner' property
Adding the DirectRunner to the classpath
Calling 'PipelineOptions.setRunner(PipelineRunner)' directly
The common solution here on SO is to add the correct dependencies, which I have done. Here is my very simple 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</groupId>
<artifactId>test_pipeline</artifactId>
<version>1.0-SNAPSHOT</version>
<properties>
<maven.compiler.source>8</maven.compiler.source>
<maven.compiler.target>8</maven.compiler.target>
</properties>
<dependencies>
<!-- https://mvnrepository.com/artifact/org.apache.beam/beam-runners-direct-java -->
<dependency>
<groupId>org.apache.beam</groupId>
<artifactId>beam-runners-direct-java</artifactId>
<version>2.33.0</version>
<scope>test</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/org.apache.beam/beam-sdks-java-core -->
<dependency>
<groupId>org.apache.beam</groupId>
<artifactId>beam-sdks-java-core</artifactId>
<version>2.33.0</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.apache.beam/beam-sdks-java-extensions-json-jackson -->
<dependency>
<groupId>org.apache.beam</groupId>
<artifactId>beam-sdks-java-extensions-json-jackson</artifactId>
<version>2.33.0</version>
</dependency>
</dependencies>
</project>
So how do I add the direct runner to my classpath (or solve this issue in any other way)?
Try removing the
<scope>test</scope>
from the beam-runners-direct-java dependency.
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 {
}
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 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>
I have created a web service and client project as well. Now I need the SEI created in web application to finish client application by taking the dependency of web application using maven. It didn't work. Can some one help me on this?
Client pom.xml
<modelVersion>4.0.0</modelVersion>
<groupId>com.dstyle.orderapp</groupId>
<artifactId>OrderProcessingApplicationClient</artifactId>
<packaging>jar</packaging>
<version>1.0-SNAPSHOT</version>
<name>OrderProcessingApplicationClient</name>
<url>http://maven.apache.org</url>
<dependencies>
<!-- using the web app as a dependency -->
<dependency>
<groupId>com.dstyle.orderapp</groupId>
<artifactId>OrderProcessingApplication</artifactId>
<version>1.0-SNAPSHOT</version>
<scope>compile</scope>
</dependency>
</dependencies>
Web service application pom.xml
<modelVersion>4.0.0</modelVersion>
<groupId>com.dstyle.orderapp</groupId>
<artifactId>OrderProcessingApplication</artifactId>
<packaging>war</packaging>
<version>1.0-SNAPSHOT</version>
<name>OrderProcessingApplication Maven Webapp</name>
<url>http://maven.apache.org</url>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<finalName>OrderProcessingApplication</finalName>
</build>
You can not declare a dependency on a project that is packaged as a Web Archive (war file).
So if your OrderProcessingApplication module is nothing but a set of APIs you would use into other projects/modules, it should be configured in a manner it is packaged as a Java Archive. This will send the built artifact (should be OrderProcessingApplication-1.0-SNAPSHOT.jar) to your local repository which will make it availble as a dependency for other projects.
So change your OrderProcessingApplication pom.xml file as follows:
<project>
<modelVersion>4.0.0</modelVersion>
<groupId>com.dstyle.orderapp</groupId>
<artifactId>OrderProcessingApplication</artifactId>
<packaging>jar</packaging>
<version>1.0-SNAPSHOT</version>
<name>OrderProcessingApplication Maven Webapp</name>
<url>http://maven.apache.org</url>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<finalName>OrderProcessingApplication</finalName>
</build>
</project>
Then issue an mvn clean install on that project and go back to your client project and check that the dependency is resolved.
You need to first run mvn install in OrderProcessingApplication to have it in your local maven repository, before mvn can find it as dependency of OrderProcessingApplicationClient.