Default pom.xml for new Eclipse Maven projects - java

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.

Related

Why is IntelliJ giving me the name of the package and the name of another package in brackets?

(Side-note: the GameLogic module is not imported anywhere and can be ignored.)
As you can see in the picture under this, the java file of the 'ConsoleApp' labels '[DesktopApp]' next to it, but the DesktopApp module does not. The pom.xml of both the ConsoleApp and the DesktopApp module do not reference eachother, so how come IntelliJ labels the source folder this way?
The ConsoleApp/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">
<parent>
<artifactId>TicTacToe</artifactId>
<groupId>com.example</groupId>
<version>1.0.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>ConsoleApp</artifactId>
<properties>
<maven.compiler.source>16</maven.compiler.source>
<maven.compiler.target>16</maven.compiler.target>
</properties>
</project>
The DesktopApp/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">
<parent>
<artifactId>TicTacToe</artifactId>
<groupId>com.example</groupId>
<version>1.0.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>DesktopApp</artifactId>
<properties>
<maven.compiler.source>16</maven.compiler.source>
<maven.compiler.target>16</maven.compiler.target>
</properties>
</project>
The pom.xml (Parent 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>com.example</groupId>
<artifactId>TicTacToe</artifactId>
<packaging>pom</packaging>
<version>1.0.0-SNAPSHOT</version>
<modules>
<module>GameLogic</module>
<module>DesktopApp</module>
<module>ConsoleApp</module>
</modules>
<properties>
<maven.compiler.source>16</maven.compiler.source>
<maven.compiler.target>16</maven.compiler.target>
</properties>
</project>
Feel free to ask for more information!
This could be caused by the fact that you marked your Java folder as a module folder instead of a source folder. Go to the Project Structure Settings and remove the module named after the Java folder. Then go to the module console app and mark the Java folder as sources.

Importing a Maven project as a sub project in an existing project in eclipse

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>

Maven child module not found when building

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

Build a module - maven

I'm new to maven and I want to build this repository and then I want only to execute smpp-multiplexer module only on centos.
I know it's a newbie question but if someone can redirect me to the right path it will be appreciated.
Here's the 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>com.a1systems</groupId>
<artifactId>smpp-test-tools</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>pom</packaging>
<name>smpp-test-tools</name>
<modules>
<module>defcode_recognizer</module>
<module>smpp_cli_pusher</module>
<module>range_slicer</module>
<module>http-adapter</module>
<module>smpp-simulator</module>
<module>smpp-zabbix-checker</module>
<module>smpp-multiplexer</module>
<module>log-watcher</module>
</modules>
</project>
if there's a possibility to build only smpp-multiplexer it will be better.
Thank you.
go to the folder smpp-multiplexer and execute mvn install

Java Classes Not Found In WAR Module of a Multi Module Maven Application

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.

Categories

Resources