简体   繁体   English

Eclipse和Maven多模块项目的依赖关系问题

[英]Dependency issues with Eclipse and a maven multi module project

I have a multi-module maven project made up of three sub-modules: web , service and domain . 我有一个由三个子模块组成的多模块Maven项目: webservicedomain I use m2e and have managed to import the maven projects into Eclipse. 我使用m2e并设法将maven项目导入Eclipse。

What's more, the service and domain projects are in the web 's java build path and the domain project is in the service 's java build path. 此外, 服务项目在Web的Java构建路径中,而项目在服务的Java构建路径中。

It is very strange because compilation errors are displayed which seem to indicate that for instance service does not see domain . 这很奇怪,因为显示了编译错误,似乎表明例如service看不到domain However when I click on a class in error in eclipse, I can navigate to the domain class. 但是,当我单击Eclipse中错误的类时,我可以导航到类。

Furthermore, I can add the web project to the Tomcat server instance but the web project does not contain the other two projects. 此外,我可以将Web项目添加到Tomcat服务器实例,但是该Web项目不包含其他两个项目。

Can anyone please help? 谁能帮忙吗?

web pom.xml: 网络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/maven-v4_0_0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <groupId>com.bignibou</groupId>
        <artifactId>bignibou</artifactId>
        <version>1.0-SNAPSHOT</version>
    </parent>
    <groupId>com.bignibou</groupId>
    <artifactId>bignibou-web</artifactId>
    <packaging>war</packaging>
    <version>1.0-SNAPSHOT</version>
    <name>bignibou-web</name>

    <build>
        <resources>
            <resource>
                <directory>src/main/java</directory>
                <includes>
                    <include>**/*.tml</include>
                    <include>**/*.properties</include>
                </includes>
            </resource>
            <resource>
                <directory>src/main/resources</directory>
                <includes>
                    <include>**/*.xml</include>
                    <include>**/*.properties</include>
                </includes>
            </resource>
        </resources>

        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-war-plugin</artifactId>
                <!--
                <version>2.0.2</version>
                <configuration>
                    <webResources>
                        <resource>
                            <directory>${basedir}/WebContent</directory>
                        </resource>
                    </webResources>
                    <warSourceDirectory>WebContent</warSourceDirectory>
                    <warSourceExcludes>WebContent/WEB-INF/lib/*.jar</warSourceExcludes>
                    <archiveClasses>false</archiveClasses>
                </configuration>
                -->
            </plugin>
        </plugins>
    </build>

    <dependencies>
        <dependency>
            <groupId>com.bignibou</groupId>
            <artifactId>bignibou-domain</artifactId>
            <version>1.0-SNAPSHOT</version>
        </dependency>
        <dependency>
            <groupId>com.bignibou</groupId>
            <artifactId>bignibou-service</artifactId>
            <version>1.0-SNAPSHOT</version>
        </dependency>
        <dependency>
            <groupId>org.apache.tapestry</groupId>
            <artifactId>tapestry-core</artifactId>
            <version>5.2.6</version>
        </dependency>
        <dependency>
            <groupId>org.apache.tapestry</groupId>
            <artifactId>tapestry-beanvalidator</artifactId>
            <version>5.2.6</version>
        </dependency>
        <dependency>
            <groupId>org.apache.tapestry</groupId>
            <artifactId>tapestry-spring</artifactId>
            <version>5.2.6</version>
        </dependency>
        <dependency>
            <groupId>com.google.code.gson</groupId>
            <artifactId>gson</artifactId>
            <version>1.7.1</version>
        </dependency>
        <dependency>
            <groupId>org.apache.tapestry</groupId>
            <artifactId>tapestry-test</artifactId>
            <version>5.2.6</version>
            <scope>test</scope>
            <exclusions>
                <exclusion>
                    <artifactId>testng</artifactId>
                    <groupId>org.testng</groupId>
                </exclusion>
            </exclusions>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-test</artifactId>
            <version>3.0.5.RELEASE</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.easymock</groupId>
            <artifactId>easymock</artifactId>
            <version>2.5.2</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>javax</groupId>
            <artifactId>javaee-web-api</artifactId>
            <version>6.0</version>
            <scope>provided</scope>
        </dependency>
        <!-- <dependency> <groupId>com.formos.tapestry</groupId> <artifactId>tapestry-testify</artifactId> 
            <version>1.0.2</version> <scope>test</scope> </dependency> <dependency> <groupId>com.formos.tapestry</groupId> 
            <artifactId>tapestry-xpath</artifactId> <version>1.0.1</version> <scope>test</scope> 
            </dependency> -->
    </dependencies>
</project>

service pom.xml 服务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>
        <groupId>com.bignibou</groupId>
        <artifactId>bignibou</artifactId>
        <version>1.0-SNAPSHOT</version>
    </parent>
    <groupId>com.bignibou</groupId>
    <artifactId>bignibou-service</artifactId>
    <version>1.0-SNAPSHOT</version>
    <name>bignibou-service</name>

    <!-- Shared version number properties -->
    <properties>
        <org.springframework.version>3.0.5.RELEASE</org.springframework.version>
    </properties>

    <dependencies>
        <!--
            Core utilities used by other modules.
            Define this if you use Spring Utility APIs (org.springframework.core.*/org.springframework.util.*)
        -->
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-core</artifactId>
            <version>${org.springframework.version}</version>
        </dependency>

        <!--
            Expression Language (depends on spring-core)
            Define this if you use Spring Expression APIs (org.springframework.expression.*)
        -->
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-expression</artifactId>
            <version>${org.springframework.version}</version>
        </dependency>

        <!--
            Bean Factory and JavaBeans utilities (depends on spring-core)
            Define this if you use Spring Bean APIs (org.springframework.beans.*)
        -->
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-beans</artifactId>
            <version>${org.springframework.version}</version>
        </dependency>

        <!--
            Aspect Oriented Programming (AOP) Framework (depends on spring-core, spring-beans)
            Define this if you use Spring AOP APIs (org.springframework.aop.*)
        -->
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-aop</artifactId>
            <version>${org.springframework.version}</version>
        </dependency>

        <!--
            Application Context (depends on spring-core, spring-expression, spring-aop, spring-beans)
            This is the central artifact for Spring's Dependency Injection Container and is generally always defined
        -->
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-context</artifactId>
            <version>${org.springframework.version}</version>
        </dependency>

        <!--
            Various Application Context utilities, including EhCache, JavaMail, Quartz, and Freemarker integration
            Define this if you need any of these integrations
        -->
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-context-support</artifactId>
            <version>${org.springframework.version}</version>
        </dependency>

        <!--
            Transaction Management Abstraction (depends on spring-core, spring-beans, spring-aop, spring-context)
            Define this if you use Spring Transactions or DAO Exception Hierarchy
            (org.springframework.transaction.*/org.springframework.dao.*)
        -->
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-tx</artifactId>
            <version>${org.springframework.version}</version>
        </dependency>

        <!--
            JDBC Data Access Library (depends on spring-core, spring-beans, spring-context, spring-tx)
            Define this if you use Spring's JdbcTemplate API (org.springframework.jdbc.*)
        -->
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-jdbc</artifactId>
            <version>${org.springframework.version}</version>
        </dependency>

        <!--
            Object-to-Relation-Mapping (ORM) integration with Hibernate, JPA, and iBatis.
            (depends on spring-core, spring-beans, spring-context, spring-tx)
            Define this if you need ORM (org.springframework.orm.*)
        -->
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-orm</artifactId>
            <version>${org.springframework.version}</version>
        </dependency>

        <!--
            Object-to-XML Mapping (OXM) abstraction and integration with JAXB, JiBX, Castor, XStream, and XML Beans.
            (depends on spring-core, spring-beans, spring-context)
            Define this if you need OXM (org.springframework.oxm.*)
        -->
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-oxm</artifactId>
            <version>${org.springframework.version}</version>
        </dependency>

        <!--
            Web application development utilities applicable to both Servlet and Portlet Environments
            (depends on spring-core, spring-beans, spring-context)
            Define this if you use Spring MVC, or wish to use Struts, JSF, or another web framework with Spring (org.springframework.web.*)
        -->
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-web</artifactId>
            <version>${org.springframework.version}</version>
        </dependency>

        <!--
            Support for testing Spring applications with tools such as JUnit and TestNG
            This artifact is generally always defined with a 'test' scope for the integration testing framework and unit testing stubs
        -->
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-test</artifactId>
            <version>${org.springframework.version}</version>
            <scope>test</scope>
        </dependency>

        <dependency>
            <groupId>commons-dbcp</groupId>
            <artifactId>commons-dbcp</artifactId>
            <version>1.3</version>
        </dependency>

        <dependency>
            <groupId>com.bignibou</groupId>
            <artifactId>bignibou-domain</artifactId>
            <version>1.0-SNAPSHOT</version>
        </dependency>
        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <version>5.1.6</version>
        </dependency>
        <dependency>
            <groupId>commons-collections</groupId>
            <artifactId>commons-collections</artifactId>
            <version>3.1</version>
        </dependency>
    </dependencies>
    <build>
        <resources>
            <resource>
                <directory>src/main/resources</directory>
                <includes>
                    <include>**/*.xml</include>
                    <include>**/*.properties</include>
                </includes>
            </resource>
        </resources>
    </build>

</project>

domain pom.xlm 域pom.xlm

<?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>
        <groupId>com.bignibou</groupId>
        <artifactId>bignibou</artifactId>
        <version>1.0-SNAPSHOT</version>
    </parent>
    <groupId>com.bignibou</groupId>
    <artifactId>bignibou-domain</artifactId>
    <version>1.0-SNAPSHOT</version>
    <name>bignibou-domain</name>

    <dependencies>
        <dependency>
            <groupId>javax.validation</groupId>
            <artifactId>validation-api</artifactId>
            <version>1.0.0.GA</version>
        </dependency>
        <dependency>
            <groupId>javax.inject</groupId>
            <artifactId>javax.inject</artifactId>
            <version>1</version>
        </dependency>

        <dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-validator</artifactId>
            <version>4.2.0.Final</version>
        </dependency>
         <dependency>
            <groupId>com.google.code.gson</groupId>
            <artifactId>gson</artifactId>
            <version>1.7.1</version>
        </dependency>
        <!--
        <dependency>
            <groupId>org.hibernate.javax.persistence</groupId>
            <artifactId>hibernate-jpa-2.0-api</artifactId>
            <version>1.0.0.Final</version>
        </dependency>
        <dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-entitymanager</artifactId>
            <version>3.5.3-Final</version>
        </dependency>
        -->
        <dependency>
            <groupId>org.eclipse.persistence</groupId>
            <artifactId>org.eclipse.persistence.jpa</artifactId>
            <version>2.0.2</version>
        </dependency>
        <dependency>
            <groupId>org.eclipse.persistence</groupId>
            <artifactId>javax.persistence</artifactId>
            <version>2.0.0</version>
        </dependency>
    </dependencies>
    <build>
        <resources>
            <resource>
                <directory>src/main/resources</directory>
                <includes>
                    <include>**/*.xml</include>
                    <include>**/*.properties</include>
                </includes>
            </resource>
        </resources>
    </build>
    <repositories>
        <repository>
            <id>eclipselink</id>
            <url>http://www.eclipse.org/downloads/download.php?r=1&amp;nf=1&amp;file=/rt/eclipselink/maven.repo/</url>
        </repository>
    </repositories>
</project>              

super pom.xlm: 超级pom.xlm:

<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>com.bignibou</groupId>
    <artifactId>bignibou</artifactId>
    <packaging>pom</packaging>
    <version>1.0-SNAPSHOT</version>
    <name>bignibou super pom</name>
    <modules>
        <module>domain</module>
        <module>service</module>
        <module>web</module>
    </modules>
    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <configuration>
                    <source>1.6</source>
                    <target>1.6</target>
                </configuration>
            </plugin>
        </plugins>
    </build>
    <dependencies>
        <dependency>
            <groupId>log4j</groupId>
            <artifactId>log4j</artifactId>
            <version>1.2.16</version>
        </dependency>
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-api</artifactId>
            <version>1.5.8</version>
        </dependency>
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-simple</artifactId>
            <version>1.5.8</version>
        </dependency>
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-log4j12</artifactId>
            <version>1.6.3</version>
        </dependency>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.8.2</version>
            <scope>test</scope>
        </dependency>
    </dependencies>
</project>

Define domain and service modules inside the dependency management tag in super pom. 在super pom的依赖管理标签中定义域和服务模块。 So basically add following definition inside super pom: 因此,基本上在super pom中添加以下定义:

     <dependencyManagement>
        <dependencies>
           <dependency>
              <groupId>com.bignibou</groupId>
              <artifactId>bignibou-domain</artifactId>
              <version>1.0-SNAPSHOT</version>
           </dependency>
           <dependency>
              <groupId>com.bignibou</groupId>
              <artifactId>bignibou-service</artifactId>
              <version>1.0-SNAPSHOT</version>
           </dependency>
        <dependencies>
     </dependencyManagement>

After adding these definitions to the super pom, you will also have the chance to remove version numbers for these dependencies from module pom's. 将这些定义添加到超级pom之后,您还将有机会从pom模块的这些依赖项中删除版本号。

You shouldn't work with eclipses build paths. 您不应该使用Eclipse构建路径。

Add the service and domain to the web pom.xml dependencies. 将服务和域添加到Web pom.xml依赖项。 Add the domain to the pom.xml from your service. 将域从服务添加到pom.xml。

After you set up the dependencies correctly m2e will configure the build paths correctly for you. 正确设置依赖关系后,m2e将为您正确配置构建路径。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM