1

I added a dependency to my pom.xml file but cannot find the option to import the dependency. I'm not able to use the library in my program.

I've looked online and many suggest going to Settings -> Maven -> .... but this option simply does not exist for me.

I have also seen other solutions of simply right clicking the pom.xml -> Maven -> Reimport. Again, I don't have this option. I am pretty sure this is a Maven project.

Does anyone know what might be the problem?

eyes enberg
  • 556
  • 1
  • 8
  • 30

3 Answers3

3

You might need to configure Auto-Import for Maven projects. You can enable such feature going to File > Settings > Maven > Importing. There is a checkbox that says "Import Maven projects automatically". If you can't find that option, try using Ctrl+Shift+A that helps you to find actions by name. Just write "maven" and check what alternative suits you the best.

If this do not work, open my "Maven Project" Panel. Find it at the right side of your IDE. There you have the reimport button.

Maven Projects Panel

EDIT:

A few weeks ago, I faced the same problem when reimporting a project. It was due to Intellij didn't remember the setting for the maven setting file. I needed to override the default "User settings file" (see the picture below) with my valid ~/.m2 path.

User settings

Julieta
  • 407
  • 2
  • 8
  • The issue was that there was no Maven when I pressed Settings (just Gradle and grant). However, I hit Ctrl + Shift + A like you said, typed Maven and the auto re-import feature was there. Thank you. – eyes enberg Aug 29 '16 at 12:20
  • I had the same issue - this solution helped (changing the directory of currently used maven) but in addition I had to delete the whole ~/.m2 folder and reimport everything again – Kacper Wolkowski Sep 13 '21 at 20:26
0

The maven will automatically download the jar file from public repository after you save the pom file. If you find that it doesn't exist in your maven dependencies, you can try to check below:

  1. Check your network connectivity, whether it's able to connect to public repository.

  2. Check whether the required dependency exist in public.

  3. If it's a local dependency, please make sure you have done the Maven Install.

  • I'm using the dependency in another Maven project so I know it's working. When I include it in the new project's pom.xml and synchronize + rebuild it doesn't recognise the classes. There is no reimport option anywhere (which I'm sure I was able to do somehow on my other project). – eyes enberg Aug 29 '16 at 04:07
0

IntelliJ should download and add all your dependencies to the project's classpath automatically as long as your POM is compliant and all the dependencies are available.

When importing Maven projects into IntelliJ an information box usually comes up asking you if you want to configure Auto-Import for Maven projects. That means that if you make any changes to your POM those changes will be loaded automatically.

You can enable such feature going to File > Settings > Maven > Importing, there is a checkbox that says "Import Maven projects automatically".

If that doesn't help, then I would suggest to make a full clean-up and start again:

  • Close your project window (and IntelliJ) and remove all *.iml files and all .idea folders (there should be one per module).
  • Run mvn clean install from the command line
  • Re-import the project into IntelliJ and pay attention when it asks you to enable auto-import

Check this post for more Information

Community
  • 1
  • 1
Keshan Nageswaran
  • 8,060
  • 3
  • 28
  • 45