Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

IntelliJ IDE | .iml File lost or deleted

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! :)

like image 413
WetWer Avatar asked Apr 11 '16 07:04

WetWer


People also ask

How do I recover deleted files in IntelliJ?

If you've accidentally deleted a file that was not under version control, you can restore it with Local History. Select the node that contained the file you deleted in the Project tool window, right-click it and choose Local History | Show History from the context menu.

Where are .IML files stored?

Storage (iml file) Configuration information for a module is stored in a . iml module file. By default, such a file is located in the module's content root folder.

How do I open .IML files in IntelliJ?

From the main menu, select File | New | Module from Existing Sources. In the dialog that opens, specify the path the . iml file of the module that you want to import, and click Open. By doing so, you are attaching another module to the project without physically moving any files.


1 Answers

*.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.

like image 162
dambros Avatar answered Sep 20 '22 23:09

dambros