簡體   English   中英

如何在Intellij IDEA 12中設置maven項目

[英]How to setup a maven project in Intellij IDEA 12

我在將由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>

如果項目在命令行上運行( mvn clean install ),那么它在100%的可能性也會在IntelliJ 12中運行:-)

在文件 - >項目導入 - >從外部Maven模型后,您應該看到模塊。

我在IntelliJ設置中檢查的是maven主目錄的位置(文件 - >設置 - > Maven)以及它讀取(或不讀取)的settings.xml文件。

IDE中的mvn install不應與命令行中的mvn install有所不同。 如果是這樣,它會比較mvn help:effective-settings命令行的mvn help:effective-settings輸出和IntelliJ(也許還有Netbeans)。

如果您沒有看到所有模塊,請右鍵單擊parent-pom.xml並選擇maven - > reimport。 要解決依賴關系,您必須執行一次安裝。 它並不會在所有情況下自動解決依賴關系。

pom.xml文件在項目中可用時,您可以通過運行以下命令生成IntelliJ idea項目所需的文件:

mvn idea:idea

在此處查看更多選項和詳細信息: http//maven.apache.org/plugins/maven-idea-plugin/usage.html

有同樣的問題,你可以簡單地右鍵+點擊代碼然后去Maven-> Reimport它應該做的伎倆

我使用了mvn -U idea:idea來生成具有下載依賴項的IntelliJ特定文件。

將工件版本org.jboss.spec:jboss-javaee-6.0更新到3.0.1.Final-redhat-1

<dependency>
    <groupId>org.jboss.spec</groupId>
    <artifactId>jboss-javaee-6.0</artifactId>
    <version>3.0.1.Final-redhat-1</version>
    <type>pom</type>
    <scope>provided</scope>     
</dependency>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM