Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Relationship between .iml file and pom.xml file

Each time I create a Maven project, there is a .iml file along with a pom.xml file. What exactly is their relationship?

like image 803
derek Avatar asked Dec 19 '17 03:12

derek


People also ask

What is .IML file in Maven?

An IML file is a module settings file created by IntelliJ IDEA, an Integrated Development Environment (IDE) used to develop Java applications. It stores information about a development module, which is a Java, Plugin, Android, or Maven component of a Java application.

What is the use of .IML file?

IML is a module file created by IntelliJ IDEA, an IDE used to develop Java applications. It stores information about a development module, which may be a Java, Plugin, Android, or Maven component; saves the module paths, dependencies, and other settings.

What is the use of IML file in Maven project?

IML file stores information concerning development modules like an android, plugin, java, or maven component of a java application. It stores modules, paths, types, dependencies, and order settings. Additionally, it stores a module-level setting for larger development projects while using XML formatting.

What is difference between POM and POM XML?

POM stands for Project Object Model, and it is the core of a project's configuration in Maven. It is a single configuration XML file called pom. xml that contains the majority of the information required to build a project.


2 Answers

The pom.xml is used by maven to resolve your project's dependencies, which plugins to execute and a lot of other things. From the maven website:

A Project Object Model or POM is the fundamental unit of work in Maven. It is an XML file that contains information about the project and configuration details used by Maven to build the project.

The .iml file on the other hand is part of IntelliJ's own project structure. The short version is that it declares the libraries (e.g. jars) that are visible only to the module, and not the rest of the project or other projects. It's an xml file containing a library entry for each artifact declared in your pom.xml, along with its scope (e.g. TEST or COMPILE). For example:

<?xml version="1.0" encoding="UTF-8"?> <module org.jetbrains.idea.maven.project.MavenProjectsManager.isMavenModule="true" type="JAVA_MODULE" version="4">   <component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_8">     <output url="file://$MODULE_DIR$/target/classes" />     <output-test url="file://$MODULE_DIR$/target/test-classes" />     <content url="file://$MODULE_DIR$">       <sourceFolder url="file://$MODULE_DIR$/src/main/java" isTestSource="false" />       <sourceFolder url="file://$MODULE_DIR$/src/test/java" isTestSource="true" />       <excludeFolder url="file://$MODULE_DIR$/target" />     </content>     <orderEntry type="inheritedJdk" />     <orderEntry type="sourceFolder" forTests="false" />     <orderEntry type="library" scope="COMPILE" name="Maven: com.google.guava:guava:18.0" level="project" />     <orderEntry type="library" scope="TEST" name="Maven: org.hamcrest:hamcrest-library:1.3" level="project" />     <orderEntry type="library" scope="TEST" name="Maven: org.hamcrest:hamcrest-core:1.3" level="project" />     <orderEntry type="library" scope="TEST" name="Maven: junit:junit:4.12" level="project" />   </component> </module> 

I assume IntelliJ keeps its own file format so it can read the project faster, regardless of which build system the project is using (e.g. maven vs. gradle).

like image 197
gjoranv Avatar answered Oct 02 '22 14:10

gjoranv


IntelliJ idea doesn't understand the maven project model (POM.xml) itself. When creating or importing maven project in idea. It also creating its own project structure, maven dependencies , module details etc etc.. basically required project metadata in the format it can understand and use it internally for it actions. These metadata stored in .iml file and .idea project directory.

Main advantage of keeping it's own structure would provide capacity to run faster and manage project efficiently. I hope this give some explanation on the relationship between these two files.

Sample pom.xml

 <?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://maven.apache.org/POM/4.0.0"          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"          xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">     <modelVersion>4.0.0</modelVersion>      <groupId>test</groupId>     <artifactId>test</artifactId>     <version>1.0-SNAPSHOT</version>      <build>         <plugins>             <plugin>                 <groupId>org.apache.maven.plugins</groupId>                 <artifactId>maven-compiler-plugin</artifactId>                 <configuration>                     <source>1.8</source>                     <target>1.8</target>                 </configuration>             </plugin>         </plugins>     </build>      <dependencies>         <dependency>             <groupId>log4j</groupId>             <artifactId>log4j</artifactId>             <version>${log4j.version}</version>         </dependency>         <dependency>             <groupId>org.slf4j</groupId>             <artifactId>slf4j-log4j12</artifactId>             <version>${org.slf4j.version}</version>         </dependency>         <dependency>             <groupId>org.easymock</groupId>             <artifactId>easymock</artifactId>             <version>2.5.2</version>             <optional>true</optional>         </dependency>         <dependency>             <groupId>org.jmock</groupId>             <artifactId>jmock</artifactId>             <version>${jmock.version}</version>             <optional>true</optional>         </dependency>         <dependency>             <groupId>org.jmock</groupId>             <artifactId>jmock-junit4</artifactId>             <version>${jmock.version}</version>             <optional>true</optional>         </dependency>         <dependency>             <groupId>junit</groupId>             <artifactId>junit</artifactId>             <version>${junit.version}</version>             <scope>test</scope>         </dependency>         <dependency>             <groupId>junitperf</groupId>             <artifactId>junitperf</artifactId>             <version>1.8</version>         </dependency>     </dependencies>      <properties>         <jmock.version>2.5.1</jmock.version>         <junit.version>4.6</junit.version>         <log4j.version>1.2.14</log4j.version>         <org.slf4j.version>1.5.2</org.slf4j.version>     </properties> </project> 

Relavent IDEA .iml file

<?xml version="1.0" encoding="UTF-8"?> <module org.jetbrains.idea.maven.project.MavenProjectsManager.isMavenModule="true" type="JAVA_MODULE" version="4">   <component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_8">     <output url="file://$MODULE_DIR$/target/classes" />     <output-test url="file://$MODULE_DIR$/target/test-classes" />     <content url="file://$MODULE_DIR$">       <sourceFolder url="file://$MODULE_DIR$/src/main/java" isTestSource="false" />       <sourceFolder url="file://$MODULE_DIR$/src/main/resources" type="java-resource" />       <sourceFolder url="file://$MODULE_DIR$/src/test/java" isTestSource="true" />       <excludeFolder url="file://$MODULE_DIR$/target" />     </content>     <orderEntry type="inheritedJdk" />     <orderEntry type="sourceFolder" forTests="false" />     <orderEntry type="library" name="Maven: log4j:log4j:1.2.14" level="project" />     <orderEntry type="library" name="Maven: org.slf4j:slf4j-log4j12:1.5.2" level="project" />     <orderEntry type="library" name="Maven: org.slf4j:slf4j-api:1.5.2" level="project" />     <orderEntry type="library" name="Maven: org.easymock:easymock:2.5.2" level="project" />     <orderEntry type="library" name="Maven: org.jmock:jmock:2.5.1" level="project" />     <orderEntry type="library" name="Maven: org.hamcrest:hamcrest-core:1.1" level="project" />     <orderEntry type="library" name="Maven: org.hamcrest:hamcrest-library:1.1" level="project" />     <orderEntry type="library" name="Maven: org.jmock:jmock-junit4:2.5.1" level="project" />     <orderEntry type="library" name="Maven: junit:junit-dep:4.4" level="project" />     <orderEntry type="library" scope="TEST" name="Maven: junit:junit:4.6" level="project" />     <orderEntry type="library" name="Maven: junitperf:junitperf:1.8" level="project" />   </component> </module> 
like image 43
nayakam Avatar answered Oct 02 '22 13:10

nayakam