与maven的春天启动为父项目

时间:2016-10-26 09:18:04

标签: java spring maven spring-boot

我有一个spring boot maven项目,名称为“CSMaster”,它包含我在另一个项目中使用的公共代码(AppAdmin)。

CSMaster项目包含 - 所有常见代码,如域,存储库层,服务层及其pom.xml文件。

AppAdmin项目包含 - 控制器层,其辅助类,jsp文件及其pom.xml文件。 在这个控制器层中,我们已经自动连接了Master Project中的服务层。

现在在编写代码时,我能够访问AppAdmin Project中的所有Parent Project方法,但是在通过mvn install生成AppAdmin Project的战争时,它会抛出以下错误 -

[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 7.996 s
[INFO] Finished at: 2016-10-26T13:07:25+05:30
[INFO] Final Memory: 28M/280M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.1:compile (default-compile) on project AppAdmin: Compilation failure: Compilation failure:
[ERROR] /home/ttnd/sumit/zzzLearning/repo/boot_appadmin/src/main/java/com/appadmin/helper/PermGroupHelper.java:[10,27] package com.csmaster.domain does not exist

在创建构建时,它没有获取主项目类。

我的Pom文件是 -

CSMaster: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>

    <groupId>com.csmaster</groupId>
    <artifactId>CSMaster</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <packaging>jar</packaging>

    <name>CSMaster</name>
    <description>MasterProject</description>

    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>1.4.1.RELEASE</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
        <java.version>1.8</java.version>
        <hibernate.version>5.2.2.Final</hibernate.version>
    </properties>

    <dependencies>

        <!-- Spring -->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        .
        .
        .
        .
        .
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>


</project>

AppAdmin: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>

    <groupId>com.appadmin</groupId>
    <artifactId>AppAdmin</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <packaging>war</packaging>
    <name>AppAdmin</name>
    <description>AppAdmin</description>

    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>1.4.1.RELEASE</version>
        <relativePath /> <!-- lookup parent from repository -->
    </parent>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
        <java.version>1.8</java.version>
        <hibernate.version>5.2.2.Final</hibernate.version>
    </properties>

    <dependencies>

        <!-- Parent Jar -->
        <dependency>
            <groupId>com.csmaster</groupId>
            <artifactId>CSMaster</artifactId>
            <version>0.0.1-SNAPSHOT</version>
            <scope>runtime</scope>
        </dependency>

        <!-- Spring -->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        .
        .
        .
        .
        .
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>
</project>

我该如何解决.. ???

1 个答案:

答案 0 :(得分:0)

您的CSMaster依赖关系是运行时并且符合maven introduction guide;

运行时:

  

此范围表示不需要依赖关系   编译,但是用于执行。它在运行时和测试中   classpaths,但不是编译类路径。

将您的依赖关系声明范围从运行时更改为编译,如下所示;

    <dependency>
        <groupId>com.csmaster</groupId>
        <artifactId>CSMaster</artifactId>
        <version>0.0.1-SNAPSHOT</version>
        <scope>compile</scope>
    </dependency>