![](/img/trans.png)
[英]Error: Main method not found in class singleInheritance.A, please define the main method as: public static void main(String[] args) or a JavaFX
[英]JavaFX not calling main(String[] args) method
我開發了可以作為GUI
執行的GUI
, CLI
依賴於提供的參數。 這是應用程序類:
public class Main extends Application {
public static void main(String[] args) {
if (args != null && args.length > 0 && args[0].equals("cli")) {
String pathToProperties = args[1];
Cli cli = new Cli(pathToProperties);
cli.loadPropertiesAndGenerateApk();
} else {
launch(args);
}
}
@Override
public void start(Stage primaryStage) throws Exception {
FXMLLoader loader = new FXMLLoader(getClass().getResource("view/sample.fxml"));
Parent root = (Parent) loader.load();
primaryStage.setTitle("Allowed Site Configurator");
primaryStage.setScene(new Scene(root, 800, 800));
primaryStage.show();
}
}
當我構建工件時,Intellij IDEA創建MANIFEST.MF
:
Manifest-Version: 1.0
JavaFX-Version: 2.2
JavaFX-Application-Class: sample.Main
Created-By: JavaFX Packager
Main-Class: com/javafx/main/Main
當我調用java -jar JavaFXApp.jar "cli" ~/config.properties
程序只調用start()
方法而不先調用main()
方法。
問題是:如何強制首先調用main()
方法?
為GUI創建一個單獨的類:
public class Main {
public static void main(String[] args) {
if (args != null && args.length > 0 && args[0].equals("cli")) {
String pathToProperties = args[1];
Cli cli = new Cli(pathToProperties);
cli.loadPropertiesAndGenerateApk();
} else {
Application.launch(GUIApp.class, args);
}
}
}
和
public class GUIApp extends Application {
@Override
public void start(Stage primaryStage) throws Exception {
FXMLLoader loader = new FXMLLoader(getClass().getResource("view/sample.fxml"));
Parent root = (Parent) loader.load();
primaryStage.setTitle("Allowed Site Configurator");
primaryStage.setScene(new Scene(root, 800, 800));
primaryStage.show();
}
}
並配置構建,以便Main
是主類。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.