springboot 2.0多模块标准父类pom文件,别再问问什么找不到主类了,照着个写就行

标准如下:

<?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.baeldung.spring-boot-modules</groupId>
        <artifactId>spring-boot-modules</artifactId>
        <version>1.0.0-SNAPSHOT</version>
        <relativePath>../</relativePath>
    </parent>

    <artifactId>spring-boot-basic-customization</artifactId>
    <packaging>jar</packaging>

    <name>spring-boot-basic-customization</name>
    <description>Module For Spring Boot Basic Customization</description>

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

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

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

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

    <properties>
        <!-- The main class to start by executing "java -jar" -->
        <start-class>com.baeldung.changeport.CustomApplication</start-class>
    </properties>
</project>

找不到主类就是因为你没有设置开始的主类是哪个,这个父类文件中在最后有一行<start-class>com.baeldung.changeport.CustomApplication</start-class> 设置了主类位置。

这里的 com.baeldung.changeport.CustomApplication,改成你主类所在位置。

MANIFEST.MF就照这个写:

Manifest-Version: 1.0
Main-Class: com.example.server.ServerApplication
Class-Path: org.springframework.boot.loader.JarLauncher

同理,com.example.server.ServerApplication改成你主类地址。

注意:这个父类设置要在pom.xml文件中<parent>`标签中有spring-boot-starter-parent属性才会生效。 换句话就是自己手动建立的springboot中可能无法生效。

那么自己手动建立的无法生效怎么办?
看下面:

<build>
    <plugins>
        <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>             
            <configuration>    
                <mainClass>com.baeldung.DemoApplication</mainClass>
            </configuration>
        </plugin>
    </plugins>
</build>

是的,把这段代码贴进父类pom.xml文件中就完事。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

timi先生

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值