81

Last week I was working on a Java EE project with IntelliJ IDE.

Today: As I started up my IntelliJ 2016.1 and it gave me the error:

Error Loading Project

Cannot load module FirstWebApp

As I looked at the details it said it could not find my FirstWebApp.iml file and so could not load my project.

I checked out my project structure in the Explorer and everything except the iml file were there. I also looked at the Recycle Bin but I couldn't find it there as well.

  • How can such a file just disappear?

  • How can I get my iml file back if its possible?

  • What do these iml files do?

I'm new in the Java World. If more information is needed just comment! :)

1
  • 3
    Not relevant to the original question, but, I just want to add: if you work with git, configure a gitignore so these files will not be pushed
    – Arefe
    Commented Feb 16, 2018 at 2:40

10 Answers 10

102

*.iml files have nothing to do with your code/Java. It is a hidden file created by Intellij on the root folder of your project which contains your module information. This is the reason you should not version this kind of file, afterall other developers using a different IDE won't need them.

If you closed Intellij, I think there isn't a way to get the same file back, but on the other hand it is pretty simple to regenerate a new .iml file:

Gradle based project

Click the Sync Project with Gradle Files button (this one enter image description here) in the toolbar;

Maven based project

Go to File > Project Structures > Modules > Add > Import Module > (select your modules base directory) > OK

Edit:

My previous answer were based on IntelliJ 14 and it seems some things have changed on the newer versions, as pointed by hBrent and BeC on the comments.

Using Intellij Community 2018.1 for this update:

Maven based project

The procedure remains the same, the only difference I saw is the Add icon isn't green anymore. One can also try removing the rootFolder/.idea/modules.xml and adding the modules afterwards to reset all information regarding the previous configurations.

Gradle based project

Should use "Refresh all Gradle projects" on the Gradle Tool Window (View > Tool Windows > Gradle), represented by the standard refresh icon.

9
  • 1
    I think that button looks a little different now. I clicked on "refresh all gradle projects" and "execute gradle tasks" in the gradle window. Not sure which one generated the iml file, but I was fine after that.
    – hBrent
    Commented Dec 20, 2017 at 0:20
  • 1
    The settings are different now. I still don't see how to regenerate the impl file within a maven project.
    – DrB
    Commented May 16, 2018 at 11:34
  • @BeC I have just downloaded the latest CE edition of Intellij and for Maven projects the same procedure still regenerated the *.iml files. The + button isn't green anymore, but after clicking it and importing a module from existing sources it worked. Maybe you can try to remove the .idea/modules.xml file before adding the modules back to Intellij to regenerate everything. Let me know if it worked or not please.
    – dambros
    Commented May 17, 2018 at 14:45
  • There is no sync project button Commented Oct 15, 2019 at 21:04
  • 1
    @PrateekGupta what exactly is happening on Pycharm? I feel like the gradle problem doesn't apply to python
    – dambros
    Commented May 26, 2021 at 14:29
88

My mvn project was not also loading correctly in IntelliJ IDEA after I removed .iml file. I fixed it this way:

  1. Closed IntelliJ IDEA
  2. Deleted .idea dir which was in my project dir.
  3. I reopened IntelliJ IDEA and .idea dir and also .iml was after a while automatically recreated by IntelliJ.

Fixed for me.

3
  • 1
    Thanks! after I had to do: File -> Invalidate Caches / Restart
    – Cohensius
    Commented Mar 12, 2020 at 8:20
  • this also fixed my problem! Commented Sep 15, 2020 at 19:49
  • The other methods assumed maven or gradle. I am using IntelliJ without either of those and this worked for me. In fact when I used the Project Setings wizard to rename the project, it didn't update the .iml and doing this got me a new .iml file with the correct name. Commented Apr 28, 2021 at 17:30
14

For Maven projects:

  • Open the Maven Tool Window (indicated with this icon: enter image description here)
  • Click the Reimport All Maven Projects button (indicated with this icon: Reimport All Maven Projects).

Instructions: https://www.jetbrains.com/help/idea/maven-projects-tool-window.html

1
  • 1
    This is the only instruction that actually got my multi-layered Maven project being imported as Maven project/module. Thanks.
    – NuCradle
    Commented Jan 27, 2020 at 0:35
11

enter image description here

If you delete the *.iml file and the .idea folder and close the IntelliJ, it will be re-generated when you open the project again in the next time.

7

I also removed .iml file by accident. Here is how it was resolved:

  1. Closed IntelliJ IDEA
  2. Reopened program
  3. Selected Import Project -> Create project from existing sources
  4. Clicked Next. It created correct project configuration for me.
7
  1. delete .idea folder inside your project
  2. re import the project

it will again compile and build .idea folder for the configuration.

2
  • Easiest solution. And this works very well when your project is neither gradle based or maven based. Thanks! Commented Mar 30, 2021 at 6:59
  • You will lose your window settings, run configurations, and other things when you do this. So keep track of that information so you can rebuild it. Commented Jan 25, 2022 at 16:33
5

If you can't recover it via the most upvoted way, you could simply copy another .iml file, paste it into the package* that requires a .iml file, and rename the .iml file to the name of the package. This should work if it is the same type (in my case UTF-8).

*Copy the .iml file by going into package files, right-clicking the package name, and press paste.

You can accomplish this in the left-hand task bar. I have prepared a video demonstration (there's no audio).

1
  • I did this, but strangely, renaming the pasted .iml file also renames the copied .iml file.
    – Audiopolis
    Commented Aug 23, 2023 at 20:53
2

The Gradle refresh did not work in my case. Several project folders were also missing, so I could not copy/paste new .iml files either.

However when I opened the project anew, choosing Delete Existing Project and Import, the project was able to recreate all the .iml files.

3
  • There is Delete Existing Project? Commented Oct 15, 2019 at 21:05
  • Yes, but it will not delete your project at such. It will close your project properly in IntelliJ and then reopen it from scratch. Usually you don't want to do that, since it takes longer to reopen the project this way. But when things don't work - it may help you. Commented Oct 18, 2019 at 13:52
  • 2
    It's worth mentioning, that doing this, will also clear your Run/Debug Configurations. So you will have to recreate those. Commented Oct 18, 2019 at 13:56
1

Create a new file with the project name and paste it. In case you are working with flutter.

<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
  <component name="NewModuleRootManager" inherit-compiler-output="true">
    <exclude-output />
    <content url="file://$MODULE_DIR$">
      <sourceFolder url="file://$MODULE_DIR$/lib" isTestSource="false" />
      <sourceFolder url="file://$MODULE_DIR$/test" isTestSource="true" />
      <excludeFolder url="file://$MODULE_DIR$/.dart_tool" />
      <excludeFolder url="file://$MODULE_DIR$/.idea" />
      <excludeFolder url="file://$MODULE_DIR$/.pub" />
      <excludeFolder url="file://$MODULE_DIR$/build" />
    </content>
    <orderEntry type="sourceFolder" forTests="false" />
    <orderEntry type="library" name="Dart SDK" level="project" />
    <orderEntry type="library" name="Flutter Plugins" level="project" />
    <orderEntry type="library" name="Dart Packages" level="project" />
  </component>
</module>
2
  • What do you mean with project name? Commented Oct 15, 2019 at 21:09
  • 1
    @IgorGanapolsky try the project folder name: so path/to/projects/my-project would mean that the .iml file in that folder should be called my-project.iml. that's at least what AndroidStudio created automatically when I import a project
    – rexxar
    Commented May 8, 2020 at 10:31
1

I am using phpstorm and project with multiple repos.

My scenario was that, for reasons unspecified, i deleted "main" project directory (and cloned again). Which resulted next project directory to become main , i guess. And also old "main" to be removed from project view in phpstorm.

After trying to open newly cloned project and attach, it failed. New .iml file in attached newly cloned project was fine (although it reported failure), so i went into next projects .idea directory and found .iml file looking like this:

<?xml version="1.0" encoding="UTF-8"?>
<module type="WEB_MODULE" version="4">
  <component name="NewModuleRootManager">
    <content url="file://$MODULE_DIR$" />
    <orderEntry type="inheritedJdk" />
    <orderEntry type="module" module-name="Project1" />
    <orderEntry type="sourceFolder" forTests="false" />
    <orderEntry type="module" module-name="Project3" />
    <orderEntry type="module" module-name="Project4" />
    <orderEntry type="module" module-name="Project1" />
</component>
</module>

So i quit phpstorm, removed all Project1 entries from the second project iml file, restarted IDE, opened and attached newly cloned project1 again, and it was suddenly fine.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.