2015-10-20 51 views
0

我有第三方JAR,我通過mvn install:install-file命令創建了一個工件。工件被添加到項目中,並且模塊的pom.xml和導入得很好。IntelliJ無法使用Maven解析符號第三方jar

用第三方JAR中的符號創建一個Java類不幸的是仍然沒有解決。紅燈燈泡顯示,沒有我期望的「導入類」選項。

我試過使緩存失效|重新啓動但無濟於事。

任何想法?

編輯如果我改爲安裝已編譯的JAR,則符號已解析。這是爲什麼?

編輯2添加顯示內部共享工件的pom.xml。

<?xml version="1.0" encoding="UTF-8"?> 
<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> 
    <packaging>pom</packaging> 
    <name>Sandbox</name> 
    <parent> 
     <groupId>com.x.y</groupId> 
     <artifactId>third-party-parent</artifactId> 
     <version>1.0-SNAPSHOT</version> 
    </parent> 

    <groupId>com.x.y.z</groupId> 
    <artifactId>thirdparty-z</artifactId> 
    <version>1.0-SNAPSHOT</version> 

    <dependencies> 
     <dependency> 
      <groupId>com.x.y.thirdparty</groupId> 
      <artifactId>thirdparty-sources</artifactId> 
      <version>1.0</version> 
     </dependency> 

     <dependency> 
      <groupId>com.x.y.thirdparty</groupId> 
      <artifactId>thirdparty-compiled</artifactId> 
      <version>1.0</version> 
     </dependency> 
    </dependencies> 

</project> 
+1

是的groupId,artifactId和version是否正確? (我的意思是它們與安裝依賴項時使用的是相同的嗎?)您是否更新過IntelliJ中的Maven項目? – Tunaki

+0

也許「Maven - 下載源代碼」會有所幫助,但不知道 – Klever

+0

的POM設置是否正常,否則它不會首先導入到IntelliJ中,對嗎?我可以導航到圖書館並查看來源。如果我嘗試直接引用一個類,如com.x.y. 它不起作用。 IntelliJ能夠自動完成com.x.y.但它不會在下拉列表中顯示,儘管它存在於源代碼jar中! – Rabiees

回答

0

這個Maven項目文件pom.xml包含修復和一些小技巧/什麼改變,爲什麼它已被更改的提示。

<?xml version="1.0" encoding="UTF-8"?> 
<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> 

    <!-- Parent POM best at the top --> 
    <!-- WANRING: Here you import the parent of 3th party. This is (almost) never correct!!! --> 
    <!-- For a simple project, which only exists of 1 set of classes and unit tests, you do --> 
    <!-- not need a parent POM. Only for multi module Maven project, you will have a parent --> 
    <!-- POM. Or for organisation wide configuration, of repositories, Maven plugin   --> 
    <!-- configuration, and so. When starting with a small project, leave out the parent POM --> 
    <!-- reference.                   --> 
    <parent> 
     <groupId>com.x.y</groupId> 
     <artifactId>third-party-parent</artifactId> 
     <version>1.0-SNAPSHOT</version> 
    </parent> 

    <!-- Better keep all project stuff together --> 
    <groupId>com.x.y.z</groupId> 
    <artifactId>your-project-name</artifactId> 
    <packaging>pom</packaging> 
    <name>My Little Sandbox</name> 
    <version>1.0.0-SNAPSHOT</version> 

    <dependencies> 
     <!-- Here only a reference to the compiled jar is required!!!     --> 
     <!-- If a source jar is available, it will get pulled in automatically!!!  --> 
     <!-- As this is done by (naming) convention of all jars, in a Maven repository --> 
     <dependency> 
      <groupId>com.x.y.thirdparty</groupId> 
      <artifactId>thirdparty</artifactId> 
      <version>1.0</version> 
     </dependency> 
    </dependencies> 

</project> 

備註:其中一個新項目延伸屆黨父POM,是當新的項目是一些實物屆党項目的extention /插件的罕見病例。然後,它可以使用相同的Maven Plug-in版本,依賴關係等等,就像第三方使用的一樣。這使得最新的Extention/Plug-in與第三方軟件的其他部分配合良好。

具體的例子來嘗試

<?xml version="1.0" encoding="UTF-8"?> 
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>org.organisation.play-ground</groupId> 
    <artifactId>my-little-sandbox</artifactId> 
    <packaging>pom</packaging> 
    <name>My Little Sandbox</name> 
    <version>1.0.0-SNAPSHOT</version> 

    <dependencies> 
     <!-- A dependency reuired for each phase --> 
     <dependency> 
      <groupId>org.slf4j</groupId> 
      <artifactId>slf4j-api</artifactId> 
      <version>1.7.12</version> 
     </dependency> 

     <!-- A dependency only needed during runtime phase --> 
     <dependency> 
      <groupId>ch.qos.logback</groupId> 
      <artifactId>logback-classic</artifactId> 
      <version>1.1.3</version> 
      <scope>runtime</scope> 
     </dependency> 

     <!-- A dependency only needed during compile and test phase --> 
     <dependency> 
      <groupId>org.testng</groupId> 
      <artifactId>testng</artifactId> 
      <version>6.9.8</version> 
      <scope>test</scope> 
     </dependency> 
    </dependencies> 
</project> 
+0

@hajder,這是否讓你更進一步? – Verhagen

+0

對不起,錯過了這一點。謝謝! – Rabiees

相關問題