2012-12-18 109 views
6

我有問題將NetBeans創建的Maven項目導入到IDEA 12中。在POM中編寫的依賴項工件不起作用。它告訴我「無法解析」import org.springframework.xxx;「上的符號'springframework'」。「當我運行它時,它說org.springframework.xxx不存在。 這裏是POM文件如何在Intellij IDEA中設置Maven項目12

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

+0

應該是直接的,獨立於Netbeans。也許檢查一般的Maven設置(文件 - >設置-Maven)並嘗試重新導入項目(右鍵單擊項目 - > Maven - >重新導入)。 也檢查您的pom.xml中的一些「錯誤」。也許有一個netbeans被忽略的「錯誤」,但IDEA沒有。 – Adrian

+0

其實在pom文件中可能有錯誤。提示是「無法獲取依賴項信息:無法讀取工件的元數據文件'javax.activation:activation:jar':無法解析版本'[0.9.1.2,0.9.1.2-redhat-1]'依賴項'c3p0:c3p0:jar':範圍藐視版本排序:[0.9.1.2,0.9.1.2-redhat-1] for project unknown:jboos-dependency-management-build ... from指定的遠程存儲庫:central,eap, ...依賴xxx的路徑:xxx:war ...「。這是否意味着某些工件無法從列出的存儲庫中檢索? – rAy

+0

非常奇怪的行爲。請重新檢查IDEA使用的Mavne版本,也許你可以試着用你的外部版本覆蓋內部版本。 – Adrian

回答

6

如果該項目在命令行(mvn clean install)的機會就像是100%它會在12的IntelliJ工作太:-)

文件後上運行 - >項目導入 - >從外部Maven模型你應該看到模塊。

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

IDE中的mvn install應該與命令行中發生的不同。如果是這樣,它會比較從命令行和IntelliJ(也可能來自Netbeans)的輸出mvn help:effective-settings

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

+0

儘管在pom文件上有一個錯誤提示,說「無法獲取依賴項信息:無法讀取工件的元數據文件'javax.activation:activation:jar':Unable to parse version'[0.9.1.2,0.9 .1.2-redhat-1]'fo dependency'c3p0:c3p0:jar'...依賴xxx的路徑:xxx:war ...「,mvn clean安裝過程成功完成,退出代碼爲0.我想知道artifact是從遠程mvn倉庫下載的。似乎在這些存儲庫中找不到工件。 – rAy

+0

以及他們可能會被打破。所以我會刪除本地存儲庫並重試。還請使用help:effective-pom和help:有效設置來檢查maven central是否在您的存儲庫列表中。 – wemu

+0

謝謝你的幫助。正如你所說,來自本地資源庫的工件被打破了。 Spring框架和其他框架的依賴性得到了解決,但是沒有用於中央倉庫的工件的依賴性仍然沒有解決。非中央倉庫不僅應該在pom.xml中聲明,還要在settings.xml中聲明? – rAy

0

更新版本神器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> 
0

有同樣的問題, 可以只需右鍵單擊代碼並轉到Maven-> Reimport,它應該可以做到這一點

0

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

相關問題