ProGuard 在我的 JavaFX 应用程序中找不到主要方法
ProGuard can't find the main method in my JavaFX application
我做了一个简单的 JavaFX 程序,我似乎无法用 ProGuard 混淆它。
我关注了这个问题:Obfuscating JavaFX application
这是我的代码:
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();
}
}
根据那个问题的回答,这应该是我的配置文件:
-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[]);
}
但是在尝试 运行 .JAR 程序时出现以下错误:
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
根据另一个问题:Error: Main method not found in class Calculate, please define the main method as: public static void main(String[] args)
我需要我的 class 有一个带正文的 main
方法。显然我已经明白了,正如您从我上面的代码中看到的那样。
那我做错了什么?我正在使用 Java 8.
问题似乎是因为你没有使用 MANIFEST.MF
来指定哪个是主要的 class(我认为这是因为你通过 eclipse exporter 导出了 JAR)
您可以通过尝试在配置中添加这一行来解决这个问题。
-keepclasseswithmembers public class com.javafx.main.Main, org.eclipse.jdt.internal.jarinjarloader.*, HelloWorld {
public static void main(java.lang.String[]);
}
我做了一个简单的 JavaFX 程序,我似乎无法用 ProGuard 混淆它。
我关注了这个问题:Obfuscating JavaFX application
这是我的代码:
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();
}
}
根据那个问题的回答,这应该是我的配置文件:
-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[]);
}
但是在尝试 运行 .JAR 程序时出现以下错误:
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
根据另一个问题:Error: Main method not found in class Calculate, please define the main method as: public static void main(String[] args)
我需要我的 class 有一个带正文的 main
方法。显然我已经明白了,正如您从我上面的代码中看到的那样。
那我做错了什么?我正在使用 Java 8.
问题似乎是因为你没有使用 MANIFEST.MF
来指定哪个是主要的 class(我认为这是因为你通过 eclipse exporter 导出了 JAR)
您可以通过尝试在配置中添加这一行来解决这个问题。
-keepclasseswithmembers public class com.javafx.main.Main, org.eclipse.jdt.internal.jarinjarloader.*, HelloWorld {
public static void main(java.lang.String[]);
}