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
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>
When I create a starter project for spring-boot I get this error in the pom file. This is just to create a basic spring boot project
Project build error: Invalid packaging for parent POM [unknown-group-id]:[unknown-artifact-id]:[unknown-version], must be "pom" but is "jar"
<!-- This is the pom which from https://docs.spring.io/spring-boot/docs/current/reference/html/getting-started-first-application.html -->
<?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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.example</groupId>
<artifactId>myproject</artifactId>
<version>0.0.1-SNAPSHOT</version>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.1.5.RELEASE</version>
</parent>
</project>
Your parent project has <packaging>JAR</packaging> not POM. For creating Spring Boot projects with all needed dependencies you can use https://start.spring.io/.
I'm on Eclipse Neon.1 and when I create new Maven projects I get a default pom.xml with this content:
<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</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>test</name>
</project>
How can I modify this default template? I'd like to add some properties, for example
<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</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>test</name>
<properties>
<encoding>UTF-8</encoding>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>
</project>
Of course I can create my own archetype and use it to have this pom, but the m2e plugin is so configurable I hope this is possible without an archetype.
The question is, which archetype is actually used, when you skip the archetype selection. My first thought was, that it must be maven-archetype-quickstart. This would be the default when stepping into the archetype selection.
But the sad truth is, that no archetype is used at all and the POM is filled directly with the minimal set of values (groupId/artifactId/version). This is hard coded and cannot be changed or extended with your properties. Sorry.
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.
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