Add Maven support to an existing project
You can open an existing non-Maven project and add a Maven support via IntelliJ IDEA UI.
Add Maven support
Open an existing project, for example, a Java project.
In the Project tool window, right-click your project and select Add Framework Support .
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 . The artifactId and version are specified automatically.
For more information regarding 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.
Create an executable JAR
You can conclude the following optional steps to create an executable JAR.
Click 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:
Alternatively, we can ask Maven to add this line of code into the MANIFEST.MF file with the following code in pom.xml :
In your POM specify the Manifest file information, so you can use Maven to generate an executable jar file.

Alternatively, you can execute package instead of the install 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.
Как создать jar файл в intellij idea maven

A JAR (Java archive) file is a platform-independent package of your application in a single archive file. Packaging your application into a JAR makes it easier to distribute your program, and it also means functionalities in your program are reusable—for example, other programs can use your functionalities just by adding your JAR file as a dependency.
There are two types of JARs: normal and executable. Normal JARs have no entry point, meaning you cannot directly execute this type of JAR. You can only add it as a dependency to other programs and access the classes and functions in your program. On the other hand, an executable JAR can be executed directly without any external program. Simply put, you can start an executable JAR directly just by double-clicking on it.
IntelliJ provides a couple different ways to export a JAR from your workspace. In this tutorial, I’ll explain the two different methods for setting up your project architecture to export a JAR from IntelliJ:
- Building an artifact in IntelliJ
- Using Maven
To understand the tutorial better, you’ll use a simple example program that accepts user profile information as a command line argument. This program also uses Picocli and Apache Commons Cli as external dependencies, which will support validating and parsing the command line parameters.
Export a JAR Using the Build Artifact Method
In this method, you’ll export a JAR using the IntelliJ build option. Before starting up, you’ll need to create a project and add the necessary dependencies to it. Dependencies are external programs packaged as a JAR with some functionalities implemented already and can easily be reused in your program. You’ll also need to create a main class with some simple functionality.
Once you’ve created a project and a Run Configuration, which can be used to execute the project, let’s set up your program to export a JAR from the IntelliJ workspace.
1. Configure the project settings to define the artifacts of this project. Click Project Structure from the file menu.
- Extract to the target JAR: This option extracts all the class files of your external libraries to the JAR you’re creating. This single JAR will contain your class files and also the class files from your external dependencies. This option is recommended because handling a single JAR is easier than handling multiple. You can easily add it to your other programs and execute it with a double click.
- Copy to the output directory and link via Manifest: This option copies your dependency JARs to the output directory and creates a link with your Java program using the manifest file. If you select this option, you should also specify a location where the manifest file needs to be created. This method is recommended if you have a lot of JARs, and particularly if any of them are signed. Signed JARs may not work properly when you extract the class files into the JAR. Therefore, it’s better to copy the JARs to the output directory and use them via the manifest file.
5. Select the appropriate option and click OK, creating an artifact in your Artifacts window.
Exporting a JAR Using Maven
Maven is a project management and automation tool, developed to make the build process easier. For example, you can create scripts to:
- Build a project and create a JAR after each and every commit to your git repo.
- Build a project nightly and deploy the JARs in the production systems when all the defined test cases are passing.
- Automate build and deployment of projects with Jenkins.
To begin, create a Maven project in IntelliJ using this tutorial. Remember to add the necessary classes for your project. You can use the same class files and dependencies used in the previous section’s example.
When you create a new Maven project, you’ll have the minimal POM file created in your project directory with the following contents:
This POM file contains three important artifacts for the project:
- groupId : A unique base name of the company that creates and maintains the project.
- artifactId : A unique name for the project itself
- version : Version number for the project
Configuring the Maven build
In this section, you’ll configure the aspects of your Maven build. You can add various plugins inside the build section of your POM file based on your requirements. Each will have different functions. These plugins will be executed during the build of your project.
In this tutorial, you’ll add the necessary plugin and configure it to export a JAR during the build.
This adds a Maven compiler for your projects and also denotes the java version for compiling your sources. Here, you’re using Java version 1.8.
2. Add the maven-assembly-plugin . This creates an assembly of your Java project.
For a quick explanation of the plugin’s various sections:
- artifactId : The name of the plugin itself
- configuration : Configures the maven assembly
- finalName : Final name of the assembly to be created : Flag to include or exclude the assembly name in the JAR’s final name : Adds instructions to the archive builder, in this case, adding the main class of your Java program in the manifest : List of references to assembly descriptors available on the plugin’s classpath
- execution : Tag to specify the activities to be performed during execution
- goal : Here, directory-single is used to create a single file during the build
Now that you’ve configured the Maven settings for your project, the whole POM file for the project should look like this:
Executing a Maven Build
Next, you’ll create a configuration for the Maven build and execute it. It’ll export a JAR in the directories you’ve specified.
1. Navigate to Run > Edit Configurations. The Run/Debug Configurations window opens.
Conclusion
Building a JAR in IntelliJ is a little complicated when it comes to configuring project structure and generating artifacts. In the case of using Maven, it’s even more difficult due to the setup involved with configuring the POM file and the project’s build processes.
But in this tutorial, you learned how to tackle two different options for building a JAR (using the build artifact method and using Maven) in IntelliJ to make the process easier. If you’ve got any suggestions or tips for creating a JAR that this article didn’t cover, please let me know about them in the comments.
How to create a JAR file with Maven in IntelliJ
Use Maven to compile and package your Java application
Updated: 10 May 2022
Building a JAR file is the most common way to share your compiled Java application. When you pull dependencies from Maven, they’re actually contained in a bunch of JAR files. So how do you create your own JAR?
Perhaps you’re new to Java development (welcome!), or you’re moving to IntelliJ from Eclipse? Well, fortunately it’s quite easy to create a JAR file in IntelliJ IDEA with a Maven project.
Let’s see how to do it.
Summary
To create a JAR file from a Maven project in IntelliJ IDEA, go to the Maven Tool Window (View → Tool Windows → Maven), expand your project in the tree, expand Lifecycle, and then double-click on package.
Create a JAR of a Maven project
Maven is a project management tool for Java projects, used by lots of projects. Maven can download dependencies, run tests, compile your Java application and package it.
IntelliJ comes with its own Maven instance, which we can control from the IntelliJ GUI.
So whenever we want to perform Maven tasks – like compiling, running tests or packaging – we can use the tools in IntelliJ to do it.
In Maven, all of the tasks to create a JAR are defined in a phase called package . (A phase is just a stage in a build — there are other phases like compile and test .)
An example Maven project
The steps below should work with any basic Maven project, but in case you want to see an example, check out this repository:
Here’s the POM file that I used:
Now let’s create a JAR file from this Maven project.
Create a JAR from your Maven project
Open your Maven project in IntelliJ IDEA (File → Open).
Make sure that the Maven tool window is visible by going to View → Tool Windows → Maven.
Expand your project in the tree, expand Lifecycle and double-click on package.
IntelliJ will run the Maven package phase, and you’ll see the output in another window below.
What is a JAR file, anyway?
A JAR file is kinda special. As well as your compiled classes, it also contains a manifest file ( MANIFEST.MF ).
This manifest file contains some basic info about your app, but it can also contain information about other files inside the JAR.
So it’s better to use your IDE or build tool (like Maven) to help you create it.
Wrapping up
We’ve seen how to create a JAR file for a Maven project in IntelliJ.
By Tom Donohue, Editor | Twitter | LinkedIn
Tom is the founder of Tutorial Works. He’s an engineer and open source advocate. He uses the blog as a vehicle for sharing tutorials, writing about technology and talking about himself in the third person. His very first computer was an Acorn Electron.
Thanks for reading. Let’s stay in touch.
It took us this long to find each other. So before you close your browser and forget all about this article, shall we stay in touch?
Join our free members’ newsletter. We’ll email you our latest tutorials and guides, so you can read at your leisure! (No spam, unsubscribe whenever you want.)
Thank you!
We’ve sent you an email. Please check your email, and click the link inside to confirm your subscription.
Want more? Read these articles next.
How to find out where a Maven dependency comes from: Need to know exactly which libraries and dependencies your Java project is using? Maven knows that. Here’s how find out.
Run a web server in a Linux VM with Vagrant [Learning Project]: Learn Linux and virtualisation basics by deploying a website in this tutorial.
How to create a simple HTTP server in Java with Undertow: Create a very lightweight Java web server, which packages to a small fat-jar, under 3MB; ideal for learning or demos
Java IDEs: The Definitive Guide (and Top Picks): Not all IDEs are created the same, so if you’re writing Java code, make sure you choose a good one.
You might also like.
Advertisements
report this ad Advertisements
Tutorial Works is a website to help you navigate the world of IT, and grow your tech career, with tips, tutorials, guides, and real opinions.
Thanks for being here today!
Copyright © 2022 Tom Donohue. All rights reserved, except where stated. You can use our illustrations on your own blog, as long as you include a link back to us.
Как создать Jar файл в Maven

В этом уроке я покажу вам, как использовать Maven для создания Java проекта и упаковать его в *.jar файл, а также как сделать его исполняемым.
1) Создание Maven проекта.
Есть два способа создать Maven project:
1. С помощью maven command:
2. С иcпользованием IDE, в моем случае это Intellij IDEA 11.3




2. Создание jar файла
Чтобы создать jar файл нам потребуется добавить в конфигурационный Maven файл pom.xml.
В этом файле в теге <pagckaging>jar</pagckaging>
Если вы попытаетесь собрать проект Maven, Maven упакует этот проект в “jar” файл с именем «projectMy-1.0.jar» , найти этот файл вы можете в корне проекта в папке target .