Проблемы с зависимостями в Eclipse и многомодульном проекте maven

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

Более того, проекты service и domain находятся в пути сборки java web, а проект domain в пути сборки java сервиса.

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

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

Кто-нибудь может помочь?

веб-помп.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>

служба 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>

person balteo    schedule 22.11.2011    source источник


Ответы (2)


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

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

person melihcelik    schedule 22.11.2011
comment
Мелихелик: Спасибо. Я сделал это. Нужно ли мне впоследствии повторно импортировать проект maven в eclipse? - person balteo; 23.11.2011
comment
Да, повторный импорт также может быть необходим. Я только что понял, что при попытке исправить отступ я удалил закрывающий тег для тега dependencies, сейчас исправил. И я также добавил дополнительную информацию. - person melihcelik; 23.11.2011
comment
теперь это намного лучше, потому что я вижу войны доменов и служб на сервере Tomcat. Однако консоль tomcat, похоже, не указывает, что она развертывает приложение: я не получаю абсолютно ничего, связанного с моим приложением на консоли. Действительно очень странно... - person balteo; 23.11.2011
comment
После выполнения чистой рабочей директории модуля было развернуто мое приложение! Спасибо всем!! - person balteo; 23.11.2011

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

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

После того, как вы правильно настроите зависимости, m2e правильно настроит для вас пути сборки.

person Udo Held    schedule 22.11.2011
comment
Спасибо за ответ. Однако зависимости уже указаны в файлах pom... - person balteo; 23.11.2011
comment
Попробуйте обновить конфигурацию проекта для всех ваших проектов. Не могли бы вы опубликовать 3 помпона? Выполните установку maven для трех проектов. После этого просмотрите сгенерированную войну веб-проектов и проверьте, включены ли зависимости. - person Udo Held; 23.11.2011
comment
Да, после установки mvn я проверил и заметил, что зависимости были там. Однако экземпляр Eclipse tomcat не будет развертывать войну (согласно консоли), но отображает веб-проект в экземпляре сервера: очень странно... - person balteo; 23.11.2011
comment
Здесь мы работаем с MyEclipse. Он хорошо справляется с нашими веб-проектами Maven. - person Udo Held; 23.11.2011
comment
Я не могу найти очевидную ошибку в файле pom. Поскольку наша война выглядит нормально, у вас, вероятно, есть ошибка развертывания. Отображаются ли зависимости как зависимости maven в каждом модуле? Попробуйте также очистить проект. Еще одна вещь, которую можно попробовать, это закрыть домен и служебный модуль после установки и проверить, развертывает ли он установленные вами артефакты. - person Udo Held; 23.11.2011
comment
Что касается вашей точки зрения о возможной ошибке развертывания: я просмотрел консоль и не могу найти ничего, связанного с моим приложением: никакой информации о регистрации! Однако веб-приложение появляется под сервером, что меня озадачивает... - person balteo; 23.11.2011
comment
Я сделал чистую рабочую директорию модуля, и теперь она работает! Спасибо! - person balteo; 23.11.2011