8

我在将 Netbeans 创建的 maven 项目导入 IDEA 12 时遇到问题。在 pom 中编写的依赖项工件不起作用。它告诉我“import org.springframework.xxx;”上的“无法解析符号'springframework'”。当我运行它时,它说 org.springframework.xxx 不存在。这是pom文件

<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/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>cn.edu.seu.cose.jellyjolly</groupId>
<artifactId>jellyjolly-openshift-dist</artifactId>
<packaging>war</packaging>
<version>1.0</version>
<name>Jelly Jolly Openshift Distribution</name>
<organization>
    <name>College of Software Engineering, Southeast University</name>
    <url>http://cose.seu.edu.cn/</url>
</organization>
<repositories>
    <repository>
        <id>eap</id>
        <url>http://maven.repository.redhat.com/techpreview/all</url>
        <releases>
            <enabled>true</enabled>
        </releases>
        <snapshots>
            <enabled>true</enabled>
        </snapshots>
    </repository>
    <repository>
        <id>maven-restlet</id>
        <name>Public online Restlet repository</name>
        <url>http://maven.restlet.org</url>
    </repository>
</repositories>
<pluginRepositories>
    <pluginRepository>
        <id>eap</id>
        <url>http://maven.repository.redhat.com/techpreview/all</url>
        <releases>
            <enabled>true</enabled>
        </releases>
        <snapshots>
            <enabled>true</enabled>
        </snapshots>
    </pluginRepository>
</pluginRepositories>
<properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <maven.compiler.source>1.6</maven.compiler.source>
    <maven.compiler.target>1.6</maven.compiler.target>
    <netbeans.hint.license>gpl30</netbeans.hint.license>
</properties>
<dependencies>
    <dependency>
        <groupId>org.jboss.spec</groupId>
        <artifactId>jboss-javaee-6.0</artifactId>
        <version>3.0.0.Final-redhat-1</version>
        <type>pom</type>
        <scope>provided</scope>
    </dependency>
    <dependency>
        <groupId>javax.servlet</groupId>
        <artifactId>jstl</artifactId>
        <version>1.2</version>
    </dependency>
    <dependency>
        <groupId>taglibs</groupId>
        <artifactId>standard</artifactId>
        <version>1.1.2</version>
    </dependency>
    <dependency>
        <groupId>commons-dbcp</groupId>
        <artifactId>commons-dbcp</artifactId>
        <version>1.4</version>
        <type>jar</type>
    </dependency>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-context</artifactId>
        <version>3.1.3.RELEASE</version>
        <type>jar</type>
    </dependency>
    <dependency>
        <groupId>org.restlet.jee</groupId>
        <artifactId>org.restlet</artifactId>
        <version>2.0.0</version>
        <type>jar</type>
    </dependency>
    <dependency>
        <groupId>org.restlet.jee</groupId>
        <artifactId>org.restlet.ext.xml</artifactId>
        <version>2.0.0</version>
        <type>jar</type>
    </dependency>
    <dependency>
        <groupId>net.java.dev.rome</groupId>
        <artifactId>rome</artifactId>
        <version>1.0.0</version>
        <type>jar</type>
    </dependency>
    <dependency>
        <groupId>mysql</groupId>
        <artifactId>mysql-connector-java</artifactId>
        <version>5.1.21</version>
    </dependency>
    <dependency>
        <groupId>junit</groupId>
        <artifactId>junit</artifactId>
        <version>4.10</version>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>commons-lang</groupId>
        <artifactId>commons-lang</artifactId>
        <version>2.6</version>
    </dependency>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-webmvc</artifactId>
        <version>3.1.3.RELEASE</version>
    </dependency>
</dependencies>
<profiles>
    <profile>
        <!-- When built in OpenShift the 'openshift' profile will be used when
                    invoking mvn. -->
        <!-- Use this profile for any OpenShift specific customization your app
                    will need. -->
        <!-- By default that is to put the resulting archive into the 'webapps'
                    folder. -->
        <!-- http://maven.apache.org/guides/mini/guide-building-for-different-environments.html -->
        <id>openshift</id>
        <build>
            <finalName>jellyjolly</finalName>
            <plugins>
                <plugin>
                    <artifactId>maven-war-plugin</artifactId>
                    <version>2.1.1</version>
                    <configuration>
                        <outputDirectory>webapps</outputDirectory>
                        <warName>ROOT</warName>
                    </configuration>
                </plugin>
            </plugins>
        </build>
    </profile>
</profiles>

4

4 回答 4

8

pom.xml文件在您的项目中可用时,您可以通过运行以下命令生成 IntelliJ idea 项目所需的文件:

mvn idea:idea

Check out more options and details here: http://maven.apache.org/plugins/maven-idea-plugin/usage.html

于 2014-07-09T03:41:04.070 回答
7

如果项目在命令行 ( mvn clean install) 上运行,机会就像 100% 它也将在 IntelliJ 12 中运行 :-)

在文件 -> 项目导入 -> 从外部 Maven 模型之后,您应该会看到模块。

我要在 IntelliJ 设置中检查的是 maven 主目录(文件 -> 设置 -> Maven)的位置以及它读取(或不读取)的 settings.xml 文件。

IDE 中的mvn install内容不应与命令行上发生的内容不同。如果是这样,它将比较mvn help:effective-settings命令行和 IntelliJ(也可能来自 Netbeans)的输出。

如果您只是没有看到所有模块,请右键单击 parent-pom.xml 并选择 maven -> reimport。要解决依赖关系,您必须执行一次安装。它不会在所有情况下自动解决依赖关系。

于 2012-12-18T09:38:09.450 回答
0

有同样的问题,您可以简单地右键单击代码并转到 Maven->重新导入,它应该可以解决问题

于 2013-06-27T13:13:55.007 回答
0

我曾经使用mvn -U idea:idea下载的依赖项生成 IntelliJ 特定文件。

于 2014-07-06T00:43:12.703 回答