Java教程

Java Springcloud项目bug记录过程02---springboot项目打包,linux服务器上运行报错

本文主要是介绍Java Springcloud项目bug记录过程02---springboot项目打包,linux服务器上运行报错,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!

Linux执行Jar包报错: no main manifest attribute

解决方案:

    <build>
        <plugins>

            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-jar-plugin</artifactId>
                <version>2.3.2</version>
            </plugin>

            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <!--<version>2.1.6.RELEASE</version>-->
                <executions>
                    <execution>
                        <goals>
                            <goal>repackage</goal>
                        </goals>
                    </execution>
                </executions>
                <configuration>
                    <includeSystemScope>true</includeSystemScope>
                    <mainClass>com.hzbank.flep.TestApplication</mainClass>
                </configuration>
            </plugin>
        </plugins>
    </build>

但项目打包时可能还会报以下错误:

Failed to execute goal org.springframework.boot:spring-boot-maven-plugin:2.5.4:repackage (default) on project flep-sdk-cloud-test1: Execution default of goal org.springframework.boot:spring-boot-maven-plugin:2.5.4:repackage failed: Plugin org.springframework.boot:spring-boot-maven-plugin:2.5.4 or one of its dependencies could not be resolved: Failed to collect dependencies at org.springframework.boot:spring-boot-maven-plugin:jar:2.5.4 -> org.springframework.boot:spring-boot-buildpack-platform:jar:2.5.4: Failed to read artifact descriptor for org.springframework.boot:spring-boot-buildpack-platform:jar:2.5.4: Could not transfer artifact org.springframework.boot:spring-boot-buildpack-platform:pom:2.5.4 from/to central (https://repo.maven.apache.org/maven2): repo.maven.apache.org: Unknown host repo.maven.apache.org -> [Help 1]

 报错分析:

日志提示是spring-boot-mavne-plugin 2.5.4 repackage 重新打包报错

排查结果:

spring-boot-mavne-plugin 2.5.4与springboot工程中使用的版本冲突了

解决方案:

springboot项目应该使用父标签<parent></parent>,统一规范项目使用的springboot版本,从而避免版本冲突。

<?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.ttbank.flep</groupId>
    <artifactId>flep-sdk-cloud-test1</artifactId>
    <version>1.0-SNAPSHOT</version>
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.1.6.RELEASE</version>
    </parent>
    <dependencies>
        <dependency>
            <groupId>com.hzbank.flep</groupId>
            <artifactId>flep-sdk-cloud</artifactId>
            <version>1.2-20211112.004552-45</version>
            <!--springboot和注册中心源生依赖,如存在jar包冲突,可以手动排除,使用源生依赖-->
            <exclusions>
                <exclusion>
                    <groupId>org.springframework.boot</groupId>
                    <artifactId>spring-boot-autoconfigure</artifactId>
                </exclusion>

                <exclusion>
                    <groupId>org.springframework.cloud</groupId>
                    <artifactId>spring-cloud-commons</artifactId>
                </exclusion>
            </exclusions>

        </dependency>

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

        <dependency>
            <groupId>com.alibaba.cloud</groupId>
            <artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>
            <version>2.1.0.RELEASE</version>
        </dependency>

    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-jar-plugin</artifactId>
                <version>2.3.2</version>
            </plugin>

            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <!--<version>2.1.6.RELEASE</version>-->
                <executions>
                    <execution>
                        <goals>
                            <goal>repackage</goal>
                        </goals>
                    </execution>
                </executions>
                <configuration>
                    <includeSystemScope>true</includeSystemScope>
                    <mainClass>com.hzbank.flep.TestApplication</mainClass>
                </configuration>
            </plugin>
        </plugins>
    </build>
</project>

 

这篇关于Java Springcloud项目bug记录过程02---springboot项目打包,linux服务器上运行报错的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!