0

How can I create .exe with modifiable .txt dependencies (sources, dictionaries) from JavaFX program? I want to modify dependency's content in the future.

I tried Launch4J, but I dont find any options which help me to make .exe with modifiable .txt dependencies. Anyone can make it in Launch4J or in other technology?

Simple examples:

TestApplication:

public class TestApplication extends Application {

    @Override
    public void start(Stage stage) throws Exception {
        Parent root = FXMLLoader.load(getClass().getResource("/test.fxml"));
        stage.setTitle("Test");
        stage.setScene(new Scene(root));
        stage.show();
    }
}

TestController:

public class TestController {
    @FXML
    public Button text1Button;
    @FXML
    public Button text2Button;
    @FXML
    public TextArea textArea;

    public void printText1(ActionEvent actionEvent) {
        List<String> lines=readFromFile("src/main/resources/text1");
        StringBuilder sb = new StringBuilder();
        lines.forEach(l->sb.append(l).append("\n"));
        textArea.setText(sb.toString());
    }

    public void printText2(ActionEvent actionEvent) {
        List<String> lines=readFromFile("src/main/resources/text2");
        StringBuilder sb = new StringBuilder();
        lines.forEach(l->sb.append(l).append("\n"));
        textArea.setText(sb.toString());
    }

    private List<String> readFromFile(String filePath){
        List<String> lines = new ArrayList<>();
        try{
             lines=Files.readAllLines(Paths.get(filePath));
        }
        catch (IOException ioe){
             ioe.printStackTrace();
        }
        return lines;
    }
}

test.fxml:

<AnchorPane prefHeight="400.0" prefWidth="600.0" xmlns="http://javafx.com/javafx/16" xmlns:fx="http://javafx.com/fxml/1" fx:controller="org.example.TestController">
   <children>
      <Button fx:id="text1Button" layoutX="180.0" layoutY="43.0" mnemonicParsing="false" onAction="#printText1" text="Text1" />
      <Button fx:id="text2Button" layoutX="374.0" layoutY="43.0" mnemonicParsing="false" onAction="#printText2" text="Text2" />
      <TextArea fx:id="textArea" layoutX="114.0" layoutY="112.0" prefHeight="200.0" prefWidth="371.0" />
   </children>
</AnchorPane>

trashgod
  • 203,806
  • 29
  • 246
  • 1,045
  • Take a look at the Packaging Tool ( https://docs.oracle.com/en/java/javase/17/jpackage/packaging-overview.html ). – Queeg Jun 25 '22 at 21:29
  • 2
    Don’t make them resources. Instead place the files in the [input directory](https://docs.oracle.com/en/java/javase/17/docs/specs/man/jpackage.html#options-for-creating-the-application-image) and the files will be included in your [application image](https://docs.oracle.com/en/java/javase/14/jpackage/packaging-overview.html#GUID-DAE6A497-6E6F-4895-90CA-3C71AF052271) and can be read and written by your application. – jewelsea Jun 25 '22 at 22:03
  • 2
    Or, you can read the resources, then write them out to a [writable file](https://stackoverflow.com/questions/10308221/how-to-copy-file-inside-jar-to-outside-the-jar). – jewelsea Jun 25 '22 at 22:05

0 Answers0