编译失败。在eclipse java中使用多个maven模块时MOJ0失败

时间:2016-09-18 11:00:24

标签: java eclipse maven spring-mvc maven-2

我有以下prokect目录

MenuOrder
    - MenuOrder-Admin
         pom.xml
    - MenuOrder-Ap
         pom.xml
    pom.xml

请忽略MenuOrder-Api文件夹。这里没用了

enter image description here

我有以下pom设置

父母pom - > MenuOrder的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/maven-v4_0_0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>com</groupId>
    <artifactId>MenuOrder</artifactId>
    <packaging>pom</packaging>
    <version>0.0.1-SNAPSHOT</version>
    <name>MenuOrder Maven Webapp</name>
    <url>http://maven.apache.org</url>

    <build>
        <finalName>MenuOrder</finalName>
    </build>

    <modules>
        <module>MenuOrder-Ap</module>
        <module>MenuOrder-Admin</module>
    </modules>

    <properties>

        <junit.version>4.12</junit.version>

        <spring.version>4.2.4.RELEASE</spring.version>
        <spring-data-jpa.version>1.9.2.RELEASE</spring-data-jpa.version>

        <hibernate.version>5.0.7.Final</hibernate.version>
        <hibernate.validator>5.2.3.Final</hibernate.validator>

        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>

    </properties>

    <dependencies>

        <!-- Spring Framework -->
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-webmvc</artifactId>
            <version>${spring.version}</version>
            <type>jar</type>
            <scope>compile</scope>
        </dependency>

        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-jdbc</artifactId>
            <version>${spring.version}</version>
            <type>jar</type>
            <scope>compile</scope>
        </dependency>


        <!-- ORM dependencies -->
        <dependency>
            <groupId>org.springframework.data</groupId>
            <artifactId>spring-data-jpa</artifactId>
            <version>${spring-data-jpa.version}</version>
        </dependency>

        <dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-entitymanager</artifactId>
            <version>${hibernate.version}</version>
        </dependency>

        <dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-validator</artifactId>
            <version>${hibernate.validator}</version>
        </dependency>

        <dependency>
            <groupId>javax.el</groupId>
            <artifactId>javax.el-api</artifactId>
            <version>2.2.4</version>
        </dependency>


        <!-- MySql -->
        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <version>5.1.38</version>
        </dependency>


        <!-- Test -->
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.12</version>
        </dependency>

        <!-- Provided -->
        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>javax.servlet-api</artifactId>
            <version>3.1.0</version>
            <scope>provided</scope>
        </dependency>

        <!-- https://mvnrepository.com/artifact/org.springframework/spring-context-support -->
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-context-support</artifactId>
            <version>4.3.2.RELEASE</version>
        </dependency>

    </dependencies>

</project>

Child1 pom - &gt; MenuOrder-Admin的pom.xml

<?xml version="1.0"?>
<project
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
    xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <groupId>com</groupId>
        <artifactId>MenuOrder</artifactId>
        <version>0.0.1-SNAPSHOT</version>
    </parent>
    <artifactId>MenuOrder-Admin</artifactId>
    <packaging>war</packaging>
    <name>MenuOrder-Admin</name>
    <url>http://maven.apache.org</url>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    </properties>

    <build>
        <finalName>MenuOrder-Admin</finalName>
    </build>

    <dependencies>
        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>javax.servlet-api</artifactId>
            <version>3.1.0</version>
            <scope>provided</scope>
        </dependency>

        <dependency>
            <groupId>com</groupId>
            <artifactId>MenuOrder-Ap</artifactId>
            <version>0.0.1-SNAPSHOT</version>
        </dependency>
    </dependencies>
</project>

Child2 pom - &gt; MenuOrder-Ap的pom.xml

<?xml version="1.0"?>
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <modelVersion>4.0.0</modelVersion>
  <parent>
    <groupId>com</groupId>
    <artifactId>MenuOrder</artifactId>
    <version>0.0.1-SNAPSHOT</version>
  </parent>
  <groupId>com</groupId>
  <artifactId>MenuOrder-Ap</artifactId>
  <version>0.0.1-SNAPSHOT</version>
  <name>MenuOrder-Ap</name>
  <url>http://maven.apache.org</url>
  <properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
  </properties>
  <dependencies>
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>3.8.1</version>
      <scope>test</scope>
    </dependency>
  </dependencies>
</project>

即使我在MenuOrder-Ap中添加了MenuOrder-Admin作为依赖项,但当我尝试导入MenuOrder-Ap的任何包时,eclipse都不会显示错误但是当我尝试mvn-clean-install时,我收到编译错误,指出它无法找到导入的包。

以下是MenuOrder-Admin

的服务类示例
package com.menuorder.admin.persistence.controller;

import com.menuorder.api.*;

@Controller
public class UserController {


}

Eclipse没有显示任何错误,但是当我尝试mvn clean install时,它给出了以下错误: -

[ERROR] COMPILATION ERROR : 
[INFO] -------------------------------------------------------------
[ERROR] /media/pranishres/510712721F638E31/Projects/TestParent/MenuOrder-Admin/src/main/java/com/menuorder/admin/persistence/controller/UserController.java:[10,1] package com.menuorder.api does not exist
[INFO] 1 error
[INFO] -------------------------------------------------------------
[INFO] ------------------------------------------------------------------------
[INFO] Reactor Summary:
[INFO] 
[INFO] MenuOrder Maven Webapp ............................. SUCCESS [  0.312 s]
[INFO] MenuOrder-Ap ....................................... SUCCESS [  1.156 s]
[INFO] MenuOrder-Admin .................................... FAILURE [  0.333 s]
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 4.420 s
[INFO] Finished at: 2016-09-18T16:31:38+05:45
[INFO] Final Memory: 22M/261M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.1:compile (default-compile) on project MenuOrder-Admin: Compilation failure
[ERROR] /media/pranishres/510712721F638E31/Projects/TestParent/MenuOrder-Admin/src/main/java/com/menuorder/admin/persistence/controller/UserController.java:[10,1] package com.menuorder.api does not exist
[ERROR] -> [Help 1]
[ERROR] 
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR] 
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoFailureException
[ERROR] 
[ERROR] After correcting the problems, you can resume the build with the command
[ERROR]   mvn <goals> -rf :MenuOrder-Admin

请帮我解决这个问题。我一整天都在修理它。

谢谢

0 个答案:

没有答案