Reputation: 1572
I am trying to make my jar run. It builds and all but when I try to run the jar it says:
no main manifest attribute, in Sagrada.jar
build.gradle
:
plugins {
id 'application'
id 'org.openjfx.javafxplugin' version '0.0.8'
id 'org.beryx.jlink' version '2.12.0'
}
apply plugin: 'java'
repositories {
mavenCentral()
}
dependencies {
// https://mvnrepository.com/artifact/org.apache.commons/commons-collections4
compile group: 'org.apache.commons', name: 'commons-collections4', version: '4.4'
// https://mvnrepository.com/artifact/mysql/mysql-connector-java
compile group: 'mysql', name: 'mysql-connector-java', version: '8.0.18'
}
javafx {
version = "13"
modules = [ 'javafx.controls', 'javafx.fxml' ]
}
mainClassName = "$moduleName/nl.avans.sagrada.MainApp"
jlink {
options = ['--strip-debug', '--compress', '2', '--no-header-files', '--no-man-pages']
launcher {
name = 'Sagrada'
}
}
Then I run Tasks > application > run which works fine. But when I try to build a jar with Tasks > build > build or Tasks > build > jar it outputs this jar with the problem described above.
I followed JavaFX 13 tutorial: https://openjfx.io/openjfx-docs/
Then JavaFX and IntelliJ > Modular with Gradle
I don't want the image but a runnable jar which I need for a school project.
I did check the Path
variables which are set to the right Java. I also tried to run the jar with jar -jar Sagrada.jar nl.avans.sagrada.MainApp
.
Upvotes: 0
Views: 671
Reputation: 2148
You did not define a "manifest - attribute" in your gradle build.
You should specify the "jar" task like that :
jar {
manifest {
attributes(
'Main-Class': 'your.main.package.MainApp'
)
}
from {
configurations.runtimeClasspath.collect { it.isDirectory() ? it : zipTree(it) }
}
}
EDIT:
You should also Clarify the nessecary moduls.
You can do this via the module-info.java
or use the "compileJava" task in gradle, to declare the VM arguments for compilation.
gradle:
compileJava {
doFirst {
options.compilerArgs = [
'--module-path', classpath.asPath,
'--add-modules', 'javafx.controls,javafx.fxml,javafx.graphics'
]
println options.compilerArgs
}
}
module-info.java
module ProjectName {
requires javafx.controls;
requires javafx.fxml;
requires transitive javafx.graphics;
// specify the package the uses the modules
opens com.your.package to javafx.fxml, javafx.controls;
exports org.openjfx;
}
i Hope that helps
Also you should use a Launcher, that Starts the Application and not use the Application as main class (in the case you did not already did this). Your Main Class should not Extend Application.
public class AppLauncher{
public static void main(String args[]){
Application.launch(YourApplication.class,args)
}
}
Upvotes: 2