Build a module - maven - java

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

Related

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

Maven Ant run something at the end of the build

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>

The parent project must have a packaging type of POM

I am trying to create a new maven module. Parent project is a Web Service and has pom.xml.
How can I fix this error and create a new module?
Update your parent project's pom.xml by replacing packaging property from jar/war to pom as following...
<?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>project-group</groupId>
<artifactId>webservice</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>pom</packaging>
<name>project-name</name>
<url>http://maven.apache.org</url>
</project>
Open POM.xml in eclipse Id->Overview->ArtifactId->Packaging(Select POM from dropdown)->Save then create new Maven module.

Is there a way to build all my Maven projects with just one command ?

I am really new with Maven, and I have set up 2 maven projects, one of them is my utility API, the second is Jersey API. I installed utility API as part of my local Maven repository and added it in the pom.xml file.
Everything is working fine, it's just that when I want to build/run tests I need to go to each directory where projects are and run the commands. Is there a way to run one command or reconfigure the project in a way, so that I am able to process everything just from my REST API directory?
Eg. mvn clean test ... something ... -> goes and tests both of my projects.
Once again, I am new to Maven, but also I did a research and could not find a proper useful information that could help me out. If this is one of those questions that needs to be close, could you please at least provide me with some more information before closing it ? Thank you.
You can use multimodule maven projects. You define a structure like this
/
pom.xml (A)
util-api
pom.xml (B)
jersey.api
pom.xml (C)
In the children pom's you specify a <parent> node.
(A) 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>
<groupId>mygroup.id</groupId>
<artifactId>myparentartifact</artifactId>
<packaging>pom</packaging>
<version>0.0.1-SNAPSHOT</version>
...
<modules>
<module>util-api</module>
<module>jersey-api</module>
</modules>
</pom>
(B) 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>
<artifactId>myparentartifact</artifactId>
<groupId>mygroup.id</groupId>
<version>0.0.1-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>
<artifactId>util-api</artifactId>
<packaging>jar</packaging>
</pom>
(C) 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>
<artifactId>myparentartifact</artifactId>
<groupId>mygroup.id</groupId>
<version>0.0.1-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>
<artifactId>jersey-api</artifactId>
<packaging>jar</packaging>
</pom>
With this configuration you can build all modules with one command: mvn clean install
You can use Maven's aggregation pom.
Are you looking for a command , which can run your test and also build you app with all the module included ?
I thin you are looking for mvn clean install.
Please make sure, you say this in the highest maven pom.xml, which all include all the dependencies.
There is an option to combine related projects into one by having a top level POM using modules feature.
<modules>
<module>utility-api</module>
<module>Jersey-api</module>
</modules>
and can compile and run the test cases with
mvn clean install
You need to create parent POM for your 2 modules with
<packaging>pom</packaging>
so when you run for example mvn install on your parent POM it will run it on it's every child module.
More info on working with multiple modules here

Categories

Resources