Проблемы зависимости с Eclipse и мультимодульным проектом Maven - PullRequest
2 голосов
/ 23 ноября 2011

У меня есть многомодульный проект maven, состоящий из трех субмодулей: web , service и domain . Я использую m2e и мне удалось импортировать maven проекты в Eclipse.

Более того, сервис и домен находятся в пути сборки Java web , а domain - в проекте путь сборки Java .

Это очень странно, потому что отображаются ошибки компиляции, которые, кажется, указывают, что, например, service не видит domain . Однако, когда я нажимаю на класс по ошибке в затмении, я могу перейти к классу domain .

Кроме того, я могу добавить проект web к экземпляру сервера Tomcat, но проект web не содержит два других проекта.

Может кто-нибудь помочь, пожалуйста?

web 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

<?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>

домен 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>              

супер пом.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>

Ответы [ 2 ]

3 голосов
/ 23 ноября 2011

Определить домен и служебные модули внутри тега управления зависимостями в 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>

После добавления этих определений в супер-помпу, у вас также будет возможность удалить номера версий для этих зависимостей из модуля pom.

1 голос
/ 23 ноября 2011

Вы не должны работать с путями построения затмений.

Добавьте службу и домен в зависимости от pom.xml. Добавьте домен в pom.xml из вашего сервиса.

После правильной настройки зависимостей m2e правильно настроит пути сборки.

...