温馨提示:本文翻译自stackoverflow.com,查看原文请点击:Maven - JavaFX ProGuard app is not working after obfuscate
javafx maven obfuscation proguard classnotfoundexception

Maven - 混淆后,JavaFX ProGuard应用程序无法正常工作

发布于 2020-04-15 11:14:44

我在尝试混淆我的javaFX应用程序4天而没有成功后写了这个问题...

关于项目:
JDK:Azul JavaFX 8.42.0.23
构建工具:Maven
Ide:Intelij
ProGuard版本:6.2.2

问题是什么:
我无法正确混淆我的代码。构建应用程序后,既可以原生运行,也可以像胖子一样正常运行。经过混淆后,我有以下错误:

 javafx.fxml.LoadException: 
file:/C:/Users/pawel/Desktop/X/X/target/X-1.3-jar-with-dependenciesOBF.jar!/fxml/MainWindow.fxml

    at javafx.fxml.FXMLLoader.constructLoadException(FXMLLoader.java:2601)
    at javafx.fxml.FXMLLoader.importClass(FXMLLoader.java:2848)
    at javafx.fxml.FXMLLoader.processImport(FXMLLoader.java:2692)
    at javafx.fxml.FXMLLoader.processProcessingInstruction(FXMLLoader.java:2661)
    at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2517)
    at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2441)
    at javafx.fxml.FXMLLoader.load(FXMLLoader.java:2409)
    at c.b.g(SourceFile:227)
    at c.b.i(SourceFile:36)
    at c.b$5.a(SourceFile:194)
    at c.b$5.a(SourceFile:183)
    at com.d.a.a$1.a(SourceFile:32)
    at com.sun.javafx.application.PlatformImpl.lambda$null$5(PlatformImpl.java:295)
    at java.security.AccessController.doPrivileged(Native Method)
    at com.sun.javafx.application.PlatformImpl.lambda$runLater$6(PlatformImpl.java:294)
    at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:95)
    at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
    at com.sun.glass.ui.win.WinApplication.lambda$null$3(WinApplication.java:177)
    at java.lang.Thread.run(Thread.java:748)
Caused by: java.lang.ClassNotFoundException
    at javafx.fxml.FXMLLoader.loadType(FXMLLoader.java:2899)
    at javafx.fxml.FXMLLoader.importClass(FXMLLoader.java:2846)
    ... 17 more

当前的progard设置:

-injars 'C:\Users\pawel\Desktop\PROJEKTY JAVA\x\target\jfx\native\x\app\x-1.3-jfx.jar'
-outjars 'C:\Users\pawel\Desktop\PROJEKTY JAVA\x\target\jfx\native\x\app\x-1.3-jfxOBF.jar'
-injars 'C:\Users\pawel\Desktop\PROJEKTY JAVA\x\target\x-1.3-jar-with-dependencies.jar'
-outjars 'C:\Users\pawel\Desktop\PROJEKTY JAVA\x\target\x-1.3-jar-with-dependenciesOBF.jar'

-libraryjars 'C:\Program Files\Java\jre1.8.0_181\lib\rt.jar'
-libraryjars 'C:\Program Files\Java\jre1.8.0_181\lib\javaws.jar'
-libraryjars 'C:\Program Files\Java\jre1.8.0_181\lib\ext\jfxrt.jar'

-verbose
-dontnote
-dontwarn
-dontoptimize
-dontshrink

# Keep names of fields marked with @FXML, @Inject and @PostConstruct attributes
-keepclassmembers class * {
  @javafx.fxml.FXML *;
  @javax.inject.Inject *;
  @javax.annotation.PostConstruct *;
}

# Keep entry-point class
-keep class main.Main {
  public static void main(java.lang.String[]);
}

# Keep all annotations and meta-data
-keepattributes *Annotation*,Signature,EnclosingMethod

# Save meta-data for stack traces
-printmapping out.map
-renamesourcefileattribute SourceFile
-keepattributes SourceFile,LineNumberTable

# Rename FXML files together with related views
-adaptresourcefilenames **.fxml,**.png,**.css,**.properties
-adaptresourcefilecontents **.fxml
-adaptclassstrings

另外,我检查了来自stackoverflow的建议:
将FXML文件的所有名称更新为以大写字母
开头将所有类名称的列表添加为classobfuscationdictionary

其他信息,我有应用程序的预加载器(带有徽标和加载栏的单个fxml),并且正在运行。问题是当我尝试加载fxml包含include标签的应用程序主窗口时。

<?xml version="1.0" encoding="UTF-8"?>

<?import com.jfoenix.controls.JFXProgressBar?>
<?import javafx.geometry.Insets?>
<?import javafx.scene.control.ScrollPane?>
<?import javafx.scene.layout.BorderPane?>
<?import javafx.scene.layout.HBox?>
<?import javafx.scene.layout.VBox?>

<BorderPane maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" prefHeight="2000.0" prefWidth="2000.0" style="-fx-background-color: #323234;" styleClass="main-container" stylesheets="@../css/mainStyles.css" xmlns="http://javafx.com/javafx/8.0.171" xmlns:fx="http://javafx.com/fxml/1" fx:controller="controller.MainScreenController">
   <children>
      <VBox layoutX="300.0" layoutY="31.0" prefHeight="358.0" prefWidth="289.0">
         <children>
            <HBox alignment="CENTER" spacing="20.0" VBox.vgrow="ALWAYS">
               <padding>
                  <Insets bottom="10.0" left="10.0" right="10.0" top="10.0" />
               </padding>
               <VBox.margin>
                  <Insets />
               </VBox.margin>
            </HBox>
            <HBox prefHeight="100.0" prefWidth="200.0" />
            <HBox prefHeight="100.0" prefWidth="200.0" />
         </children>
      </VBox>
   </children>
   <left>
      <fx:include source="menus/MenuLeft.fxml" BorderPane.alignment="TOP_LEFT" />
   </left>
   <top>
      <fx:include source="menus/MenuTop.fxml" />
   </top>
   <bottom>
      <JFXProgressBar fx:id="progressBar" maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" minHeight="3.0" BorderPane.alignment="CENTER" />
   </bottom>
   <center>
      <ScrollPane fitToHeight="true" fitToWidth="true" BorderPane.alignment="TOP_LEFT">
         <content>
            <VBox fx:id="vContainer" maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" />
         </content>
      </ScrollPane>
   </center>
</BorderPane>

查看更多

提问者
Paweł
被浏览
211
Paweł 2020-02-04 19:08

经过5天的寻找我有解决方案。

问题是由javax包外部的fxml文件中的导入引起的。要解决此问题,我们必须:

选中以下复选框:
在此处输入图片说明

使用方法和字段以及两个星号将导入添加为“保留” **:
在此处输入图片说明

在此处输入图片说明