吾爱破解 - 52pojie.cn

 找回密码
 注册[Register]

QQ登录

只需一步,快速开始

查看: 1271|回复: 3
收起左侧

[求助] gradle 打成jar包无法加载主类

[复制链接]
积木工具箱 发表于 2021-5-24 14:22
[Asm] 纯文本查看 复制代码
version '1.0-SNAPSHOT'

apply plugin: 'java'

apply plugin: 'maven'

apply plugin: 'application'

group 'apns2'
version '1.0-SNAPSHOT'
description = """apns_aoetech"""
mainClassName = "com.aoetech.lailiao.apns.Main"
sourceCompatibility = 1.8//JDK的版本为1.7
targetCompatibility = 1.8
repositories {
    google()
    maven { url "http://maven.aliyun.com/nexus/content/groups/public/" }
    mavenCentral()
    maven { url "http://repo.maven.apache.org/maven2" }
}

tasks.withType(JavaCompile) {
    options.encoding = 'UTF-8'
}


jar {


    from {

        configurations.runtime.collect {
            it.isDirectory() ? it : zipTree(it)
        }

        configurations.compile.collect {
            it.isDirectory() ? it : zipTree(it)
        }
    }

    manifest {
        attributes 'Main-Class': 'com.aoetech.lailiao.apns.Main',
                'Class-Path': configurations.runtime.files.collect {"$it.name"}.join(' ')


    }

    exclude 'META-INF/*.RSA', 'META-INF/*.SF','META-INF/*.DSA'

}


dependencies {
    //compile 'org.apache.logging.log4j:log4j-api:2.5'
    //compile 'org.apache.logging.log4j:log4j-core:2.5'
    //slf4j Bridge to Log4j 2.x
    //compile 'org.apache.logging.log4j:log4j-slf4j-impl:2.5'
    implementation fileTree(dir:'libs',include:['*.jar'])
    implementation group: 'io.netty', name: 'netty-codec-http2', version: '4.1.24.Final'
    implementation group: 'io.netty', name: 'netty-handler-proxy', version: '4.1.24.Final'
    implementation group: 'io.netty', name: 'netty-resolver-dns', version: '4.1.24.Final'
    implementation group: 'io.netty', name: 'netty-tcnative-boringssl-static', version: '2.0.8.Final'
    implementation group: 'com.eatthepath', name: 'fast-uuid', version: '0.1'
    implementation group: 'com.google.code.gson', name: 'gson', version: '2.8.4'
    implementation 'org.slf4j:slf4j-api:1.7.25'
    implementation 'ch.qos.logback:logback-core:1.1.7'
    implementation 'ch.qos.logback:logback-classic:1.1.7'
    testImplementation group: 'junit', name: 'junit', version: '4.12'
    testImplementation group: 'pl.pragmatists', name: 'JUnitParams', version: '1.1.1'
    implementation group: 'io.netty', name: 'netty-all', version: '4.1.24.Final'
    implementation group: 'redis.clients', name: 'jedis', version: '2.8.2'
    // https://mvnrepository.com/artifact/org.json/json
    implementation group: 'org.json', name: 'json', version: '20180130'
    // https://mvnrepository.com/artifact/org.apache.httpcomponents/httpclient
    implementation group: 'org.apache.httpcomponents', name: 'httpclient', version: '4.5.5'
    // https://mvnrepository.com/artifact/com.alibaba/fastjson
    implementation group: 'com.alibaba', name: 'fastjson', version: '1.2.47'
    // https://mvnrepository.com/artifact/com.meizu.flyme/push-server-sdk
    implementation group: 'com.meizu.flyme', name: 'push-server-sdk', version: '1.2.7.20180307_release'
    // https://mvnrepository.com/artifact/org.apache.commons/commons-lang3
    implementation group: 'org.apache.commons', name: 'commons-lang3', version: '3.9'
// https://mvnrepository.com/artifact/com.google.guava/guava
    implementation group: 'com.google.guava', name: 'guava', version: '19.0'


}



配置文件如上 build出来的jar包很小 运行jar就显示无法加载主类  在idea里run是没问题的 没用过gradle 请大佬指教一下

发帖前要善用论坛搜索功能,那里可能会有你要找的答案或者已经有人发布过相同内容了,请勿重复发帖。

只是来打酱油 发表于 2021-5-24 15:29
直接运行是通过类class文件,打包成jar包需要声明入口的main 类。
你找个正常运行的那种jar包解压看看就知道了
 楼主| 积木工具箱 发表于 2021-5-24 15:39
只是来打酱油 发表于 2021-5-24 15:29
直接运行是通过类class文件,打包成jar包需要声明入口的main 类。
你找个正常运行的那种jar包解压看看就知 ...

有声明的
VioletKiss 发表于 2021-5-26 09:22
你是下面这个意思?

https://blog.csdn.net/u010845141/article/details/47342057
您需要登录后才可以回帖 登录 | 注册[Register]

本版积分规则

返回列表

RSS订阅|小黑屋|处罚记录|联系我们|吾爱破解 - LCG - LSG ( 京ICP备16042023号 | 京公网安备 11010502030087号 )

GMT+8, 2024-11-25 23:16

Powered by Discuz!

Copyright © 2001-2020, Tencent Cloud.

快速回复 返回顶部 返回列表