I have a single Java Maven project having a pom.xml with jar packaging.
Now I want to add a sub-project in that project. So, I need to change the packaging pom from jar.
<groupId>org.test.app</groupId>
<artifactId>testPom</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>
Please provide any suggestion.
This would be the parent POM part with packaging and a couple of module references:
<groupId>org.test.app</groupId>
<artifactId>testPom</artifactId>
<packaging>pom</packaging>
<version>1.0-SNAPSHOT</version>
<modules>
<module>submodule</module>
<module>another-submodule</module>
</modules>
Hope it helps.
Related
My goal is to turn an existing maven project (char-counter) into a module of my multi-module maven project. How can I do this? I use Eclipse 4.16.0.
Here is the structure of my projects.
You can include the sub-modules inside your parent maven project in following way.
Inside your multi-module-project pom.xml
<modules>
<module>char-counter</module>
</modules>
See here: Maven Multiple module
Assuming that you want to convert your char-counter project to multi-module-project.
You need to have following in your multi-module-project pom.
<groupId>com.parent</groupId>
<artifactId>multi-module-project</artifactId>
<version>1.0.0-SNAPSHOT</version>
<packaging>pom</packaging>
<modules>
<module>Anagram<module>
<module>Calculator<module>
</modules
And then in Anagram project's pom :
<parent>
<groupId>com.parent</groupId>
<artifactId>multi-module-project</artifactId>
<version>1.0.0-SNAPSHOT</version>
</parent>
<groupId>com.child</groupId>
<artifactId>Anagram</artifactId>
<version>1.0.0-SNAPSHOT</version>
<packaging>jar</packaging>
And in Calculator project's pom:
<parent>
<groupId>com.parent</groupId>
<artifactId>multi-module-project</artifactId>
<version>1.0.0-SNAPSHOT</version>
</parent>
<groupId>com.child</groupId>
<artifactId>Calcultor</artifactId>
<version>1.0.0-SNAPSHOT</version>
<packaging>jar</packaging>
Also you need to add dependency of one module to other,in which you want to use the code from other module and then you need to deploy the artifact(module) which has dependency included in it and has starting point to run (like main).
I included a project as dependency in another project. On maven package the included dependency is not compiled as jar, but an empty folder is created.
projects:
main-test (packaging: jar)
main-webservice (packaging: war)
the main-webservice project includes the jar with pom.
main-test pom.xml:
<?xml version="1.0"?>
<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.main</groupId>
<artifactId>test</artifactId>
<packaging>jar</packaging>
</project>
main-webservice 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>de.main</groupId>
<artifactId>ws</artifactId>
<version>1.0</version>
<packaging>war</packaging>
<dependencies>
<dependency>
<groupId>de.main</groupId>
<artifactId>test</artifactId>
<version>1.0</version>
</dependency>
</dependencies>
<build><plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.4</version>
</plugin>
</plugins></build>
</project>
The dependencies of the test project are resolved inside webservice project, so the pom seems to be correct.
Anyhow, if I run "mvn package", the resources of main-webservices compile to target, but the libs folder contains another folder named main-test-1.0.jar. BUT it's a folder, not a packed jar.
What could be wrong here? How can I get the project to be packaged as jar, not as folder?
included dependency is not compiled as jar
Maven never compiles dependencies. It just takes them as they are and either puts them on the classpath or copies them into the WAR. But it never changes the artifact.
That also means the dependency must be in your local repo (somewhere below ~/.m2/repository/) or Maven will be unhappy (= fail with an error).
Note: Maven doesn't have a big memory. It can always only keep a single module in his tiny brain. In Eclipse, you can add another project as it is to the build path but Maven can't do that. For Maven to work properly, you must install all the dependencies in your local repo.
Idea:
Check if the jar exists in your repository
Check if the jar project in eclipse is not referenced in the war project in the Java Build Path
Do it without eclipse mvn plugin:
mvn eclipse:clean (for both projects)
mvn eclipse:eclipse (for both projects)
mvn clean install (for both projects)
I have project with several dependencies on other project.
<?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>group1</groupId>
<artifactId>artifact1<artifactId>
<name>RealtyRegistry</name>
<packaging>war</packaging>
<version>1.0.0-SNAPSHOT</version>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>group1</groupId>
<artifactId>artifact2</artifactId>
<version>1.0.0</version>
</dependency>
<dependency>
<groupId>group1</groupId>
<artifactId>artifact3</artifactId>
<version>1.0.0</version>
</dependency>
</dependencies>
All of them developed by me simultaniously. I add edition to files of all of project and i need to build main project together with dependent ones. How to do that for projects without tree structure?
There can be 2 or more covering trees for projects hierachy, for example: A depends on B,C; D depends on C,E; A and D are independent.
You can build multiple projects together using "Modules". Normally, you would do this by creating a "mother" project with <packaging>pom</packaging> and adding your real project as modules using the <modules> tag. Then, when you build the "mother" project, all modules are automatically built in the right order.
Here is an example from the Maven by Example book:
<groupId>org.sonatype.mavenbook.multi</groupId>
<artifactId>simple-parent</artifactId>
<version>1.0</version>
<packaging>pom</packaging>
<modules>
<module>simple-weather</module>
<module>simple-webapp</module>
</modules>
Note that this requires you to have your modules in subfolders that are named accordingly. For example, you would have the "mother" pom in some folder:
/.../my-project/
and the modules in:
/.../my-project/simple-weather/
/.../my-project/simple-webapp/
For more information, read Chapter 6. A Multi-module Project of the book, it's freely available on the Sonatype website.
I'm new to maven, and trying to understand how to release my project. I have the following project setup in svn:
trunk
|-deployer
| |-pom.xml
|-webapp
| |-pom.xml
|-utils
|-pom.xml
While developing webapp, I always want to develop against the latest snapshot version of utils, so I declare the dependency on utils in webapp/pom.xml via:
com.company
utils
1.0-SNAPSHOT
Webapp itself is also currently versioned at version 1.0-SNAPSHOT. It's pom.xml has the declaration:
<artifactId>webapp</artifactId>
<packaging>war</packaging>
<version>1.0-SNAPSHOT</version>
<name>Sample Webapp</name>
So everything is working great, but now I want to release my software. In deployer, I have the following in 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/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.company</groupId>
<artifactId>deployer</artifactId>
<packaging>pom</packaging>
<version>1.0-SNAPSHOT</version>
<name>Project Release</name>
<modules>
<module>externals/webapp</module>
</modules>
<properties>
<url.svn>http://<my-server>/<project>/trunk</url.svn>
</properties>
<scm>
<connection>scm:svn:${url.svn}</connection>
</scm>
<build>
<plugins>
<plugin>
<artifactId>maven-release-plugin</artifactId>
<version>2.3</version>
<configuration>
<tagBase>
http://<my-server>/<project>/tags
</tagBase>
</configuration>
</plugin>
</plugins>
</build>
<distributionManagement>
<repository>
<id>Releases</id>
<name>Releases</name>
<url>http://<nexus-server>/nexus/content/repositories/releases</url>
</repository>
<snapshotRepository>
<id>Snapshots</id>
<name>Snapshots</name>
<url>http://<nexus-server>/nexus/content/repositories/snapshots</url>
</snapshotRepository>
</distributionManagement>
</project>
Within the deployer folder itself I have a folder called "externals" which has an svn-externals set to check out my webapp project (I added this because maven complained about not being able to find it), so my modules path should be correct.
Questions
1.) I want to release a version of my web app, but when I run a mvn release:prepare and mvn release:perform in my deployer project, my only tangible output is my trunk tagged in svn and a pom uploaded to my nexus repository. This makes sense in that my deployer artifact packaging is type "pom", but it also doesn't get the job done of getting me a war of my webapp (I should note here that if a do a release in the webapp project by itself though, that I will get the war). I need to release multiple modules, and so I thought I could use maven aggregation from the deployer project to accomplish this, but it doesn't seem to be working.
2.) Is there a better way to achieve what I am trying to do?
Thank you for any insights you can provide.
You should run the maven-release-plugin against each module that you intend to release. I've never seen someone have a special "deployer" module that releases the other modules, this is not how things are commonly done.
Normally to release the webapp module you would run the commands against the webapp module, and to release the utils module you would run the commands against the utils module.
If you have a parent module that ties webapp and util together then I believe you can just run the release commands against that.
As matt b says, simply adding a maven-release-plugin entry at the top pom will probably do what you want. If you want to collect several artifacts into a proper release bundle, you want to create a module for this, but then you want to look at the maven assembly plugin. It can collect various jars (wether from modules or external dependencies) and resources into a directory, zip file or similar.
i have 3 maven project (starto.commons,starto.hibernate,starto.server) that use some same dependencies and two of then use the thread project(commons).
i try to unit the 3 project to one big maven project (lets call him starto.bigMavenProject for the example)
i mean that:
1) every project stay project on its own bat use the starto.bigMavenProject pom for dependencies
2)when i build (run mvn insatll) starto.bigMavenProject it's build the all three project (starto.commons,starto.hibernate,starto.server).
thanks in advance.
It sounds like you want a Maven parent project for your three projects. I'd suggest taking a look at the POM documentation on inheritance as well as Sonatype's simple example.
Basically, you want a POM for start.bigMavenProject something 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/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>starto</groupId>
<artifactId>bigMavenProject</artifactId>
<packaging>pom</packaging>
<version>1.0</version>
<modules>
<module>commons</module>
<module>hibernate</module>
<module>server</module>
</modules>
</project>
Though you may need to do some additional tweaking to, e.g., your directory structure, etc.
The key thing is your parent POM should have <packaging>pom</packaging> and define each sub-project as a module.