My code has gotten quite large and so I've decided to build a runnable JAR to see how it's done. I probably should've tried sooner because I'm getting 2 different errors related to the project structure, first is the "no main manifest attribute error" when trying to run the JAR from command prompt. Double-clicking the JAR does nothing (Win7). The second issue is related to the FXMLLoader explained lower down.
I followed the steps here to build the JAR, which involved moving all Maven files into the JAR directory. The compiled JAR gave me the manifest error, so I followed this which adds a Maven plugin in my pom.xml
file. The error might be caused by a wrong naming convention with the line <mainClass>com.primary.Drag</mainClass>
where primary
is the package and Drag
is my Drag.java file (class) which has the main
method.
Inititally I was using the default package but read that this is not recommended for larger projects, so I put all my files into "primary". Here is my current hierarchy as shown in IntelliJ:
The problem is that ever since I created the "primary" package, I can no longer even compile the program via IntelliJ, let alone build a runnable JAR. This is due by the second error I mentioned, which is java.lang.IllegalStateException: Location is not set.
on this line within primary/Drag.java
:
FXMLLoader loader = new FXMLLoader(getClass().getClassLoader().getResource("firstlaunch.fxml"));
It used to work with the default package, but not anymore.
I tried replacing firstlaunch.fxml
with /primary/firstlaunch.fxml
and /resources/firstlaunch.fxml
(with and without moving resources into primary package) but no luck.
3 Related Questions:
- Is my project structure incorrect?
- How do I reference the fxml file from the
primary
package? - Is this what I should write in Maven's mainClass tags?
<mainClass>com.primary.Drag</mainClass>