如何在Intellij IDEA 11中构建maven导入项目?

如何在Intellij IDEA 11中构建maven导入项目?,maven,intellij-idea,Maven,Intellij Idea,我通过导入maven项目创建了一个新的IntelliJ项目。效果很好: 我可以从maven项目窗格(在IDE屏幕的左侧)执行maven目标。例如,我可以使用编译目标来编译项目 现在我想使用build | Make project选项从UI构建项目。但是,它不起作用。它抱怨缺少应用程序包,好像看不到依赖项一样。这些依赖项在各自的pom.xml文件中定义,但是从IDE创建项目似乎忽略了它 我要做什么才能使它工作 编辑 好的,我已经从我的主页中删除了.m2目录,并从Maven项目弹出菜单开始编译目标

我通过导入maven项目创建了一个新的IntelliJ项目。效果很好:

我可以从maven项目窗格(在IDE屏幕的左侧)执行maven目标。例如,我可以使用编译目标来编译项目

现在我想使用build | Make project选项从UI构建项目。但是,它不起作用。它抱怨缺少应用程序包,好像看不到依赖项一样。这些依赖项在各自的pom.xml文件中定义,但是从IDE创建项目似乎忽略了它

我要做什么才能使它工作

编辑

好的,我已经从我的主页中删除了.m2目录,并从Maven项目弹出菜单开始编译目标。我可以在控制台窗格中看到maven从maven Central下载依赖项(我只给出了日志的前几行,很长):

因此,我认为连接Maven Central没有问题

EDIT2

请注意: 请注意问题-有两个模块从Maven导入-CommonCore。他们的Maven工件Id分别是commonscore。IntelliJ似乎混淆了工件Id和模块名称,因为:

  • 项目弹出按钮显示模块名称,后面是括号中相应的maven工件Id
  • 在“项目设置”对话框中,模块仅由相应的maven工件Id给出
  • 但在模块依赖项中,它仅列出模块名称
  • Core模块(maven工件IdCore)应该看到依赖关系Common模块(maven工件Idcommons),但它没有,这就是问题所在

    EDIT3

    以下是最顶级的pom.xml:

    <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>com.shunra</groupId>
        <name>VCat-build</name>
        <version>1.0.0.SNAPSHOT</version>
        <artifactId>VCat-build</artifactId>
        <packaging>pom</packaging>
        <modules>
            <module>../../../util.logging</module>
            <module>../../../Infra</module>
            <module>../../../DTOs</module>
            <module>../../../ShunraLicense</module>
            <module>../../../Common</module>
            <module>../../../Core</module>
            <module>../../../VCat</module>
        </modules>
        <build>
            <plugins>
            </plugins>
        </build>
    </project>
    
    
    4.0.0
    com.shunra
    VCat构建
    1.0.0.1快照
    VCat构建
    聚甲醛
    ../../../util.logging
    ../../../Infra
    ../../../DTOs
    ../../../ShunraLicense
    ../../../Common
    ../../../Core
    ../../VCat
    
    以下是通用模块的示例:

    <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>com.shunra</groupId>
      <artifactId>commons</artifactId>
      <version>0.0.1</version>
      <dependencies>
            <dependency>
                <groupId>com.sun.jna</groupId>
                <artifactId>jna</artifactId>
                <version>3.0.9</version>
            </dependency>
    
            <dependency>
                <groupId>commons-io</groupId>
                <artifactId>commons-io</artifactId>
                <version>1.4</version>
            </dependency>
            <dependency>
                <groupId>org.apache.commons</groupId>
                <artifactId>commons-math</artifactId>
                <version>2.2</version>
            </dependency>
            <dependency>
                <groupId>org.codehaus.jackson</groupId>
                <artifactId>jackson-mapper-asl</artifactId>
                <version>1.9.4</version>
                <type>jar</type>
                <scope>compile</scope>
            </dependency>
            <dependency>
                <groupId>javax.xml.bind</groupId>
                <artifactId>jaxb-api</artifactId>
                <version>2.2.7</version>
                <type>jar</type>
                <scope>compile</scope>
            </dependency>
            <dependency>
                    <groupId>com.shunra</groupId>
                    <artifactId>util.logging</artifactId>
                    <version>0.0.1</version>
            </dependency>
            <dependency>
                    <groupId>com.google.code.gson</groupId>
                    <artifactId>gson</artifactId>
                    <version>1.6</version>
                    <scope>compile</scope>
            </dependency>
            <dependency>
                    <groupId>commons-codec</groupId>
                    <artifactId>commons-codec</artifactId>
                    <version>1.6</version>
                    <scope>compile</scope>
            </dependency>
            <dependency>
                  <groupId>org.restlet.jse</groupId>
                  <artifactId>org.restlet</artifactId>
                  <version>2.0.10</version>
            </dependency>
            <dependency>
              <groupId>javax.inject</groupId>
              <artifactId>javax.inject</artifactId>
              <version>1</version>
              <scope>compile</scope>
            </dependency>
            <dependency>
                <groupId>commons-configuration</groupId>
                <artifactId>commons-configuration</artifactId>
                <version>1.8</version>
                <type>jar</type>
                <scope>compile</scope>
            </dependency>
            <dependency>
                <groupId>commons-beanutils</groupId>
                <artifactId>commons-beanutils</artifactId>
                <version>1.8.3</version>
                <type>jar</type>
                <scope>compile</scope>
            </dependency>
    <!--        <dependency>
                <groupId>com.shunra</groupId>
                <artifactId>license</artifactId>
                <version>0.0.1</version>
            </dependency> -->
            <dependency>
                  <groupId>com.shunra</groupId>
                  <artifactId>dtos</artifactId>
                  <version>0.0.1</version>
            </dependency>
      </dependencies>
        <repositories>
        <repository>
           <id>maven-restlet</id>
           <name>Public online Restlet repository</name>
           <url>http://maven.restlet.org</url>
        </repository> 
       </repositories>
      <build>
        <sourceDirectory>src</sourceDirectory>
        <resources>
          <resource>
            <directory>src</directory>
            <excludes>
              <exclude>**/*.java</exclude>
            </excludes>
          </resource>
        </resources>
        <plugins>
          <plugin>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>2.3.2</version>
            <configuration>
              <source/>
              <target/>
            </configuration>
          </plugin>
        </plugins>
      </build>
    </project>
    
    
    4.0.0
    com.shunra
    平民
    0.0.1
    com.sun.jna
    jna
    3.0.9
    公地io
    公地io
    1.4
    org.apache.commons
    公共数学
    2.2
    org.codehaus.jackson
    杰克逊地图绘制者
    1.9.4
    罐子
    编译
    javax.xml.bind
    jaxb api
    2.2.7
    罐子
    编译
    com.shunra
    util.logging
    0.0.1
    com.google.code.gson
    格森
    1.6
    编译
    通用编解码器
    通用编解码器
    1.6
    编译
    org.restlet.jse
    org.restlet
    2.0.10
    javax.inject
    javax.inject
    1.
    编译
    共用配置
    共用配置
    1.8
    罐子
    编译
    公地小海狸
    公地小海狸
    1.8.3
    罐子
    编译
    com.shunra
    dtos
    0.0.1
    maven restlet
    公共在线Restlet存储库
    http://maven.restlet.org
    src
    src
    **/*.爪哇
    maven编译器插件
    2.3.2
    
    这是一个核心模块:

    <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>com.shunra</groupId>
      <artifactId>core</artifactId>
      <version>0.0.1</version>
      <dependencies>
        <dependency>
          <groupId>com.shunra</groupId>
          <artifactId>commons</artifactId>
          <version>0.0.1</version>
        </dependency>
        <dependency>
            <groupId>com.shunra</groupId>
            <artifactId>license</artifactId>
            <version>0.0.1</version>
        </dependency>
      </dependencies>
      <build>
        <sourceDirectory>src</sourceDirectory>
        <resources>
          <resource>
            <directory>src</directory>
            <excludes>
              <exclude>**/*.java</exclude>
            </excludes>
          </resource>
        </resources>
        <plugins>
          <plugin>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>2.3.2</version>
            <configuration>
              <source/>
              <target/>
            </configuration>
          </plugin>
        </plugins>
      </build>
    </project>
    
    
    4.0.0
    com.shunra
    核心
    0.0.1
    com.shunra
    平民
    0.0.1
    com.shunra
    许可证
    0.0.1
    src
    src
    **/*.爪哇
    maven编译器插件
    2.3.2
    
    EDIT4


    终于解决了。已删除所有Intellij文件并重新导入。我猜pom.xml文件的变化让IntelliJ感到困惑。

    查看屏幕截图,您似乎没有脱机工作,这是导致此问题的最常见原因

  • 尝试从Maven Projects弹出按钮下载源代码和文档(这是左侧的第三个图标)。这通常会唤醒它并导致下载

  • 使用运行时配置执行手动Maven构建。选择Edit Configurations | Maven,然后确保您的工作目录是您的项目根目录,并选择“clean package”目标。这将迫使Intellij直接通过Maven进行重建,这可能会唤醒内部后台构建过程

  • 检查您的设置,确保Intellj的Maven已从POM正确读取存储库信息,并且能够找到Maven Central。您的local settings.xml可能有问题,无法下载

  • 您还可以删除.idea和.iml文件以强制重新导入项目

  • 重新启动Intellij并希望一切顺利

  • 作为最后的手段,请通过文件|使缓存无效来使缓存无效。这可能会使您的开发速度减慢一点,直到通过使用重建它们

  • 编辑以涵盖更新的问题

    It应用程序
    <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>com.shunra</groupId>
      <artifactId>core</artifactId>
      <version>0.0.1</version>
      <dependencies>
        <dependency>
          <groupId>com.shunra</groupId>
          <artifactId>commons</artifactId>
          <version>0.0.1</version>
        </dependency>
        <dependency>
            <groupId>com.shunra</groupId>
            <artifactId>license</artifactId>
            <version>0.0.1</version>
        </dependency>
      </dependencies>
      <build>
        <sourceDirectory>src</sourceDirectory>
        <resources>
          <resource>
            <directory>src</directory>
            <excludes>
              <exclude>**/*.java</exclude>
            </excludes>
          </resource>
        </resources>
        <plugins>
          <plugin>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>2.3.2</version>
            <configuration>
              <source/>
              <target/>
            </configuration>
          </plugin>
        </plugins>
      </build>
    </project>