I have an existing Java project with a single dependency. I just want to make a pom.xml so that someone can pull the project, mvn install
or mvn init
or whatever it is, then start working. How do I do this without using an IDE?
I'm looking for the equivalent of pip freeze
or npm init
, or just what I can copy and paste into a new pom.xml
file.
I tried Googling and only found stuff for starting new projects with Maven or using an Eclipse plugin.
Follow suggested three steps to convert your project into maven project.
Step 1: As suggested by nullpointer, following attributes are mandatory in your pom to make it as maven project.
Sample pom.xml file:
<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.infy</groupId>
<artifactId>user-identity-rest</artifactId>
<version>1.0.0</version>
</project>
groupId: It is unique identifier to the group of multiple modules in your project
artifactId: Unique module identifier of your module.
version: Initially we will start with version 1.0.0 and will upgrade to 1.0.1 and so on subsequently.
You can customized these things as per your understanding and future references.
Step 2: Now you need to add all libraries in declared pom.xml which is similar to jars you added in your project.
You might have added a library in your project(lets say json-simple-1.1.1.jar). Here maven doesn't look for the whole library, instead it asks its dependency.
You can find dependency of your external library here by searching for library with exact version.
<dependency>
<groupId>com.googlecode.json-simple</groupId>
<artifactId>json-simple</artifactId>
<version>1.1.1</version>
</dependency>
Now you need to copy the dependency from given site and paste it to your pom.xml file within the <dependencies>
element. In this example, the full pom.xml is:
<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.infy</groupId>
<artifactId>user-identity-rest</artifactId>
<version>1.0.0</version>
<dependencies>
<dependency>
<groupId>com.googlecode.json-simple</groupId>
<artifactId>json-simple</artifactId>
<version>1.1.1</version>
</dependency>
</dependencies>
</project>
Maven will automatically fetch it from its repository.
Step 3: Third and last step is to build your project. Open command prompt/terminal and go to the directory where your pom.xml is declared and type mvn clean install
This will generate an executable for your project on local and voilla! You have converted and built your project into maven project
Reference Path: C:\PA\IntelliJ Workspace\Springboot Practise\target\spring-boot-examples-1.0-SNAPSHOT.jar
Note: Comment below if you need more clarifications.
You seem to be looking for a Minimal POM for your project. This is defined as -
<project>
<modelVersion>4.0.0</modelVersion>
<groupId>com.mycompany.app</groupId>
<artifactId>my-app</artifactId>
<version>1</version>
</project>
where you can replace the names more convenient to your group
and artifact
. Just a small note to take care of -
..if the configuration details are not specified, Maven will use their defaults.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With