2017-03-03 214 views
0

我對maven不太熟悉,我對如何在maven中處理以下用例感到困惑。作爲模塊的Maven依賴關係

在maven上有一個開源框架。我希望能夠擴展這個框架。在擴展的同時,我也想測試擴展是否正確。所以,我想要一個也包含框架和測試應用程序的項目。

我嘗試了一些不起作用的東西。我創建了兩個模塊samplejsonextend Maven項目

  • 模塊1。 JsonPath(這是最初的開源框架)

  • Module2。 JSONPathTest(這是它使用
    原始框架應用程序)

samplejsonextend的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"> 
    <parent> 
     <artifactId>samplejsonextend</artifactId> 
     <groupId>com.samplejsonextend</groupId> 
     <version>1.0-SNAPSHOT</version> 
    </parent> 
    <modelVersion>4.0.0</modelVersion> 

    <groupId>com.samplejsonextend.JSONPathTest</groupId> 
    <artifactId>JSONPathTest</artifactId> 
    <version>1.0-SNAPSHOT</version> 

    <dependencies> 
     <dependency> 
      <groupId>com.jayway.jsonpath</groupId> 
      <artifactId>json-path</artifactId> 
      <version>2.2.0</version> 
     </dependency> 
    </dependencies> 
</project> 

模塊1(JSONPath)的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"> 
    <parent> 
     <artifactId>samplejsonextend</artifactId> 
     <groupId>com.samplejsonextend</groupId> 
     <version>1.0-SNAPSHOT</version> 
    </parent> 
    <modelVersion>4.0.0</modelVersion> 


    <groupId>com.jayway.jsonpath</groupId> 
    <artifactId>json-path</artifactId> 
    <version>2.2.0</version> 
</project> 

Module2(JSONPathTest)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"> 
    <parent> 
     <artifactId>samplejsonextend</artifactId> 
     <groupId>com.samplejsonextend</groupId> 
     <version>1.0-SNAPSHOT</version> 
    </parent> 
    <modelVersion>4.0.0</modelVersion> 

    <groupId>com.samplejsonextend.JSONPathTest</groupId> 
    <artifactId>JSONPathTest</artifactId> 
    <version>1.0-SNAPSHOT</version> 

    <dependencies> 
     <dependency> 
      <groupId>com.jayway.jsonpath</groupId> 
      <artifactId>json-path</artifactId> 
      <version>2.2.0</version> 
     </dependency> 
    </dependencies> 
</project> 

上述配置的問題是沒有爲module1下載代碼。這是達到這個目標的正確方法嗎?如果是,那麼我可以得到一些提示,說明它爲什麼不起作用?如果這不是正確的方式,那麼如何實現?

回答

0

你可以試試嗎?

samplejsonextend的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"> 

    <artifactId>samplejsonextend</artifactId> 
    <groupId>com.samplejsonextend</groupId> 
<version>1.0-SNAPSHOT</version> 

<dependencies> 
    <dependency> 
     <groupId>com.jayway.jsonpath</groupId> 
     <artifactId>json-path</artifactId> 
     <version>2.2.0</version> 
    </dependency> 
</dependencies> 


<modules> 
    <module>JSONPathTest</module> 
    <module>JSONPath</module> 
</modules> 

</project> 

模塊1(JSONPath)的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"> 
<parent> 
    <artifactId>samplejsonextend</artifactId> 
    <groupId>com.samplejsonextend</groupId> 
    <version>1.0-SNAPSHOT</version> 
</parent> 
<modelVersion>4.0.0</modelVersion> 

<groupId>samplejsonextend</groupId> 
<artifactId>JSONPath</artifactId> 
<version>1.0-SNAPSHOT</version> 
</project> 

模塊1(JSONPathTest)的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"> 
<parent> 
    <artifactId>samplejsonextend</artifactId> 
    <groupId>com.samplejsonextend</groupId> 
    <version>1.0-SNAPSHOT</version> 
</parent> 
<modelVersion>4.0.0</modelVersion> 

    <groupId>com.samplejsonextend</groupId> 
<artifactId>JSONPathTest</artifactId> 
<version>1.0-SNAPSHOT</version> 

<dependencies> 
    <dependency> 
    <groupId>com.samplejsonextend</groupId> 
     <artifactId>JSONPath</artifactId> 
     <version>1.0-SNAPSHOT</version> 
    </dependency> 
</dependencies> 
</project> 

隨着ARBO:

samplejsonextend

  • JSONPath

  • JSONPathTest

庫的代碼將在類路徑中,所以你可以把它擴大。

在你父母的情況下!

<?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>com.samplejsonextend</groupId> 
<artifactId>samplejsonextend</artifactId> 
<packaging>pom</packaging> 
<version>1.0-SNAPSHOT</version> 

<modules> 
    <module>jsonpath</module> 
    <module>JSONPathTest</module> 
</modules> 


</project> 
+0

感謝,但不工作,我已經推項目,在github上您的建議,它說,循環引用,在GitHub上的鏈接:https://github.com/noorbakerally/samplejsonextend – Noor

+0

更改POM父: (我會在帖子末尾編輯它) – CoDel

+0

。 – CoDel