I am trying to build a JAR artifact for my project which relies on one external library nbvcxz and one imported library lanterna:
When adding the JAR under Artifacts in Project Structure, JAR -> from modules with dependencies is used:
The additional features I have added to the imported library are:
Compiling the SNAPSHOT jar of the lanterna library works as expected when running the application from within the IDE, with all of the above features and the external library working perfectly. However when I build and run the JAR artifact, the title of the window is updated and the window itself is not resiable, but the customised icon is not shown and selecting any element on the initial start screen will cause it to break.
Behavior when running from within Intellij (correct):
Behaviour when running the JAR artifact (incorrect):
What I find interesting is that the built artifact is using the lanterna library as the initial screen is displayed (lanterna is a semi-graphical library used for text-based GUIs), but is somehow omitting some of the changes I have made to it. The nbvcxz library is imported from maven and works as expected.
Any help would be greatly appreciated!
I found the problem - I was using a text file that was not specified in the source folder, so the packaged JAR was unable to find it during execution which was causing the break as soon as I selected any item from the action list box. Annoyingly, I was not receiving any error message in the console despite catching and printing any exceptions. It wasn't until I added
JOptionPane.showMessageDialog(null, t.getClass().getSimpleName() +": " + t.getMessage()); throw t; }}
that told me it couldn't find the file. I have since removed the file because it was being used to R/W which is generally advised against as JAR files are supposed to be archives that are not supposed to change.
The icon not showing was due to a similar problem in that it was also not included in the source folder but neither was it being properly referenced. After moving to the correct location and adding
ImageIcon img = new ImageIcon(this.getClass().getResource("/pwdIcon.png"));
it worked fine.
I guess I was able to kill two bugs with one stone here. I was unaware of how JAR files exactly packaged things so I assumed if it works in the IDE then it would work as a JAR without the use of source folders and proper referencing.