我使用gradle构建了Javafx应用程序,而我正在使用外部库apache poixml并且需要为其创建jar,并且在使用poixml类时无法运行我在github上尝试过的示例项目:https://github.com/IslamAssem/HelloFX-Gradle
我假设您使用单独下载的OpenJFX14 jar,并将其包含在Build路径中。
我会通过Gradle将JavaFX添加到您的附属程序中。
dependencies { implementation 'org.apache.poi:poi:4.1.1' implementation 'org.apache.poi:poi-ooxml:4.1.1' testCompile group: 'junit', name: 'junit', version: '4.12' // here starts JavaFX implementation 'org.openjfx:javafx:14' compile 'org.openjfx:javafx-base:14' compile 'org.openjfx:javafx-graphics:14' compile 'org.openjfx:javafx-controls:14' compile 'org.openjfx:javafx-fxml:14' compile 'org.openjfx:javafx-swing:14' compile 'org.openjfx:javafx-media:14' compile 'org.openjfx:javafx-web:14' }
然后,我建议您的Main不在从Application扩展的类中。
您应该创建启动器。
public class Launcher{ public static void main(String[] args){ Application.launch(HelloFX.class,args); } }
并使用JavaFX构建Jar ...
将此添加到您的build.gradle:
jar { manifest { attributes( 'Main-Class': 'your.main.package.Launcher' // replace with you main class ) } from { configurations.runtimeClasspath.collect { it.isDirectory() ? it : zipTree(it) } } }
这应该处理。