.iml文件和pom.xml文件之间的关系 [英] Relationship between .iml file and pom.xml file

查看:168
本文介绍了.iml文件和pom.xml文件之间的关系的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

每次创建一个Maven项目时,都有一个.iml文件和一个pom.xml文件. 他们到底是什么关系?

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

推荐答案

maven使用pom.xml来解决项目的依赖项,要执行的插件以及许多其他事情.从 maven网站:

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:

项目对象模型或POM是Maven中的基本工作单元.这是一个XML文件,其中包含有关项目的信息以及Maven用于构建项目的配置详细信息.

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.

另一方面,.iml文件是IntelliJ自己的项目结构.简短的版本是它声明仅对模块可见的库(例如jars),而对项目的其余部分或其他项目不可见.这是一个xml文件,其中包含pom.xml中声明的每个工件的库条目以及其范围(例如TESTCOMPILE).例如:

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>

我认为IntelliJ保留其自己的文件格式,因此无论项目使用哪个构建系统(例如 maven gradle ),它都能更快地读取项目.

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

这篇关于.iml文件和pom.xml文件之间的关系的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆