2017-09-13 57 views
0

我一直在尋找一個解決方案,現在4天沒有成功搖籃罐子,爪哇 - 由FatJar創建任務將無法正常工作

先做正常搖籃建設任務產生了微小的7KB jar文件,這顯然沒有工作,然後我說的jar配置主類:

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

它現在2MB

還是不夠好, 後來我發現了fatJar/uberJar /陰影任務,說是同義同樣的事情,所以我嘗試乾淨然後上的另一個小RMI應用 fatJar任務是將在服務器上運行,它的工作很好,它複製到主應用程序,它產生和看起來不錯60MB jar文件,但它不會出於某種原因,

該應用程序從我的IDE完全運行( IntelliJIDEA),但生產的罐子什麼都不做。

所以,我的最後一個選項是所以在這裏向專家諮詢,我們去:

這是該清潔任務的結果:

6:11:10 PM: Executing external task 'clean'...

:clean

BUILD SUCCESSFUL

Total time: 0.774 secs

6:11:11 PM: External task execution finished 'clean'.

這是該fatJar任務的結果:

6:13:13 PM: Executing external task 'fatJar'...

Note: Some input files use unchecked or unsafe operations.

Note: Recompile with -Xlint:unchecked for details.

:compileJava

:processResources

:classes

:fatJar

BUILD SUCCESSFUL

Total time: 24.831 secs

6:13:37 PM: External task execution finished '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方法直接在主要存在 - > Java的目錄

這是我的settings.gradle文件:

rootProject.name = 'Yasmeena' 

我的主要方法是啓動JavaFX應用程序的簡單方法:

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

This's my project structure

UPDATE:

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 
} 

Current state of project structure

裏面的jar文件日:

現狀的build.gradle文件這是一個包含Main的活動文件夾。類文件

UPDATE:

jar文件 - > META-INF - > MANIFEST.MF

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 
+0

https://github.com/johnrengelman/shadow – Novaterata

+0

@Novaterata既不包括fatJar插件,也不使用shadowJar插件工作,只是在某些情況下,生產的jar大小從58MB降至57MB,就是這樣! –

+0

我相信這些插件是爲了替代你的fatJar任務,你需要配置它們。我不知道如何特別解決你的問題,但它看起來仍然不是一切都在CLASSPATH中。您可以編寫一些日誌代碼來在IntelliJ下運行時獲取CLASSPATH,並以jar的形式運行並查看缺少的內容。 classpath對java來說非常重要,特別是在jar中。 – Novaterata

回答

0

按照這裏的評論是什麼嘗試。

  • 確保主類設置
  • 確保主類具有作爲一個定義
  • 檢查清單是有效
  • 檢查類存在同樣完整的類名
  • 的JavaFX可能需要一個插件

最後一個問題修復了問題this是解決問題的插件。

這是鏈中的最後一個註釋:我會建議尋找到

@jrtapsell Well, this's embarrassing but i'v found the problem, i was unaware that JavaFX apps need a special plugin for Gradle, Using the FiberFox Plugin solved my issue, Thanks for your efforts and may you post answers so that i could upvote you if you like