2

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.

Community
  • 1
  • 1
Saturn
  • 17,888
  • 49
  • 145
  • 271
  • Just a shot in the dark here, what if you put your main in another class? – Jose Martinez Jul 31 '15 at 17:45
  • @JoseMartinez doesn't seem to change anything – Saturn Jul 31 '15 at 19:28
  • You could always use this library: https://github.com/yongjhih/proguard-annotations Just add `@KeepApplication` annotation above your class. – Jared Rummler Aug 04 '15 at 17:12
  • @Voldemort not sure if this is the fix. But, in proguard doc, the class specifications shows that the opening brace (`{`) should be in the new line. so, can you try to put a new line after the `HelloWorld` class name in `keepclasseswithmembers` setting? – kucing_terbang Aug 04 '15 at 17:14
  • @kucing_terbang I'm afraid it doesn't make a difference. – Saturn Aug 05 '15 at 15:20
  • @Voldemort hmm, is it possible to share your jar file? because when I tried it using your code and configuration, the output jar seems working fine. – kucing_terbang Aug 06 '15 at 04:26
  • @kucing_terbang Sure. Here is the JAR: https://drive.google.com/file/d/0B0pnrFvDqjdmRkNWME54V1ZQcDQ/view?usp=sharing - running it should open a simple blank window. Is it perhaps because I'm using Mac OSX? – Saturn Aug 06 '15 at 07:11
  • @Voldemort I've tried run it on my place (I'm also using osx) and it is working fine; I can see the blank window with title hello world. – kucing_terbang Aug 06 '15 at 13:22
  • @kucing_terbang you used ProGuard on that JAR file with the same configuration I posted? What the hell! What version of ProGuard did you use? – Saturn Aug 06 '15 at 17:54
  • 1
    @Voldemort lol, sorry2, I thought I just need to run the JAR file. Anyway I think I know what the problem is. – kucing_terbang Aug 07 '15 at 04:00

1 Answers1

3

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[]);
}
kucing_terbang
  • 4,991
  • 2
  • 22
  • 28
  • Wow, thank you so much! I didn't know it made a difference to have used Eclipse! Do you know of other considerations I should take given that I am using Eclipse? (does NetBeans work better?) – Saturn Aug 07 '15 at 04:21
  • 1
    Well, I'm not so sure about any other configuration need to consider if using eclipse. As for Netbeans, I've tried using your configuration and it seems working fine. – kucing_terbang Aug 07 '15 at 05:28
  • @kucing_terbang what happened if someone uses Inteliji? – Panagiotis Drakatos Feb 25 '20 at 21:39
  • @PanagiotisDrakatos Hi, I'm not using mac anymore. So, I cannot say much what would happen if Intellij's used. But, maybe you can help to try it and improve the answer? – kucing_terbang Feb 26 '20 at 04:21