Reputation: 2856
I going to create a runnable JAR file inside Eclipse IDE. All my dependencies are from Maven. In Eclipse I'm creating a JavaFX GUI application for desktop.
The problem is that when I creating the runnable JAR file. I got this error.
The error is very clear.
Jar export finished with problems. See details for additional information. Could not find main method from given launch configuration.
But what is main method? Is it the public static void main(String[] args)
method here?
What should I do to solve this?
package se.danielmartensson.start;
import java.util.Optional;
import javafx.application.Application;
import javafx.application.Platform;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.scene.control.Alert;
import javafx.scene.control.Alert.AlertType;
import javafx.scene.control.ButtonType;
import javafx.stage.Stage;
import se.danielmartensson.concurrency.Measureing;
public class Main extends Application{
/*
* Start the start(Stage front)
*/
public static void main(String[] args) {
launch(args);
}
@Override
public void start(Stage front) throws Exception {
front.setOnCloseRequest(e->{
e.consume();
askForClosing();
});
Parent root = FXMLLoader.load(getClass().getResource("/se/danielmartensson/fxml/front.fxml"));
Scene scene = new Scene(root);
front.setScene(scene);
front.setTitle("JUBSPlotter");
front.show();
}
private void askForClosing() {
Alert question = new Alert(AlertType.CONFIRMATION);
question.setTitle("Closing");
question.setHeaderText("Do you want to close?");
question.setResizable(false);
question.setContentText("Press OK to close.");
Optional<ButtonType> answer = question.showAndWait();
if(answer.get() == ButtonType.OK) {
Measureing.active = false;
Platform.exit();
}
}
}
Upvotes: 1
Views: 2809
Reputation: 8031
You have to use the following maven plugin to create a runnable jar file.
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<configuration>
<archive>
<manifest>
<mainClass>
com.ddlab.rnd.App
</mainClass>
</manifest>
</archive>
</configuration>
</plugin>
This is for very simple project where you want to learn about how to create an executable jar file to run. To have a good idea about how to create a runnable/executable jar file, check this github link. https://github.com/debjava/runnableJar If you have other libraries to use as part of your application. You have to create fat jar file. To create a fat jar file, you have to use Maven Shade plugin. Find below the link for maven shade plugin.
https://maven.apache.org/plugins/maven-shade-plugin/
Upvotes: 3