tnblog
首页
视频
资源
登录

为Maven空模块配置框架类型——pom的设置

3028人阅读 2021/12/24 14:41 总访问:1044221 评论:0 收藏:0 手机
分类: Maven

一、pom.xml的使用
只要你的依赖没问题,想生成什么项目都可以,这个要对Maven稍稍要有一定的了解
如生成一个spring boot的项目

空模块maven代码

<?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>org.example</groupId>
    <artifactId>untitled</artifactId>
    <version>1.0-SNAPSHOT</version>

    <properties>
        <maven.compiler.source>8</maven.compiler.source>
        <maven.compiler.target>8</maven.compiler.target>
    </properties>

</project>

下载spring boot至少要有依赖坐标和相应版本

<?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>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.5.5</version>
        <relativePath/>
    </parent>

    <groupId>org.example</groupId>
    <artifactId>dd2</artifactId>
    <version>1.0-SNAPSHOT</version>
    <!--JDK版本-->
    <properties>
        <maven.compiler.source>8</maven.compiler.source>
        <maven.compiler.target>8</maven.compiler.target>
    </properties>

<dependencies>
    <!--      web-->
    <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>
</project>

二、Java代码的操作
空模块这来个文件夹

和类都是没有的。

注意:一定要在Java文件夹下再创一个文件夹,然后才去添加资源


启动类代码

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication
public class dd2Application {
    public static void main(String[] args) {
        try {
                                //注意启动类的名称要和类名相同
            SpringApplication.run(dd2Application.class, args);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

测试类代码

import org.junit.jupiter.api.Test;
import org.springframework.boot.test.context.SpringBootTest;

@SpringBootTest
public class dd2ApplicationTest {

    @Test
    void getTest(){
        System.out.println("我的测试");
    }
}

简单的启动了一下没有报错
其它的一些pom设置

评价
没有个性,不需要签名
排名
6
文章
6
粉丝
16
评论
8
{{item.articleTitle}}
{{item.blogName}} : {{item.content}}
ICP备案 :渝ICP备18016597号-1
网站信息:2018-2024TNBLOG.NET
技术交流:群号656732739
联系我们:contact@tnblog.net
欢迎加群交流技术