IntelliJ IDE | .iml File lost or deleted

前端 未结 10 804
梦谈多话
梦谈多话 2021-02-06 20:07

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

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

Error Loading Project

相关标签:
10条回答
  • 2021-02-06 20:46

    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>
    
    0 讨论(0)
  • 2021-02-06 20:50

    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.

    0 讨论(0)
  • 2021-02-06 20:54

    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.

    0 讨论(0)
  • 2021-02-06 20:58

    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.

    0 讨论(0)
  • 2021-02-06 21:05

    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.

    0 讨论(0)
  • 2021-02-06 21:10

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

    0 讨论(0)
提交回复
热议问题