当前位置: 首页 > 知识库问答 >
问题:

Java-FatJar任务创建的Gradle jar不起作用

弓磊
2023-03-14

我已经为这个问题寻找了4天的解决方案,但没有成功,

首先做正常的Gradle构建任务产生了一个很小的7kB jar文件,显然不起作用,然后我为主类添加了jar配置:

jar {
    manifest {
        attributes 'Main-Class': 'Main'
    }
}

现在是2MB!

仍然不够好,然后我找到了法特加/uberJar/影子任务,据说是同样的事情的同义词,所以我试着在另一个小的RMI应用程序上清理法特加任务,它将在服务器上运行,它工作得很好,将其复制到主应用程序,它产生和60MB jar文件,看起来不错,但由于某种原因它不起作用,

该应用程序运行完美从我的IDE(IntelliJIDEA),但产生的罐子只是什么都不做。

因此,我的最后一个选择是咨询专家,现在我们开始:

这是清理任务的结果:

6:11:10 PM:执行外部任务'清洁'...

:清洁

建立成功

总时间:0.774秒

下午6:11:11:外部任务执行完成“清理”。

这是fatJar任务的结果:

注意:一些输入文件使用未经检查或不安全的操作。

注意:使用-Xlint重新编译:未检查详细信息。

:compileJava

:进程资源

:班级

:法特加

建立成功

总时间:24.831秒

下午6:13:37:外部任务执行完成“fatJar”。

这是我的build.gradle文件

group 'Yasmeena'
version '1.0-SNAPSHOT'

apply plugin: 'java'

compileJava.options.encoding = 'UTF-8'

sourceCompatibility = 1.8

jar {
    manifest {
        attributes 'Main-Class': 'Main'
    }
}

task fatJar(type: Jar) {
    manifest {
        attributes 'Implementation-Title': 'Gradle Jar',
                'Implementation-Version': version,
                'Main-Class': 'Main'
    }
    baseName = project.name + '-all'
    from { configurations.compile.collect { it.isDirectory() ? it : zipTree(it) } }
    with jar
}

allprojects {
    repositories {
        mavenCentral()
        maven { url 'https://jitpack.io' }
    }
}

dependencies {

    compile 'com.mchange:c3p0:0.9.5.2'
    compile 'commons-beanutils:commons-beanutils:1.9.3'
//    compile 'org.apache.commons:commons-collections3:2.2-SNAPSHOT'
    compile 'commons-digester:commons-digester:2.1'
    compile 'commons-logging:commons-logging:1.2'
    compile 'commons-validator:commons-validator:1.6'
    compile 'org.controlsfx:controlsfx:8.40.13'
    compile 'com.jfoenix:jfoenix:1.7.0'
    compile 'com.mchange:mchange-commons-java:0.2.11'
    compile 'com.github.PlusHaze:TrayNotification:-SNAPSHOT'
    compile 'com.google.firebase:firebase-admin:5.3.0'

    compile 'org.jetbrains:annotations:15.0'
    compile 'org.slf4j:slf4j-simple:1.7.25'

    compile group: 'org.postgresql', name: 'postgresql', version: '42.1.4'
    compile group: 'com.impossibl.pgjdbc-ng', name: 'pgjdbc-ng', version: '0.6'
    compile group: 'org.eclipse.jdt.core.compiler', name: 'ecj', version: '4.6.1'
    compile group: 'de.jensd', name: 'fontawesomefx', version: '8.9'
    compile group: 'commons-collections', name: 'commons-collections', version: '3.2.2'
    compile group: 'com.lowagie', name: 'itext', version: '2.1.7'
    compile group: 'org.olap4j', name: 'olap4j', version: '1.2.0'

    compile fileTree(dir: 'lib', include: 'ReportUtilities.jar')

    compile('net.sf.jasperreports:jasperreports:6.4.1') {
        exclude group: 'com.itextpdf'
    }
    runtime 'com.itextpdf:itextpdf:5.5.0'
    runtime 'com.itextpdf:itext-pdfa:5.5.0'

    testCompile group: 'junit', name: 'junit', version: '4.12'
}

我的Main.java类保存着我的Main方法,它直接存在于Main中-

这是我的settings.gradle文件:

rootProject.name = 'Yasmeena'

我的主要方法是启动JavaFX应用程序的简单方法:

public static void main(String[] args) {
        launch(args);
}

这是我的项目结构

build.gradle文件的当前状态:

group 'Yasmeena'
version '1.0-SNAPSHOT'

apply plugin: 'java'

compileJava.options.encoding = 'UTF-8'

sourceCompatibility = 1.8

jar {
    manifest {
        attributes 'Main-Class': 'activities.Main'
    }
}

allprojects {
    repositories {
        mavenCentral()
        maven { url 'https://jitpack.io' }
    }
}

dependencies {

    compile 'com.mchange:c3p0:0.9.5.2'
    compile 'commons-beanutils:commons-beanutils:1.9.3'
    compile 'commons-digester:commons-digester:2.1'
    compile 'commons-logging:commons-logging:1.2'
    compile 'commons-validator:commons-validator:1.6'
    compile 'org.controlsfx:controlsfx:8.40.13'
    compile 'com.jfoenix:jfoenix:1.7.0'
    compile 'com.mchange:mchange-commons-java:0.2.11'
    compile 'com.github.PlusHaze:TrayNotification:-SNAPSHOT'
    compile 'com.google.firebase:firebase-admin:5.3.0'

    compile 'org.jetbrains:annotations:15.0'
    compile 'org.slf4j:slf4j-simple:1.7.25'

    compile group: 'org.postgresql', name: 'postgresql', version: '42.1.4'
    compile group: 'com.impossibl.pgjdbc-ng', name: 'pgjdbc-ng', version: '0.6'
    compile group: 'org.eclipse.jdt.core.compiler', name: 'ecj', version: '4.6.1'
    compile group: 'de.jensd', name: 'fontawesomefx', version: '8.9'
    compile group: 'commons-collections', name: 'commons-collections', version: '3.2.2'
    compile group: 'com.lowagie', name: 'itext', version: '2.1.7'
    compile group: 'org.olap4j', name: 'olap4j', version: '1.2.0'

    compile fileTree(dir: 'lib', include: 'ReportUtilities.jar')

    compile('net.sf.jasperreports:jasperreports:6.4.1') {
        exclude group: 'com.itextpdf'
    }
    runtime 'com.itextpdf:itextpdf:5.5.0'
    runtime 'com.itextpdf:itext-pdfa:5.5.0'

    testCompile group: 'junit', name: 'junit', version: '4.12'
}

buildscript {
    repositories {
        jcenter()
    }
    dependencies {
        classpath 'eu.appsatori:gradle-fatjar-plugin:0.3'
    }
}

task fatJar(type: Jar) {
    manifest {
        attributes 'Implementation-Title': 'Gradle Jar',
                'Implementation-Version': version,
                'Main-Class': 'activities.Main',
                'Class-Path': ". ${configurations.compile.collect { it.getName() }.join(' ')}"
    }
    baseName = project.name + '-all'
    from { configurations.compile.collect { it.isDirectory() ? it : zipTree(it) } }
    with jar
}

项目结构的现状

在jar文件中有一个activities文件夹,其中包含一个Main.class文件

更新:

jar文件-

Manifest-Version: 1.0
Implementation-Title: Gradle Jar
Implementation-Version: 1.0-SNAPSHOT
Class-Path: . ReportUtilities.jar c3p0-0.9.5.2.jar commons-beanutils-1
 .9.3.jar commons-digester-2.1.jar commons-logging-1.2.jar commons-val
 idator-1.6.jar controlsfx-8.40.13.jar jfoenix-1.7.0.jar mchange-commo
 ns-java-0.2.11.jar TrayNotification--SNAPSHOT.jar firebase-admin-5.3.
 0.jar annotations-15.0.jar slf4j-simple-1.7.25.jar postgresql-42.1.4.
 jar pgjdbc-ng-0.6.jar ecj-4.6.1.jar fontawesomefx-8.9.jar commons-col
 lections-3.2.2.jar itext-2.1.7.jar olap4j-1.2.0.jar jasperreports-6.4
 .1.jar google-api-client-1.22.0.jar google-api-client-gson-1.22.0.jar
  google-http-client-1.22.0.jar json-20160810.jar guava-20.0.jar googl
 e-cloud-storage-1.2.1.jar slf4j-api-1.7.25.jar netty-all-4.0.32.Final
 .jar bcmail-jdk14-138.jar bcprov-jdk14-138.jar xercesImpl-2.11.0.jar 
 jcommon-1.0.23.jar jfreechart-1.0.19.jar castor-xml-1.3.3.jar jackson
 -core-2.1.4.jar jackson-databind-2.1.4.jar jackson-annotations-2.1.4.
 jar lucene-core-4.5.1.jar lucene-analyzers-common-4.5.1.jar lucene-qu
 eryparser-4.5.1.jar core-3.2.1.jar icu4j-57.1.jar google-oauth-client
 -1.22.0.jar google-http-client-jackson2-1.22.0.jar google-http-client
 -gson-1.22.0.jar httpclient-4.0.1.jar google-cloud-core-1.2.1.jar goo
 gle-cloud-core-http-1.2.1.jar google-api-services-storage-v1-rev100-1
 .22.0.jar castor-core-1.3.3.jar commons-lang-2.6.jar javax.inject-1.j
 ar stax-1.2.0.jar stax-api-1.0-2.jar lucene-queries-4.5.1.jar lucene-
 sandbox-4.5.1.jar guava-jdk5-17.0.jar httpcore-4.0.1.jar commons-code
 c-1.3.jar joda-time-2.9.2.jar api-common-1.1.0.jar gax-1.4.1.jar prot
 obuf-java-util-3.3.0.jar proto-google-common-protos-0.1.12.jar proto-
 google-iam-v1-0.1.12.jar google-auth-library-credentials-0.7.0.jar go
 ogle-auth-library-oauth2-http-0.7.0.jar google-http-client-appengine-
 1.21.0.jar google-http-client-jackson-1.21.0.jar stax-api-1.0.1.jar j
 akarta-regexp-1.4.jar auto-value-1.2.jar threetenbp-1.3.3.jar protobu
 f-java-3.3.0.jar jackson-core-asl-1.9.11.jar bctsp-jdk14-1.38.jar bcp
 rov-jdk14-1.38.jar bcmail-jdk14-1.38.jar xml-apis-1.4.01.jar jsr305-3
 .0.0.jar gson-2.7.jar
Main-Class: activities.Main

共有1个答案

魏泰
2023-03-14

根据这里的评论,这是我们尝试过的。

  • 确保设置了主类
  • 确保主类具有与定义的相同的完整类名
  • 检查舱单有效
  • 检查类是否存在
  • JavaFX可能需要一个插件

最后最后一个解决了这个问题,这就是解决这个问题的插件。

这是链中的最后一条评论:

@jrtapsell好吧,这很尴尬,但我发现了问题,我不知道JavaFX应用程序需要一个特殊的Gradle插件,使用FiberFox插件解决了我的问题,谢谢你的努力,希望你能发布答案,这样如果你愿意,我可以投票给你

 类似资料:
  • 似乎Gradle zipAligns任务对我不起作用,不确定我做错了什么。我尝试过包含zipAligns任务,也尝试过不包含它,但似乎没有什么不同。我的gradle脚本吐出了一个“发布”版本,但当我尝试上传我的. apk时,它从来没有根据开发人员控制台进行压缩对齐。 这是我的构建脚本: 感谢您的帮助!

  • 由于某些原因,我的位图创建不起作用。我找到一只虫子了吗?当我尝试使用矩阵创建一个新位图时,它说我的宽度和高度必须大于0,这毫无意义。 我知道这看起来好像我没有做过任何研究,我做过,但这没有意义。我已经尝试了很多事情,包括将新宽度和新宽度更改为常量,但它仍然不起作用。如果有帮助的话,这是堆栈跟踪 我正在尝试制作一个旋转门户。我想有一个矩阵平移,旋转和缩放,但我没有得到工作。我决定把译文拿出来,只是做

  • 每个 gulp 任务(task)都是一个异步的 JavaScript 函数,此函数是一个可以接收 callback 作为参数的函数,或者是一个返回 stream、promise、event emitter、child process 或 observable (后面会详细讲解) 类型值的函数。由于某些平台的限制而不支持异步任务,因此 gulp 还提供了一个漂亮 替代品。 导出任务 任务(tasks

  • 我正在尝试为我的Vue自动化构建过程(Azure Devops)。使用“npm”任务的js应用程序。 为了安装节点包,我使用了内置的“安装”命令的npm任务。 对于构建过程,我已经部署了另一个npm任务,但是使用了自定义命令(构建)。此自定义生成命令成功运行,但出现以下警告 "npm WARN build'npm build'不带参数调用。你是说'npm run-script build'吗?"

  • 在本章中,让我们学习如何creating tasks 。 每当您运行Grunt时,都会指定一个或多个任务运行,以通知Grunt您希望它执行的操作。 如果指定default task ,则默认情况下将运行。 别名任务 每当指定任务列表时,新任务可以为一个或多个其他任务设置别名。 运行别名将依次运行taskList中的每个指定任务。 taskList参数应该是一个任务数组,如下所示 - grunt.r

  • 创建任务 登录后台,左侧导航中点击“添加任务” 添加任务页面 “导入任务”可以复制其他任务的所有设置(包括采集器设置、发布设置) “导入规则”可以从其他任务或文件中复制采集器设置 “更多设置”可以为任务单独配置采集设置