Reputation: 279
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:
primary
package?<mainClass>com.primary.Drag</mainClass>
Upvotes: 1
Views: 123
Reputation: 578
Answer:
Your package name should be like com.primary.******
Answer:
Always make sure that you are trying to load firstlaunch .xml from the class which is located in same package where that xml is kept. Means class which you wrote the loading code and xml file should be in same package
Answer:
If you package name corrected to com.primary , your main class Drag will correctly added by maven
Upvotes: 1