Proguard के साथ कस्टम नियंत्रण और कस्टम StringProperty

0

सवाल

मैं करना चाहते हैं का उपयोग करने के लिए proguard के साथ एक javafx आवेदन के साथ कुछ कस्टम नियंत्रण ।

  1. मैं एक कस्टम नियंत्रण में शामिल है कि एक poperty

    StringProperty  textProperty = new SimpleStringProperty(this,"text");
    public final StringProperty textProperty() {return textProperty;}
    public final String getText() {return textProperty().get();}
    public final void setText(String text) { textProperty.set(text);}
    
  2. मैं का उपयोग मेरे कस्टम नियंत्रण में एक fxml फ़ाइल.

    <Menu [...] text="logo"/>
    

मेनू वर्ग है मेरे कस्टम नियंत्रण सभी आयात बयान ठीक कर रहे हैं ।

  1. मेरे पोम फाइल मैं रखने StringProperties के रूप में है.

     <option>-keepclassmembers class * extends javafx.scene.control.Control {javafx.beans.property.StringProperty *;
                 public final javafx.beans.property.StringProperty *;
                 public final java.lang.String *;
                 public final void *;
     }</option>
    

मैं इस त्रुटि मिलती है जब मैं आवेदन शुरू करते हैं.

 Caused by: com.sun.javafx.fxml.PropertyNotFoundException: Property "text" does not exist or is read-only.

संपादित करें एमआरई

पोम

 <project xmlns="http://maven.apache.org/POM/4.0.0"  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
   xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">

   <modelVersion>4.0.0</modelVersion>
   <groupId>com.example</groupId>
   <artifactId>Example</artifactId>
   <packaging>jar</packaging>
   <version>1.0-SNAPSHOT</version>

   <name>Example</name>
  <url>http://maven.apache.org</url>

  <properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <maven.compiler.source>11</maven.compiler.source>
    <maven.compiler.target>11</maven.compiler.target>
  </properties>

  <dependencies>

        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.11</version>
            <scope>test</scope>
        </dependency>

       <!-- Java Fx libraries -->
       <dependency>
            <groupId>org.openjfx</groupId>
            <artifactId>javafx-controls</artifactId>
            <version>16</version>
       </dependency>
       <dependency>
           <groupId>org.openjfx</groupId>
           <artifactId>javafx-fxml</artifactId>
           <version>16</version>
      </dependency>

 </dependencies>

 <build>
 <plugins>

     <plugin>
         <groupId>com.github.wvengen</groupId>
         <artifactId>proguard-maven-plugin</artifactId>
         <version>2.5.1</version>
        <executions>
            <execution>
                 <phase>package</phase>
                 <goals>
                     <goal>proguard</goal>
                </goals>
            </execution>
         </executions>
    <configuration>
        <obfuscate>true</obfuscate>
        <optimize>true</optimize>
        <shrink>true</shrink>
        <injar>${project.build.finalName}.jar</injar>
        <outjar>${project.build.finalName}.jar</outjar>
        <includeDependency>true</includeDependency>
        <options>
            <option>-keep public class com.example.Main { *; }</option>
            <option>-keep public class com.example.Launcher { *; }</option>
            <option>-keepnames class com.example.custombuttons.*</option>
            <option>-adaptresourcefilecontents **.fxml </option>
            <option>-dontnote jdk.internal.jimage.*</option>
            <option>-dontnote module-info</option>
            <option>-dontnote jdk.internal.jrtfs.*</option>
            <option>-dontnote jdk.internal.jimage.decompressor.*</option>
            <option>-classobfuscationdictionary ${project.basedir}/keywords.txt</option>
            <option>-keepclassmembers class * extends javafx.scene.control.Control {javafx.beans.property.StringProperty *;
                public final javafx.beans.property.StringProperty *;
                public final java.lang.String *;
                public final void *;
            }</option>

        </options>
        <libs>
            <lib>${java.home}/jmods/java.base.jmod</lib>
            <lib>${java.home}/jmods/java.xml.jmod</lib>
            <lib>${java.home}/jmods/java.datatransfer.jmod</lib>
            <lib>${java.home}/jmods/java.desktop.jmod</lib>
        </libs>
        <archive>
            <manifest>
                <mainClass>Main</mainClass>
                <packageName>com.example</packageName>
            </manifest>
        </archive>
    </configuration>

  </plugin>

  <plugin>
    <artifactId>maven-shade-plugin</artifactId>
    <executions>
        <execution>
            <phase>package</phase>
            <goals><goal>shade</goal></goals>
            <configuration>
                <transformers>
                    <transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
                        <mainClass>com.example.Launcher</mainClass>
                    </transformer>
                </transformers>
            </configuration>
        </execution>
    </executions>
  </plugin>

</plugins>
  </build>
</project>

लांचर वर्ग.

package com.example;
import javafx.application.Application;
public class Launcher
{
    public static void main(String[] args) {
        Application.launch(Main.class);
    }
}

मुख्य वर्ग

package com.example;
import com.example.custombuttons.Menu;
import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.scene.Scene;
import javafx.scene.layout.AnchorPane;
import javafx.stage.Stage;

public class Main extends Application{

    Menu menu;

    @Override
    public void start(Stage primaryStage) throws Exception {

        AnchorPane pane;
        FXMLLoader mainLoader = new FXMLLoader(getClass().getClassLoader().getResource("layouts/main.fxml"));
        pane = mainLoader.load();
        Scene scene = new Scene(pane, 600, 445);
        primaryStage.setScene(scene);
        primaryStage.show();
        menu = (Menu) scene.lookup("#menu");
    }
}

मेनू वर्ग

package com.example.custombuttons;

import javafx.beans.property.SimpleStringProperty;
import javafx.beans.property.StringProperty;
import javafx.scene.control.Control;
import javafx.scene.control.Skin;

public class Menu extends Control{

    StringProperty  textProperty = new SimpleStringProperty(this,"text");
    public final StringProperty textProperty() {return textProperty;}
    public final String getText() {return textProperty().get();}
    public final void setText(String text) { textProperty.set(text);}

    public Menu() {
        super();
    }

    public Menu(String text){
        super();
    }

    @Override protected Skin<?> createDefaultSkin() {
        return new MenuSkin(this);
    }
}

MemuSkin वर्ग

package com.example.custombuttons;

import javafx.scene.control.SkinBase;

public class MenuSkin extends SkinBase<Menu> {

    String text;

    public MenuSkin(Menu control) {
        super(control);
        text = control.getText();
    }
}

मुख्य.fxml

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

    <?import com.example.custombuttons.Menu?>
    <?import javafx.scene.layout.AnchorPane?>

    <AnchorPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="400.0" prefWidth="600.0" >
       <children>
            <Menu layoutX="238.0" layoutY="224.0" prefHeight="63.0" prefWidth="125.0" text="menu" />
       </children>
</AnchorPane>

स्टैक ट्रेस

Caused by: javafx.fxml.LoadException:
file:C:/USER/example/target/Example-1.0-SNAPSHOT.jar!/layouts/main.fxml:10
[...]

 Caused by: com.sun.javafx.fxml.PropertyNotFoundException: Property "text" does not exist or is read-only.
    at javafx.fxml.FXMLLoader$Element.processValue(FXMLLoader.java:357)
    at javafx.fxml.FXMLLoader$Element.processPropertyAttribute(FXMLLoader.java:334)
    at javafx.fxml.FXMLLoader$Element.processInstancePropertyAttributes(FXMLLoader.java:244)
    at javafx.fxml.FXMLLoader$ValueElement.processEndElement(FXMLLoader.java:777)
    at javafx.fxml.FXMLLoader.processEndElement(FXMLLoader.java:2924)
    at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2639)
controls javafx maven proguard
2021-11-16 07:12:11
1

सबसे अच्छा जवाब

1

मैंने पाया है कि मेरी वाइल्ड कार्ड सही नहीं थीं । चाहिए किया गया है, एक सामान्य तरीका है:

<option>-keepclassmembers class * extends javafx.scene.control.Control {
    javafx.beans.property.* *;
    void set*(***);
    boolean is*();
    *** get*();
}</option>

यह होगा, वास्तव में, इस समस्या को ठीक के लिए सभी गुण में कस्टम नियंत्रण फ़ाइलें.

2021-11-17 20:11:22

अन्य भाषाओं में

यह पृष्ठ अन्य भाषाओं में है

Русский
..................................................................................................................
Italiano
..................................................................................................................
Polski
..................................................................................................................
Română
..................................................................................................................
한국어
..................................................................................................................
Français
..................................................................................................................
Türk
..................................................................................................................
Česk
..................................................................................................................
Português
..................................................................................................................
ไทย
..................................................................................................................
中文
..................................................................................................................
Español
..................................................................................................................
Slovenský
..................................................................................................................

इस श्रेणी में लोकप्रिय

लोकप्रिय सवाल इस श्रेणी में