2014-03-28 231 views
0

我將模塊從現有的maven項目中分離出來。所以創建了一個核心部分和一個包含所有mybaties接口和配置文件的模塊。將maven項目轉換爲多模塊

所以我創造了我的主要的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"> 
<modelVersion>4.0.0</modelVersion> 
<groupId>com.mycom</groupId> 
<artifactId>app</artifactId> 
<version>1.0-SNAPSHOT</version> 
<properties> 
    <spring.version>3.2.0.RELEASE</spring.version> 
</properties> 
<packaging>pom</packaging> 
<name>app</name> 
<build> 
    <plugins> 
     <plugin> 
      <groupId>org.apache.maven.plugins</groupId> 
      <artifactId>maven-compiler-plugin</artifactId> 
      <version>2.3.2</version> 
      <configuration> 
       <source>1.7</source> 
       <target>1.7</target> 
      </configuration> 
     </plugin> 
    </plugins> 
</build> 
<modules> 
    <module>core</module> 
    <module>app-mybatis</module> 
</modules> 

我的核心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"> 
<modelVersion>4.0.0</modelVersion> 
    <parent> 
    <artifactId>app</artifactId> 
    <groupId>com.mycom</groupId> 
    <version>1.0-SNAPSHOT</version> 
</parent> 
<groupId>com.mycom</groupId> 
<artifactId>core</artifactId> 
<version>1.0-SNAPSHOT</version> 
<packaging>war</packaging> 
<name>core</name> 
<description>my app</description> 

<properties> 
    <spring.version>3.1.1.RELEASE</spring.version> 
</properties> 


<dependencies> 
    <dependency> 
     <groupId>org.springframework.security</groupId> 
     <artifactId>spring-security-web</artifactId> 
     <version>${spring.version}</version> 
    </dependency> 
    <dependency> 
     <groupId>org.springframework.security</groupId> 
     <artifactId>spring-security-config</artifactId> 
     <version>${spring.version}</version> 
    </dependency> 

    <dependency> 
     <groupId>org.springframework</groupId> 
     <artifactId>spring-context</artifactId> 
     <version>${spring.version}</version> 
    </dependency> 


    <dependency> 
     <groupId>org.springframework</groupId> 
     <artifactId>spring-web</artifactId> 
     <version>${spring.version}</version> 
    </dependency> 


    <dependency> 
     <groupId>org.springframework</groupId> 
     <artifactId>spring-webmvc</artifactId> 
     <version>${spring.version}</version> 
    </dependency> 


    <dependency> 
     <groupId>org.springframework</groupId> 
     <artifactId>spring-core</artifactId> 
     <version>${spring.version}</version> 
    </dependency> 


    <dependency> 
     <groupId>org.springframework</groupId> 
     <artifactId>spring-test</artifactId> 
     <version>${spring.version}</version> 
     <scope>test</scope> 
    </dependency> 

    <dependency> 
     <groupId>org.springframework</groupId> 
     <artifactId>spring-support</artifactId> 
     <version>2.0.8</version> 
    </dependency> 


    <dependency> 
     <groupId>javax.servlet</groupId> 
     <artifactId>servlet-api</artifactId> 
     <version>2.5</version> 
    </dependency> 

    <dependency> 
     <groupId>javax.servlet.jsp</groupId> 
     <artifactId>jsp-api</artifactId> 
     <version>2.1</version> 
     <scope>provided</scope> 
    </dependency> 


    <dependency> 
     <groupId>junit</groupId> 
     <artifactId>junit</artifactId> 
     <version>4.8.2</version> 
     <scope>test</scope> 
    </dependency> 

    <dependency> 
     <groupId>org.codehaus.jackson</groupId> 
     <artifactId>jackson-core-asl</artifactId> 
     <version>1.9.13</version> 
    </dependency> 

    <dependency> 
     <groupId>org.codehaus.jackson</groupId> 
     <artifactId>jackson-mapper-asl</artifactId> 
     <version>1.9.13</version> 
    </dependency> 
    <dependency> 
     <groupId>rome</groupId> 
     <artifactId>rome</artifactId> 
     <version>1.0</version> 
    </dependency> 



    <!--Joda time --> 
    <dependency> 
     <groupId>joda-time</groupId> 
     <artifactId>joda-time</artifactId> 
     <version>2.1</version> 
    </dependency> 

    <dependency> 
     <groupId>joda-time</groupId> 
     <artifactId>joda-time-jsptags</artifactId> 
     <version>1.1.1</version> 
    </dependency> 

    <!-- mysql connector --> 

    <dependency> 
     <groupId>mysql</groupId> 
     <artifactId>mysql-connector-java</artifactId> 
     <version>5.1.24</version> 
    </dependency> 

    <!--log4j --> 
    <dependency> 
     <groupId>log4j</groupId> 
     <artifactId>log4j</artifactId> 
     <version>1.2.15</version> 
     <exclusions> 
      <exclusion> 
       <groupId>com.sun.jmx</groupId> 
       <artifactId>jmxri</artifactId> 
      </exclusion> 
      <exclusion> 
       <groupId>com.sun.jdmk</groupId> 
       <artifactId>jmxtools</artifactId> 
      </exclusion> 
      <exclusion> 
       <groupId>javax.jms</groupId> 
       <artifactId>jms</artifactId> 
      </exclusion> 
     </exclusions> 
    </dependency> 

    <!--apache common --> 
    <dependency> 
     <groupId>org.apache.httpcomponents</groupId> 
     <artifactId>httpclient</artifactId> 
     <version>4.0.1</version> 
    </dependency> 

    <dependency> 
     <groupId>commons-lang</groupId> 
     <artifactId>commons-lang</artifactId> 
     <version>2.4</version> 
    </dependency> 
    <dependency> 
     <groupId>commons-configuration</groupId> 
     <artifactId>commons-configuration</artifactId> 
     <version>1.6</version> 
    </dependency> 
    <dependency> 
     <groupId>commons-io</groupId> 
     <artifactId>commons-io</artifactId> 
     <version>2.4</version> 
    </dependency> 


</dependencies> 

<pluginRepositories> 
    <pluginRepository> 
     <id>Codehaus</id> 
     <url>http://repository.codehaus.org/</url> 
     <snapshots> 
      <enabled>true</enabled> 
     </snapshots> 
     <releases> 
      <enabled>true</enabled> 
     </releases> 
    </pluginRepository> 
</pluginRepositories> 

<build> 
    <finalName>mycom.myproject.net</finalName> 
    <plugins> 
     <plugin> 
      <groupId>org.apache.tomcat.maven</groupId> 
      <artifactId>tomcat7-maven-plugin</artifactId> 
      <version>2.2</version>    
      <configuration> 
       <url>http://127.0.0.1:8080/manager/text</url> 
       <server>TomcatServer</server> 
       <path>/app</path> 
      </configuration> 
     </plugin> 
     <plugin> 
      <artifactId>maven-compiler-plugin</artifactId> 
      <version>2.3.2</version> 
      <configuration> 
       <source>1.7</source> 
       <target>1.7</target> 
      </configuration> 
     </plugin> 
    </plugins> 
</build> 

和我mybaties模塊的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>app</artifactId> 
    <groupId>com.mycom</groupId> 
    <version>1.0-SNAPSHOT</version> 
</parent> 
<modelVersion>4.0.0</modelVersion> 

<artifactId>app-mybatis</artifactId> 
<packaging>jar</packaging> 

<name>app-mybatis</name> 

<dependencies> 

    <!-- mybaties --> 
    <dependency> 
     <groupId>org.mybatis</groupId> 
     <artifactId>mybatis</artifactId> 
     <version>3.1.1</version> 
    </dependency> 

    <dependency> 
     <groupId>org.mybatis</groupId> 
     <artifactId>mybatis-spring</artifactId> 
     <version>1.1.1</version> 
    </dependency> 

    <dependency> 
     <groupId>org.mybatis.generator</groupId> 
     <artifactId>mybatis-generator-core</artifactId> 
     <version>1.3.0</version> 
    </dependency> 


</dependencies> 

但是當我建立的MyBatis模塊它給了我一個錯誤

package com.mycom.myproject.service.impl.bean does not exist 

這已經是我的有核心模塊中。有沒有什麼我在poms的映射中失蹤了。

如果您需要更多詳細信息,請讓我知道。

回答

2

mybatis模塊中的父代指向app,因此它不會從core繼承依賴關係。如果你有共同的依賴,那麼你可以創建一個多模塊base,並在主POM添加到模塊的列表:

<modules> 
    <module>base</module> 
    <module>core</module> 
    <module>app-mybatis</module> 
</modules> 

base 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/xsd/maven-4.0.0.xsd"> 
    <modelVersion>4.0.0</modelVersion> 
    <parent> 
     <artifactId>app</artifactId> 
     <groupId>com.mycom</groupId> 
     <version>1.0-SNAPSHOT</version> 
    </parent> 

    <groupId>com.mycom</groupId> 
    <artifactId>base</artifactId> 
    <version>1.0-SNAPSHOT</version> 
    <packaging>jar</packaging> 
    <name>core</name> 
    <description>my app</description> 

    <properties> 
     <spring.version>3.1.1.RELEASE</spring.version> 
    </properties> 


    <dependencies> 
     <dependency> 
      <groupId>org.springframework.security</groupId> 
      <artifactId>spring-security-web</artifactId> 
      <version>${spring.version}</version> 
     </dependency> 
     <dependency> 
      <groupId>org.springframework.security</groupId> 
      <artifactId>spring-security-config</artifactId> 
      <version>${spring.version}</version> 
     </dependency> 
     <!-- so on --> 
    <depedencies> 
</project> 

現在,請將其作爲coreapp-mybatis的父級。我想這應該工作。

+0

嗨@Rohit感謝您的快速響應,但核心是一個模塊,而不是父母這裏的應用程序是父母。我應該把標記放在覈心pom中,我這樣做了,但這也不會造成任何不同。仍然我得到相同的錯誤 – user965884

+0

@ user965884如果core不是'app'的父親,那麼您需要在'app'中添加依賴關係。它將如何從'core'繼承依賴關係?或者爲他們兩人制定一個共同的基本團隊,並在那裏定義共同的依賴關係。並使'核心'和'應用程序'的父母。 –

+0

我也試過你的建議,它給了我錯誤[錯誤]構建無法讀取1個項目 - > [Help 1] – user965884