I inherited a project that was using Ant in Netbeans and was last worked on over a year ago. Development is on a Mac, with the aim of deploying to Mac, Linux and Windows.
The last compiled JAR file can run with a recipe like this:
`%java -Djava.library.path=$HOME/Downloads/javafx-sdk-17.0.9/lib -jar /Users/philip/Downloads/genesis2.jar`
If I run it with a newer JavaFX SDK, javafx-sdk-20.0.2 also works. However if I use v21, I get a spew of exceptions like
Exception in thread "JavaFX Application Thread" java.lang.UnsatisfiedLinkError: 'long com.sun.glass.ui.mac.MacAccessible._createGlassAcc essible()'
I tried to set up a build environment but Netbeans objected to setting it up with Ant, whether I opened the existing project or tried to start from scratch, because the existing Java platform does not support JavaFX. I tried using the OpenJDK but the interface for changing the Java platform was broken.
So: give up on that and change to using Maven.
That sort of worked but I could bet get a build that would run with the same recipe:
`% java -Djava.library.path=$HOME/Downloads/javafx-sdk-21/lib target/Genesis2JavaFX-2.0-SNAPSHOT.jar
Error: Could not find or load main class target.Genesis2JavaFX-2.0-SNAPSHOT.jar
Caused by: java.lang.ClassNotFoundException: target.Genesis2JavaFX-2.0-SNAPSHOT.jar`
I found out how to package all dependencies and that does run, after fixing a few things. For example, whenever there was code like
X.getClass().getResource(Y);
I changed it to
X.getClass().getClassLoader().getResource(Y);
I am not sure why this worked in the former build but not now.
Another issue. The Ant build was able to create a JAR file that preserved the subdirectory structure whereas with Maven, I could only find a way to package all resources at the top-level:
`<resources>
<resource>
<directory>src/main/java/org/h3abionet/genesis/view</directory>
</resource>
<resource>
<directory>src/main/java/org/h3abionet/genesis/image</directory>
</resource>
<resource>
<directory>src/main/java/org/h3abionet/genesis/help</directory>
</resource>
<resource>
<directory>src/main/java/org/h3abionet/genesis/css</directory>
</resource>
</resources>
`
To make all this work, I had to change all references to directory structure to current directory, e.g. change
view/AdmixtureOptions.fxml
to
view/Main.fxml
etc. throughout the code.
If I inspect the contents of the JAR file, the earlier build does preserve the directory structure.
Questions:
1. Is there a way I can configure Maven in pom.xml to preserve the directory structure when copying resources (non-code files) to JAR?
2. Is there a way in Netbeans using Maven to create a JAR file that can run on the command line with a pointer to a library as the old Ant build did?
3. Are there any pointers to best practice in using Maven + Netbean for JavAFX projects?
PS: some pointers to how to format code or scripts not in Java would be helpful too…
--- Update ---
That sort of worked but I could bet get a build that would run with the same recipe:
Should be
That sort of worked but I could *not* get a build that would run with the same recipe:
Seems that this forum dislikes my browsers as some features liked editing posts are broken.