Add Maven support to an existing project
Required plugins: Maven, Maven Extension (installed and enabled by default)
Refer to Maven section for all actions connected to working with a Maven project
You can open an existing non-Maven project (plain Java project) and add a Maven support via IntelliJ IDEA UI.
Before you start adding Maven to your project, please read Maven documentation to familiarize yourself with Maven concepts and components.
Open an existing project, for example, a Java project.
In the Project tool window Alt01, select the module or the project directory to which you want to add Maven.
Press CtrlShift0A and type
Add Framework Support
.Once the action is found, click it to open the Add Framework Support dialog.
In the dialog that opens, select Maven from the options on the left and click OK.
IntelliJ IDEA adds a default POM to the project and generates the standard Maven layout in Project tool window.
IntelliJ IDEA also creates a corresponding structure with Lifecycle and Plugins in the Maven tool window.
Open the generated POM and specify a
groupId
. TheartifactId
andversion
are specified automatically.note
For more information about Maven naming conventions, refer to the Maven documentation.
Every time you change the POM, IntelliJ IDEA displays a popup suggesting to import your changes.
At this point you can further develop your project using Maven. We recommend making all your project changes in POM since IntelliJ IDEA considers pom.xml as a single source of truth.
You can conclude the following optional steps to create an executable JAR.
From the main menu, select Build | Build Project (
) to build project. IntelliJ IDEA generates target folder. Note that IntelliJ IDEA only compiles sources and doesn't create either JAR file or Manifest file.
Create a Manifest file in the resources directory.
Right-click the directory, select New | Directory to create the META-INF subdirectory. Then right-click the subdirectory, select New | File to create the MANIFEST.MF file.
Open the MANIFEST.MF file in the editor and add information about your main class.
Check the following code:
Main-Class: Main
Alternatively, we can ask Maven to add this line of code into the MANIFEST.MF file with the following code in
pom.xml
:<plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-jar-plugin</artifactId> <configuration> <archive> <manifest> <mainClass> Main </mainClass> </manifest> </archive> </configuration> </plugin>
In your POM specify the Manifest file information, so you can use Maven to generate an executable jar file.
note
Alternatively, you can execute
package
instead of theinstall
command to achieve the same result.In the Maven tool window, in the Lifecycle list, double-click the install command to generate the jar file. IntelliJ IDEA generates the appropriate information in the target folder and an executable JAR in the Project tool window.
You can right-click the generated JAR and select Run to execute the file.
If the existing project contains more than one module, converting such a project into the Maven project becomes quite challenging. In this case we recommend that you create an external POM where you describe your project and open your POM as you would open a regular Maven project.
Thanks for your feedback!