gradle打包jar可执行程序遇到的问题

解决问题

  • 打包成可运行的包
  • 把依赖也打进去
  • 排查依赖中的某些文件
/*
 * This file was generated by the Gradle 'init' task.
 *
 * This generated file contains a sample Java project to get you started.
 * For more details take a look at the Java Quickstart chapter in the Gradle
 * User Manual available at https://docs.gradle.org/5.2.1/userguide/tutorial_java_projects.html
 */

plugins {
    // Apply the java plugin to add support for Java
    id 'java'

    // Apply the application plugin to add support for building an application
    id 'application'
}

repositories {
    // Use jcenter for resolving your dependencies.
    // You can declare any Maven/Ivy/file repository here.
    jcenter()
}

dependencies {
    // This dependency is found on compile classpath of this component and consumers.
//    implementation 'com.google.guava:guava:27.0.1-jre'
    implementation fileTree(dir: 'libs', include: '*.jar')


    // Use JUnit test framework
    testImplementation 'junit:junit:4.12'
}
compileJava {
    sourceCompatibility = 1.8
    targetCompatibility = 1.8
    options.fork = true
    options.incremental = true
}
applicationDistribution.from('src/main/resources'){
    into "config"
}


// Define the main class for the application
mainClassName = 'com.koal.tele.poc.TelePocTest'

jar {
    String runtimePath = ''
    configurations.runtime. each {runtimePath = runtimePath + " lib//" +it.name} // 本地lib
    from {
        configurations.runtimeClasspath.collect { it.isDirectory() ? it : zipTree(it) } // implementation 相关的引入解压并打包入新的jar中
    }
    manifest {
        attributes 'Main-Class' : 'com.koal.tele.poc.TelePocTest' // 主类类名
        attributes 'Class-Path' : runtimePath
    }
    //不删除BC库的这些文件会导致jar无法运行
    exclude(["META-INF/BC1024KE.DSA","META-INF/BC1024KE.SF","META-INF/BC2048KE.DSA","META-INF/BC2048KE.SF"])
}




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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值