简体   繁体   中英

ProGuard can't find the main method in my JavaFX application

I made a simple JavaFX program and I cannot seem to be able to obfuscate it with ProGuard.

I have followed this question: Obfuscating JavaFX application

This is my code:

import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.layout.AnchorPane;
import javafx.stage.Stage;

public class HelloWorld extends Application {

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

    @Override
    public void start(Stage primaryStage) throws Exception {
        AnchorPane root = new AnchorPane();
        Scene scene = new Scene(root, 300, 250);

        primaryStage.setTitle("Hello World!");
        primaryStage.setScene(scene);
        primaryStage.show();
    }

}

According to the answer in that question, this should be my configuration file:

-injars /Users/me/Desktop/MyProgram.jar
-outjars /Users/me/Desktop/Obfuscated.jar

-libraryjars <java.home>/lib/rt.jar
-libraryjars <java.home>/lib/ext/jfxrt.jar

-dontshrink
-dontoptimize
-flattenpackagehierarchy ''
-keepattributes Exceptions,InnerClasses,Signature,Deprecated,SourceFile,LineNumberTable,LocalVariable*Table,*Annotation*,Synthetic,EnclosingMethod
-adaptresourcefilecontents **.fxml,**.properties,META-INF/MANIFEST.MF

-keepclassmembernames class * {
    @javafx.fxml.FXML *;
}


# Keep - Applications. Keep all application classes, along with their 'main'
# methods.
-keepclasseswithmembers public class com.javafx.main.Main, HelloWorld {
    public static void main(java.lang.String[]);
}

But I get the following error when trying to run the .JAR program:

Error: Main method not found in class a.B, please define the main method as:
   public static void main(String[] args)
or a JavaFX application class must extend javafx.application.Application

According to this other question: Error: Main method not found in class Calculate, please define the main method as: public static void main(String[] args) I need my class to have a main method with a body. Clearly I already got that, as you can see from my code above.

So what did I do wrong? I am using Java 8.

Seems the problem is caused because you're not using MANIFEST.MF to specify which is the main class (I think this is because you exported the JAR via eclipse exporter)

You can fix this by trying to add this line in the configuration.

-keepclasseswithmembers public class com.javafx.main.Main, org.eclipse.jdt.internal.jarinjarloader.*, HelloWorld {
    public static void main(java.lang.String[]);
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM