码迷,mamicode.com
首页 > 其他好文 > 详细

Maven聚合项目的创建

时间:2019-05-31 01:28:46      阅读:144      评论:0      收藏:0      [点我收藏+]

标签:nts   alt   nis   local   art   image   code   访问   tap   

1.项目结构如下

技术图片

步骤如下:

技术图片

技术图片

点击Finish

这里父项目需要加入如下的构建依赖:

<dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>org.springframework.data</groupId>
                <artifactId>spring-data-releasetrain</artifactId>
                <version>Fowler-SR2</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-dependencies</artifactId>
                <version>2.0.2.RELEASE</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
        </dependencies>
    </dependencyManagement>

再加入springboot的依赖:

<dependencies>

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

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>

    </dependencies>
2.构建子项目

技术图片

技术图片

技术图片

点击next修改名称完成构建 这里我们把a-first当做启动项目,需要在maven中加入:

<build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <executions>
                    <execution>
                        <goals>
                            <goal>repackage</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>

然后加入启动类:

@SpringBootApplication
@ComponentScan("com.test.*")
public class AfirstApplication {
    public static void main(String[] args) {
        SpringApplication.run(AfirstApplication.class);
    }
}

b项目的建立

用同样的方式建立b项目 但不用建立启动类,我们项目a依赖b,如下:

技术图片

在b中建立包com.test.bsecond,下面建立类TestRead:

public class TestRead {

    public String eat(){

        return "test eat";
    }
}

在a中建立包com.test.afirst,下面建立包test,再建立类AReadB:

@Controller
public class AReadB {
    @RequestMapping("/test")
    @ResponseBody
    public  String test() {
        TestRead testRead = new TestRead();
        String eat = testRead.eat();
        return  eat;

    }
}

现在执行mvn install,这个项目下面的所有的都打包完毕

技术图片

然后我们运行启动类的jar包:

技术图片

访问路径:http://localhost:8080/test 结果如下:

test eat

Maven聚合项目的创建

标签:nts   alt   nis   local   art   image   code   访问   tap   

原文地址:https://www.cnblogs.com/charlypage/p/10952864.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!