mabe02 / lanterna

Java library for creating text-based GUIs
GNU Lesser General Public License v3.0
2.27k stars 242 forks source link

Broken JAR artifact #459

Closed tpazz closed 4 years ago

tpazz commented 4 years ago

I am using the lanterna library for a project I am working on that works perfectly inside the IDE when I click on 'Run main' but when trying to export it as an executable JAR artifact, it produces undesirable results. I have edited the library so that I have my own custom padlock icon, changed the title of the terminal frame and set the resizable option to false.

For example, here is what my start screen looks like from within Intellij (correct):

correct

Running the executable JAR (incorrect):

incorrect

Both the edited title and non-resizable frame are apparent in the executable JAR, but the custom icon is not. Additionally, selecting any item from the action list box will cause it to disappear and not display the page it should.

Selecting 'Terminal' for example should show this (within Intellij):

expected

But instead does this (executable JAR):

incorrect2

This is my configuration for creating an artifact:

projectsruct

Then I would go Build -> Build Artifacts -> Build

In summary, the project works as expected from within Intellij, but appears to be broken when running it as an executable JAR. Any help would be greatly appreciated!

jrb0001 commented 4 years ago

This sounds a lot more like you have a problem with your packaging process rather than a bug in lanterna. Did you extract the resulting jar and check that everything is where you expect it to be? Especially the icon file.

tpazz commented 4 years ago

It appears that the icon is nowhere to be found in the resulting jar, how would I be able to package it correctly?

jrb0001 commented 4 years ago

I can't really help you with that. I always used maven directly and I never had any problems with maven-assembly-plugin but there are many ways to do packaging, depending on your exact requirements.

avl42 commented 4 years ago

I have no specific experience with intellij, but most IDEs have a way to declare source folders, and automatically copy all non-java files within that folder to the target.

I don't know, how you specify the icon. Did you set it up in an intellij dialog, or did you write java code to load the file and pass it to some setApplicationIcon (or whatever its name) method?

tpazz commented 4 years ago

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 recieving 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. Thank you for the responses!

mabe02 commented 4 years ago

Great, sounds like we can close this!