我已通过导入maven项目创建了一个新的IntelliJ项目,这很顺利:
我可以从Maven Projects面板(在IDE屏幕左侧)执行maven目标。例如,我可以使用compile目标编译项目。
现在,我想使用“Build|Make Project”选项从UI构建项目。然而,它不起作用。它抱怨缺少应用程序包,好像它看不到依赖项。这些依赖关系在各自的pom.xml文件中定义,但从IDE制作项目似乎忽略了它。
我该怎么做才能使其工作?
编辑
好的,我已从我的主目录中删除了.m2目录,并从Maven Projects flyout启动了编译目标。我可以在控制台窗格中看到maven从Maven Central下载依赖项(我只给出日志的前几行,它非常长):
所以,我想连接到Maven Central没有问题。
编辑2
请注意:
注意问题-有两个模块从Maven导入-Common和Core。它们的Maven artifact Id分别是commons和core。IntelliJ似乎混淆了artifact Id和模块名称,因为:
编辑3
这是最顶层的pom.xml:
这是与“共同模块”相关的翻译:
![enter image description here](https://istack.dev59.com/JvbBs.webp)
现在,我想使用“Build|Make Project”选项从UI构建项目。然而,它不起作用。它抱怨缺少应用程序包,好像它看不到依赖项。这些依赖关系在各自的pom.xml文件中定义,但从IDE制作项目似乎忽略了它。
我该怎么做才能使其工作?
编辑
好的,我已从我的主目录中删除了.m2目录,并从Maven Projects flyout启动了编译目标。我可以在控制台窗格中看到maven从Maven Central下载依赖项(我只给出日志的前几行,它非常长):
"C:\Program Files (x86)\Java\jdk1.6.0_29\bin\java" -Dclassworlds.conf=O:\java\apache-maven-3.0.4\bin\m2.conf -Dmaven.home=O:\java\apache-maven-3.0.4 -Didea.launcher.port=7534 "-Didea.launcher.bin.path=C:\Program Files (x86)\JetBrains\IntelliJ IDEA 11.1.2\bin" -Dfile.encoding=UTF-8 -classpath "O:\java\apache-maven-3.0.4\boot\plexus-classworlds-2.4.jar;C:\Program Files (x86)\JetBrains\IntelliJ IDEA 11.1.2\lib\idea_rt.jar" com.intellij.rt.execution.application.AppMain org.codehaus.classworlds.Launcher --no-plugin-registry --fail-fast --strict-checksums --update-snapshots -f C:\dev\shunra\Application\Builder\build\vcat\pom.xml compile
[WARNING] Command line option -npr is deprecated and will be removed in future Maven versions.
[INFO] Scanning for projects...
[WARNING]
[WARNING] Some problems were encountered while building the effective model for com.shunra:VCat-build:pom:1.0.0.SNAPSHOT
[WARNING] 'version' uses an unsupported snapshot version format, should be '*-SNAPSHOT' instead. @ line 7, column 11
[WARNING]
[WARNING] It is highly recommended to fix these problems because they threaten the stability of your build.
[WARNING]
[WARNING] For this reason, future Maven versions might no longer support building such malformed projects.
[WARNING]
[INFO] ------------------------------------------------------------------------
[INFO] Reactor Build Order:
[INFO]
[INFO] util.logging
[INFO] Infra
[INFO] dtos
[INFO] commons
[INFO] license
[INFO] core
[INFO] vcat
[INFO] VCat-build
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building util.logging 0.0.1
[INFO] ------------------------------------------------------------------------
Downloading: http://repo.maven.apache.org/maven2/org/apache/maven/plugins/maven-resources-plugin/2.5/maven-resources-plugin-2.5.pom
Downloaded: http://repo.maven.apache.org/maven2/org/apache/maven/plugins/maven-resources-plugin/2.5/maven-resources-plugin-2.5.pom (7 KB at 7.2 KB/sec)
Downloading: http://repo.maven.apache.org/maven2/org/apache/maven/plugins/maven-plugins/19/maven-plugins-19.pom
Downloaded: http://repo.maven.apache.org/maven2/org/apache/maven/plugins/maven-plugins/19/maven-plugins-19.pom (11 KB at 38.7 KB/sec)
Downloading: http://repo.maven.apache.org/maven2/org/apache/maven/maven-parent/19/maven-parent-19.pom
Downloaded: http://repo.maven.apache.org/maven2/org/apache/maven/maven-parent/19/maven-parent-19.pom (25 KB at 70.0 KB/sec)
Downloading: http://repo.maven.apache.org/maven2/org/apache/apache/9/apache-9.pom
Downloaded: http://repo.maven.apache.org/maven2/org/apache/apache/9/apache-9.pom (15 KB at 63.5 KB/sec)
Downloading: http://repo.maven.apache.org/maven2/org/apache/maven/plugins/maven-resources-plugin/2.5/maven-resources-plugin-2.5.jar
Downloaded: http://repo.maven.apache.org/maven2/org/apache/maven/plugins/maven-resources-plugin/2.5/maven-resources-plugin-2.5.jar (26 KB at 63.1 KB/sec)
Downloading: http://repo.maven.apache.org/maven2/org/apache/maven/plugins/maven-compiler-plugin/2.3.2/maven-compiler-plugin-2.3.2.pom
Downloaded: http://repo.maven.apache.org/maven2/org/apache/maven/plugins/maven-compiler-plugin/2.3.2/maven-compiler-plugin-2.3.2.pom (8 KB at 29.6 KB/sec)
Downloading: http://repo.maven.apache.org/maven2/org/apache/maven/plugins/maven-plugins/18/maven-plugins-18.pom
Downloaded: http://repo.maven.apache.org/maven2/org/apache/maven/plugins/maven-plugins/18/maven-plugins-18.pom (13 KB at 53.6 KB/sec)
Downloading: http://repo.maven.apache.org/maven2/org/apache/maven/maven-parent/16/maven-parent-16.pom
Downloaded: http://repo.maven.apache.org/maven2/org/apache/maven/maven-parent/16/maven-parent-16.pom (23 KB at 66.8 KB/sec)
Downloading: http://repo.maven.apache.org/maven2/org/apache/apache/7/apache-7.pom
Downloaded: http://repo.maven.apache.org/maven2/org/apache/apache/7/apache-7.pom (15 KB at 59.5 KB/sec)
所以,我想连接到Maven Central没有问题。
编辑2
请注意:
![enter image description here](https://istack.dev59.com/QONMP.webp)
- 项目flyout显示模块名称,后跟括号中的相应maven artifact Id。
- 在项目设置对话框中,只给出各自的maven artifact Id。
- 但在模块依赖项中,仅列出模块名称。
编辑3
这是最顶层的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>
这是与“共同模块”相关的翻译:
<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>
这里是核心模块的内容:
<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
问题终于解决了。删除了所有Intellij文件,重新导入。我猜测pom.xml文件的更改方式让IntelliJ产生了困惑。