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>
Related
I am currently learning JFoenix library. There is a nice demo and instructions how to run it.
JFoenix uses Gradle, but I need to use Maven, so I've decided to recreate the demo project using Maven for further testing.
The problem appeared when I tried to run my newly created project. It turned out that some classes (e.g. de.jensd.fx.glyphs.GlyphIcon) were not found. I found out that de.jensd:fontawesomefx-fontawesome:4.7.0-5 depends on de.jensd:fontawesomefx-commons:8.15 in runtime. So I decided to add it as compile dependency and the demo ran correctly. But build.gradle of the demo specifies only de.jensd:fontawesomefx-fontawesome:4.7.0-5.
Do Maven and Gradle handle dependencies in a different way? Or is it a specific case?
Here is my 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/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>jfoenix</groupId>
<artifactId>demo</artifactId>
<version>1.0-SNAPSHOT</version>
<!-- Bintray is needed for de.jensd:fontawesomefx-fontawesome. -->
<repositories>
<repository>
<id>central</id>
<name>bintray</name>
<url>https://jcenter.bintray.com</url>
</repository>
</repositories>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.0</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>com.jfoenix</groupId>
<artifactId>jfoenix</artifactId>
<version>8.0.7</version>
</dependency>
<dependency>
<groupId>io.datafx</groupId>
<artifactId>datafx</artifactId>
<version>8.0.1</version>
</dependency>
<dependency>
<groupId>io.datafx</groupId>
<artifactId>flow</artifactId>
<version>8.0.1</version>
</dependency>
<dependency>
<groupId>de.jensd</groupId>
<artifactId>fontawesomefx-fontawesome</artifactId>
<version>4.7.0-5</version>
</dependency>
<!-- Without this dependency the project can't be compiled. -->
<dependency>
<groupId>de.jensd</groupId>
<artifactId>fontawesomefx-commons</artifactId>
<version>8.15</version>
</dependency>
</dependencies>
</project>
P.S. I am not sure whether the title for this question is OK. So suggestions are welcome.
P.P.S. If you try to compile the demo using my pom.xml you'll have to comment out demos.components.AnimationTemplateDemo.java because com.jfoenix.transitions.template package is new and is not available in com.jfoenix:jfoenix:8.0.7.
The pom.xml file at jcenter is this one:
<?xml version="1.0" encoding="UTF-8"?>
<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>
<groupId>de.jensd</groupId>
<artifactId>fontawesomefx-fontawesome</artifactId>
<version>4.7.0-5</version>
<dependencies>
<dependency>
<groupId>de.jensd</groupId>
<artifactId>fontawesomefx-commons</artifactId>
<version>8.15</version>
<scope>runtime</scope>
</dependency>
</dependencies>
</project>
As you can see, fontawesomefx-commons is only required at runtime. I’m not sure why this is, but it explains why it is not pulled at compile time.
I don’t now where gradle pulls its dependency from, you don’t mention it, but my guess is that the configuration there is not runtime, but compile.
Edit : the scope is compile at later versions of fontawesomefx-fontawesome. So it appears that the runtime scope specified in the 4.7.0-5 version is probably a bug…
pom.xml for version 4.7.0-9:
<?xml version="1.0" encoding="UTF-8"?>
<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>
<groupId>de.jensd</groupId>
<artifactId>fontawesomefx-fontawesome</artifactId>
<version>4.7.0-9</version>
<dependencies>
<dependency>
<groupId>de.jensd</groupId>
<artifactId>fontawesomefx-commons</artifactId>
<version>9.0.0</version>
<scope>compile</scope>
</dependency>
</dependencies>
</project>
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'm very new to maven, so kindly bear with me.
i have a maven project with almost 100 dependencies all of which are present in my local system. So I'm adding them to my classpath via pom.xml with <scope> being system and <systemPath> giving path to the said dependencies. A rough structure of my pom.xml looks 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>
<groupId>com</groupId>
<artifactId>MAVEN_APP</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>MAVEN_APP</name>
<properties>
<jdk.version>1.8</jdk.version>
</properties>
<dependencies>
<dependency>
<groupId>jar1</groupId>
<artifactId>dependency1</artifactId>
<version>0.9.5</version>
<scope>system</scope>
<systemPath>path/to/directory/outside/project/directory/jar1Name.jar</systemPath>
</dependency>
......
<dependency>
<groupId>jar100</groupId>
<artifactId>dependency10</artifactId>
<version>1.9.7</version>
<scope>system</scope>
<systemPath>path/to/directory/outside/project/directory/jar10Name.jar</systemPath>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
This includes all the jars into my classpath and everything is running fine.
But i would like to keep the path/to/directory/outside/project/directory/ inside my app.propeties file and pom.xml should fetch this path from the properties file.
Is there a way in maven to do this.
Could somebody help me here. Thanks in advance.
I created POM.xml file which worked perfectly until I deleted a 3rd party jar,that is dependent in my project. The problem is that the jar is missing, but it is created using the maven-antrun-plugin.
Here is the source of the plugin that creates the jar:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<version>1.8</version>
<executions>
<execution>
<phase>generate-sources</phase>
<configuration>
<tasks>
<property environment="env" />
<property name="appname" value="hellojavaworld" />
<echoproperties />
<exec dir="" executable="respawn.exe" searchpath="true">
<arg value="${basedir}\src\aion\${appname}.app" />
</exec>
</tasks>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
</plugin>
Further in the POM.xml file is this:
<dependency>
<groupId>hellojavaworld</groupId>
<artifactId>hellojavaworld</artifactId>
<scope>system</scope>
<systemPath>${basedir}\src\aion\hellojavaworld.bin\hellojavaworld.jar</systemPath>
<version>1.0</version>
<optional>true</optional>
</dependency>
Everything works fine if the hellojavaworld.jar is compiled manually,but in case the jar does not exist, there is the error missing artifact.
Question is how to write POM.xml that creates jar that is used as dependency in one POM.xml file without manual intervetions?
Thanks
One solution is to use a multi-module build. The SonaType book has a chapter devoted to the subject.
Basically you would need three POM files.
The parent:
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.sonatype.mavenbook.multi</groupId>
<artifactId>parentHoldsItTogether</artifactId>
<packaging>pom</packaging>
<version>1.0</version>
<name>Multi Chapter Simple Parent Project</name>
<modules>
<module>hellojavaworld</module>
<module>thingThatNeedsHellojavaworld</module>
</modules>
</project>
A POM for hellojavaworld:
<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>org.sonatype.mavenbook.multi</groupId>
<artifactId>parentHoldsItTogether</artifactId>
<version>1.0</version>
</parent>
<artifactId>hellojavaworld</artifactId>
<packaging>jar</packaging>
</project>
A POM for the consumer of the library:
<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>org.sonatype.mavenbook.multi</groupId>
<artifactId>parentHoldsItTogether</artifactId>
<version>1.0</version>
</parent>
<artifactId>thingThatNeedsHellojavaworld</artifactId>
<packaging>???</packaging>
<dependencies>
<dependency>
<groupId>org.sonatype.mavenbook.multi</groupId>
<artifactId>hellojavaworld</artifactId>
<version>1.0</version>
</dependency>
</dependencies>
</project>
You would organize the directory structure like this:
your_project_folder/
pom.xml <-- the parent POM
hellojavaworld/
pom.xml
src/main/java
thingThatNeedsHellojavaworld/
pom.xml
src/main/java
Create a multi module maven project: See chapter 6 of Maven by example.
The first module would be you hellojavaworld and the second the application which has a dependency on hellojavaworld.
pom.xml:
<project>
...
<modules>
<module>hellojavaworld</module>
<module>application</module>
</modules>
...
application/pom.xml
...
<dependencies>
<dependency>
<groupId>hellojavaworld</groupId>
<artifactId>hellojavaworld</artifactId>
<version>${project.version}</version>
</dependency>
</dependencies>
...
Could anybody suggest me an solution with the following exception. I am going to create a multi-module project.
Parent Project name is LOGICBACKEND
child project name is DBAccess
I need to have ear file of LOGICBACKEND which should contain DBAccess prjoects jar file.
I am getting following exception when i run mav clean install -P Developer.
[ERROR]The project com.project1.Database:DBAccess:1.0-SNAPSHOT (C:\Project1\DBAccess\pom.xml) has 1 error
[ERROR]Invalid packaging for parent POM com.project1.logic:LOGIC:1.0-SNAPSHOT (C:\Project1\pom.xml), must be "pom" but is "ear" # com.project1.logic:LOGIC:1.0-SNAPSHOT, C:\Project1\pom.xml, line 6, column 13
This is how part of my parent pom.xml looks
<modelVersion>4.0.0</modelVersion>
<groupId>com.project1.logic</groupId>
<artifactId>LOGICBACKEND</artifactId>
<packaging>ear</packaging>
<version>1.0-SNAPSHOT</version>
This is how child pom.xml looks
<groupId>com.project1.logic</groupId>
<artifactId>DBAccess</artifactId>
<packaging>ejb</packaging>
<name>DBAccess</name>
<version>1.0-SNAPSHOT</version>
<parent>
<groupId>com.project1.logic</groupId>
<artifactId>DBAccess</artifactId>
<version>1.0-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>
Could anybody help me here to understand what is going wrong here.
Thanks in advance for any help
This simple setup is a good start.
.
├── pom.xml
├── services
| ├── pom.xml
| └── src
| └── main
| └── java
| └── com
| └── stackoverflow
| └── MyEjbService.java
└── application
└── pom.xml
pom.xml
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.stackoverflow.Q13330930</groupId>
<artifactId>parent</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>pom</packaging>
<name>${project.artifactId}-${project.version}</name>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<modules>
<module>services</module>
<module>application</module>
</modules>
<dependencies>
</dependencies>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>com.stackoverflow.Q13330930</groupId>
<artifactId>services</artifactId>
<version>${project.version}</version>
<type>ejb</type>
</dependency>
</dependencies>
</dependencyManagement>
<build>
<plugins>
<plugin>
<artifactId>maven-ejb-plugin</artifactId>
<version>2.3</version>
<configuration>
<ejbVersion>3.1</ejbVersion>
</configuration>
</plugin>
</plugins>
</build>
</project>
services/pom.xml
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.stackoverflow.Q13330930</groupId>
<artifactId>parent</artifactId>
<version>1.0-SNAPSHOT</version>
</parent>
<groupId>com.stackoverflow.Q13330930</groupId>
<artifactId>services</artifactId>
<packaging>ejb</packaging>
<name>${project.artifactId}-${project.version}</name>
</project>
application/pom.xml
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.stackoverflow.Q13330930</groupId>
<artifactId>parent</artifactId>
<version>1.0-SNAPSHOT</version>
</parent>
<groupId>com.stackoverflow.Q13330930</groupId>
<artifactId>application</artifactId>
<packaging>ear</packaging>
<name>${project.artifactId}-${project.version}</name>
<dependencies>
<dependency>
<groupId>com.stackoverflow.Q13330930</groupId>
<artifactId>services</artifactId>
<type>ejb</type>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<artifactId>maven-ear-plugin</artifactId>
<version>2.7</version>
<configuration>
<defaultLibBundleDir>lib</defaultLibBundleDir>
</configuration>
</plugin>
</plugins>
</build>
</project>
You are trying to give the parent pom two functions - that is serving as a parent pom (packaging pom) and being the wrapper ear (packaging ear) - at the same time. To solve your issue you should create another maven module under your parent pom that has packaging ear and uses the maven-ear-plugin to define the output.
I got the similar error:
[ERROR]
[ERROR] Invalid packaging for parent POM sandbox:parent:6.5-SNAPSHOT, must be "pom" but is "jar" # sandbox:parent:6.5-SNAPSHOT
I figured out that the root cause was in parent version defined through properties:
<version>${revision}${changelist}</version>
As soon as I set version without referencing the properties the issue gone:
<version>6.5-SNAPSHOT</version>
Might be a maven bug.