The deletion of the .iml file causes the project to fail to start, and the report "**type** package does not exist"

Foreword: Because I am not familiar with the role of iml files, and there is no submission of the file on git, it is very annoying to watch the iml file continue to be popular, I owe it to delete it, and then the project is quoted in various reports and classes. If not, the package cannot be found, and the classes referenced in the classes in the project are also popular. Record the course of the problem.

What is an iml file?

The iml (infomation of module) file is a java modular file automatically created by IDEA. It is used for java application development and stores the information of module development. For example, a java component or maven component will generate an iml file. The module will store some module information and dependencies. information.

Problem Description

Due to deleting the iml file and starting the project, it reported that various classes and symbols could not be found, and many other classes referenced in the class became popular.

Try solution one: recompile all services

Recompile all services, and then compile through. The references in the project are still hot, and the jar, class and other files are still not found when the project is started. The solution fails. However, it is worth noting that when running maven to recompile the project, every Both projects have generated iml files, but the problem still cannot be solved.

Try solution two: re-download the git code

This time, after sorting out your own code, submit it to git, then delete all the local code, pull it from git, and then solve the problem. In fact, there is another solution, which is to manually generate an iml file in the directory of each project, and then the problem can also be solved. Use the command in the root directory of the project: mvn idea:module can also be solved , but for dozens It is not suitable for a service project, and it is not cost-effective to directly pull the code.

summary of a problem

If you use idea to load the project, an iml file will be generated. If you delete it and compile with maven, it will also generate the file. However, the generated iml file with the same name will report an error when you start the project and it will not run normally. The cause of this problem was caused by uncomfortable reading of the iml file, which was very bloody. Later, I also found out how to hide the iml file from git so that the file does not become popular.

Hide the iml file from git to prevent it from becoming popular

Open setting->File Types, as shown below:
Insert picture description here
Then select .gitingore (GitIngore) in the figure, and then click to the position in the figure below, add *.iml, and IDEA will not always prompt you that this is a git There is no file to perform the add operation.

Insert picture description here

Guess you like

Origin blog.csdn.net/m0_46897923/article/details/114678183