2017-03-03 210 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