【已解决】【一眼就会】Exception in thread “main“ java.lang.NoClassDefFoundError java.lang.ClassNo【jar中没有主清单属性】

《一眼就会系列》每天抽出一点时间巩固基础!同时学习最新知识(与时俱进)!罗列、简述、概括问题,让读者扫一眼就知道该如何处理。

其实就是配置文件和包的版本问题。

解决方法如下:(请放大并用超清观看)

java

 

build.gradle 配置文件:

apply plugin: 'java'
apply plugin: 'war'
apply plugin: 'idea'
version '1.0-SNAPSHOT'
repositories {
    mavenCentral()
}

dependencies {
    testImplementation 'org.junit.jupiter:junit-jupiter-api:5.7.0'
    testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.7.0'
    //jdbc
    compile 'org.springframework.boot:spring-boot-starter-jdbc:2.5.3'
    compile 'mysql:mysql-connector-java:8.0.28'
    //json
    compile 'com.alibaba:fastjson:1.2.39'
    //spring
    compile 'org.springframework.boot:spring-boot-starter-web:2.5.2'
    /* log4j */
    compile 'org.apache.logging.log4j:log4j-core:2.17.1'
    compile 'org.apache.logging.log4j:log4j-api:2.17.1'
    //swagger:
    compile 'io.springfox:springfox-swagger2:3.0.0'
    compile 'io.springfox:springfox-swagger-ui:3.0.0'
    compile 'com.google.guava:guava:31.0.1-jre'
    compile 'junit:junit:4.12'
}

jar {
    String JarPathAll = ''
    configurations.runtime.each {JarPathAll = JarPathAll + " lib\\"+it.name}
    manifest {
        attributes 'Main-Class': 'org.example.ApplicationStart'
        attributes 'Class-Path': JarPathAll
    }
}

test {
    useJUnitPlatform()
}

ApplicationStart.java 启动文件:

package org.example;

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

@SpringBootApplication(exclude = DataSourceAutoConfiguration.class)
public class ApplicationStart {
    public static void main(String[] args) {
        SpringApplication.run(ApplicationStart.class);
    }
}
 

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值