I have this classical project tree:
project
pom.xml
This pom.xml generates a full maven project with its own pom.xml like this:
project
pom.xml
generated-module
pom.xml
src
...
Is it possible to generate and buid this generated module with this simple command ?
mvn package
You need to add a modules decleration in your parent-pom.xml
<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>myproject</groupId>
<artifactId>PARENT</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>pom</packaging>
<modules>
<module>generated-module</module>
<module>...</module>
</modules>
</project>
https://maven.apache.org/plugins/maven-eclipse-plugin/reactor.html
Related
I am trying to import a maven project into eclipse as a subproject of a non-maven project.
The structure am seeking should look like the image below
I have tried to import the parent project and then create spring starter project and select the path to be inside the parent but I ended up with an independent project in the workspace that is duplicated in parent.
Thank in advance.
I don't think you can do that. What you can do is a modular maven project. Declare your spring-cloud as parent and guest-services as a module:
spring-cloud pom like:
<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>x.y.z</modelVersion>
<groupId>org.yourCompany.spring-cloud</groupId>
<artifactId>spring-cloud-parent</artifactId>
<version>1.0-SNAPSHOT</version>
<properties/>...
<dependencies/>...
<build/>...
<modules>
<module>guest-services</module>
</modules>
</project>
guest-services pom like:
<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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>x.y.z</modelVersion>
<groupId>org.yourCompany.guest</groupId>
<artifactId>guest-services</artifactId>
<name>guest-services</name>
<description>Description for this module</description>
<parent>
<groupId>org.yourCompany.spring-cloud</groupId>
<artifactId>spring-cloud-parent</artifactId>
<version>1.0-SNAPSHOT</version>
<relativePath>..</relativePath>
</parent>
<properties/>...
<dependencies/>...
<build/>...
</project>
I am trying to learn how maven multi-project builds work. I have a very simple setup right now, a top level POM that defines 1 subproject, the web application, and a web project that has a pretty basic pom file. From the parent level directory, when i try to run 'mvn clean install' i get the following error:
Child module /home/jeb/Desktop/payroll/payroll-web> of /home/jeb/Desktop/payroll/pom.xml does not exist
Here is the 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>payroll</groupId>
<artifactId>payroll-top</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>pom</packaging>
<modules>
<module>payroll-web></module>
</modules>
</project>
And here is the subproject (web app) 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>
<name>payroll-web</name>
<parent>
<groupId>payroll</groupId>
<artifactId>payroll-top</artifactId>
<version>0.0.1-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>
<groupId>payroll</groupId>
<artifactId>payroll-web</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>war</packaging>
<dependencies>
</dependencies>
<build>
<finalName>payrollwebapp</finalName>
</build>
</project>
I'm not sure what I am missing to get the project to build, any help is appreciated.
You have a trailing ">" at the end of the module name.
<module>payroll-web></module>
`<parent>
<groupId>payroll</groupId>
<artifactId>payroll-top</artifactId>
<version>*0.0.1-SNAPSHOT*</version>
<relativePath>../pom.xml</relativePath>
</parent>`
Correct the parent version to 1.0
I have a Maven parent project that has 6 modules, each module generates a specific artifact that is copied somewhere, when all the modules are built I want to be able to run an ant task that commits and pushes these artifacts into its GIT repository. Any idea how this could be achieved inside Maven? Currently I run Maven from Ant and then I run the GIT Commit/Push task.
Thanks!
Johann
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<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>Group</groupId>
<artifactId>Parent</artifactId>
<version>1.0.0-SNAPSHOT</version>
<packaging>pom</packaging>
<modules>
<module>ModuleUtil</module>
<module>ModuleDomain</module>
<module>ModuleData</module>
<module>ModuleUi</module>
<module>ModuleAsync</module>
<module>ModuleBatch</module>
<!-- At this stage I would like to run something -->
</modules>
</project>
I had a multi module application called ParentApp(Which is a parent project) and it has JARMOdule, WARModule, EARModule. EAR Module has dependedncies of JARModule and WARMOdule
ParentPOM
<?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>ParentApp</groupId>
<artifactId>ParentApp</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>pom</packaging>
<modules>
<module>JARModule</module>
<module>WARModule</module>
<module>EARModule</module>
</modules>
</project>
EARModule 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>ParentApp</groupId>
<artifactId>ParentApp</artifactId>
<version>0.0.1-SNAPSHOT</version>
</parent>
<artifactId>EARModule</artifactId>
<packaging>ear</packaging>
<dependencies>
<dependency>
<groupId>ParentAPP</groupId>
<artifactId>WARModule</artifactId>
<version>0.0.1-SNAPSHOT</version>
<type>war</type>
</dependency>
<dependency>
<groupId>ParentAPP</groupId>
<artifactId>JARModule</artifactId>
<version>0.0.1-SNAPSHOT</version>
</dependency>
</dependencies>
</project>
And respective JAR and WAR Poms which doesn't have any dependecies, WARModule is a WebApp, I had a class in WARModule when i build the ParentApp with mvn clean install
under target folder under classes i still have
I'm basically trying to have a rest service in WARModule but unable to make it work, any help is appreciated. Thanks!!
You need to follow the Maven standard folder structure.
You should put all your java code inside src/main/java folder.
Looking at the image you uploaded, it looks like the SampleApp.java is not present in the correct directory as expected by maven.
In my spring project 'Calorie counter', I have the following file structure:
Calorie counter code/
CalorieCounterWar/
src/
target/
pom.xml
...
CalorieCounter/
src/
target/
pom.xml/
...
Everytime I have to do mvn clean install both in CaloriecCounter and CalorieCounterWar to build the project. Without writing a script to do it together, is there a way to modifiy/add pom.xml to do both buids by single mvn clean install?
Make a parent project which has both projects as modules.
Example from http://books.sonatype.com/mvnex-book/reference/multimodule-sect-simple-parent.html:
<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>simple-parent</artifactId>
<packaging>pom</packaging>
<version>1.0</version>
<name>Multi Chapter Simple Parent Project</name>
<modules>
<module>simple-weather</module>
<module>simple-webapp</module>
</modules>
....