I wrote an application in eclipse, exported it with libraries extracted, compiled it into an exe using launch4j. It runs fine, but only when the main.jar is in the same parent folder. I'm not sure if it's something from launch4j messing it up, or if it's elsewhere. I've included a sample of the code
jvm options
--module-path /users/fishe/javafx-sdk-11.0.2/lib --add-modules javafx.controls,javafx.fxml -Djavafx.verbose=true -jar main.jar
SAMPLE
package src;
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.control.*;
import javafx.scene.layout.*;
import javafx.stage.Stage;
import java.io.File;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.Serializable;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.List;
public class Testing extends Application implements Serializable {
private static final long serialVersionUID = 8659236541611368787L;
protected Button buttonFileSave = new Button("Save");
protected Button buttonPrevious = new Button("<");
protected Button buttonNext = new Button(">");
protected TextArea textFileData = new TextArea();
protected TextField textFileMark = new TextField();
protected VBox boxMain = new VBox();
protected HBox boxToolbar = new HBox();
protected Scene primaryScene = new Scene(boxMain);
protected Stage primaryStage;
protected File fileDirectory = new File(System.getProperty("user.home") + "/Documents/fileEditor/data");
protected File fileDirectoryData = new File(System.getProperty("user.home") + "/Documents/fileEditor/data");
protected List<String> fileData;
protected List<String> fileMark;
protected int fileCount;
protected int file;
protected static class Data implements Serializable {
private static final long serialVersionUID = 17L;
protected List<String> fileData;
protected List<String> fileMark;
protected int fileCount;
protected int lastFile;
}
public void start(final Stage newStage) {
primaryStage = newStage;
primaryStage.setScene(primaryScene);
primaryStage.show();
boxMain.getChildren().addAll(textFileMark, textFileData, boxToolbar);
boxToolbar.getChildren().addAll(buttonPrevious, buttonFileSave, buttonNext);
buttonPrevious.setOnAction(event -> {
fileData.set(file, textFileData.getText());
fileMark.set(file, textFileMark.getText());
if (file > 0) {
file -= 1;
}
textFileData.setText(fileData.get(file));
textFileMark.setText(fileMark.get(file));
});
buttonNext.setOnAction(event -> {
if (fileCount == file) {
fileData.add("");
fileMark.add("");
fileCount += 1;
}
file += 1;
textFileData.setText(fileData.get(file));
textFileMark.setText(fileMark.get(file));
});
buttonFileSave.setOnAction(event -> {
fileData.set(file, textFileData.getText());
fileMark.set(file, textFileMark.getText());
final Data saveData = new Data();
saveData.fileData = fileData;
saveData.fileMark = fileMark;
saveData.fileCount = fileCount;
saveData.lastFile = file;
save(saveData);
});
fileDirectory.mkdirs();
if (!fileDirectoryData.isFile()) {
final Data saveData = new Data();
saveData.fileData = new ArrayList<>();
saveData.fileMark = new ArrayList<>();
saveData.fileData.add("");
saveData.fileMark.add("");
saveData.lastFile = 0;
saveData.fileCount = 0;
save(saveData);
}
final Data loadData = (Data) load();
fileMark = loadData.fileMark;
fileData = loadData.fileData;
file = loadData.lastFile;
fileCount = loadData.fileCount;
textFileData.setText(fileData.get(file));
textFileMark.setText(fileMark.get(file));
}
protected Object load() {
Object oisReturn = null;
try (ObjectInputStream ois = new ObjectInputStream(Files.newInputStream(Paths.get(fileDirectoryData.toString())))) {
oisReturn = ois.readObject();
} catch(Exception e) {
System.out.println("Error on load: " + e);
e.printStackTrace();
}
return oisReturn;
}
protected void save(final Serializable data) {
try (ObjectOutputStream oos = new ObjectOutputStream(Files.newOutputStream(Paths.get(fileDirectoryData.toString())))) {
oos.writeObject(data);
} catch(Exception e) {
System.out.println("Error on save: " + e);
e.printStackTrace();
return;
}
}
public static void main(final String[] args) throws Exception{
launch(args);
}
}