Images aren't loading in .jar file - java

I am aware the question has been asked before. However, I have tried all the solutions and none seem to work. I have created a simple GUI program using javax.swing, and of course it works perfectly in IntelliJ. However, its consequent jar file has quite a few issues. First and foremost, none of the images even display. I have been importing them as so:
img = new ImageIcon((ImageIO.read(new File("image_name.png"))));
I found a solution suggesting I use:
BufferedImage img = ImageIO.read(new FileInputStream("res/name.png"));
However, not only does it not load in the jar, it takes 5 seconds for the program to even launch in the compiler.
This is getting extremely frustrating, making this an executable.
If it's of any use, the JButton components on the jar also don't seem to work. Whenever you click them, they remain pressed but nothing happens further.
I understand this isn't loads of info, but I would nontheless appreciate any help you can give. Thanks!

Related

Is it possible to embed JDK and other requirements into runnable jar?

Two days ago I got close to finishing a java program that wrote, I wanted to let some friends play with it for a bit to find flaws etc. I created a runnable jar trough Eclipse and then I used Launch4j to transform the runnable jar into a .exe
It worked perfectly fine on my pc, but any other user couldn't open it. After a while I discovered that when people would install java JDK, it worked for about 40%, but this atleast pushed me in the direction of what the flaw is. Is there a way to (automaticly?) embed everything in the jar that my program is in need of? Or is there a way to determine what exactly it all is that people need for the .exe to run and what they are missing by running some pre-checks that can re-direct them to links where they can download this? I can't seem to find much on this subject, so I probably made a mis assumption somewhere, any help/clearance is appreciated!
There is a new tool called jpackage, which should do what you want.
Also see the User's Guide.

Eclipse Crashing when Associating External Editors

I've recently been attempting to set up SceneBuilder but suddenly my copy of Eclipse crashes pretty much instantly when I attempt to try and associate any external editor with a file type (not just XFXML). I've done some research and this seems to be the only page I can find talking about the issue, but I'm not sure how to take the advice therein.
I've linked the error log generated by these crashes. If anyone has experience something similar or has any idea how to go about troubleshooting this issue I'd greatly appreciate your input!
//I've included this code block to allow the pastebin link to work. There have
not been any issues with programming as the IDE won't operate as expected.

How to Recompile Deconstructed EXE

I had some software developed on oDesk about a year ago. What I get back is a java based .EXE
It runs as a standalone without any sort of installation. The problem is they screwed up some graphics for the buttons, it didn't bother me at the time, because I got what I wanted, a minimal viable product that got the job done.
With that said, it's been bothering me for a while, and when I reach back out to the guy - I can't get him.
I used 7zip to open the .EXE and extracted all the contents. I found where the buttons were and fixed them, obviously trying to drag it into 7Zip in the specified location isn't going to work.
How do I go about recompiling everything?
I'm new to all this, so if you need any additional information, please don't hesitate to ask. I just want this thing to look as I intended.

Animated GIF leads to SplashScreen being null

I know this is probably close to a duplicate of this thread: Animated GIF in Splashscreen
But since it seems unanswered and I can't comment on it or anything I'm sorry to repost this but it would be awesome if someone could give me an answer.
I am making a game and this game takes quite a lot of time to start. Therefore I want to give the user feedback during the loading screen so he knows the application hasn't crashed. That's why I use the SplashScreen API from java 7.
In eclipse, when I run my application using the following configuration in VM Arguments, SplashScreen.getSplashScreen() returns null.
-splash:src/aapplication/Splash.gif
But when I use this configuration, it works fine (I have to files in the same package, one is Splash.png and the other Splash.gif):
-splash:src/aapplication/Splash.png
In a jar file (in MANIFEST.MF), this doesn't work:
SplashScreen-Image: aapplication/Splash.gif
While this does:
SplashScreen-Image: aapplication/Splash.png
My GIF is about 1Mb in size while the PNG is 50kb.
Can anyone explain to me why does the GIF can't even be loaded while the PNG does (I know it's not the path since they have the same)?
Everywhere I looked, it said it should work just as fine as for PNGs.
Thanks for your help!
I think you'll find that the problem comes down to two things...
Using the command line parameter (-splash), Java expects the image to be a file on the file system, whereas the manifest file expects it to be an embedded resource.
Java doesn't seem capable of playing optimised gifs, that is gifs whose frames represent the difference between the last and current frame, instead of a complete image (as far as the splash screen goes).
I tried using
and
The first image failed, but the second worked, the difference, as near as I can tell, is the first is optimised and the second is not...

Java save method stops working when .jar is moved

I’m coding my first java Desktop application using eclipse and I’m having difficulty deploying it. My project uses JavaFX2 and the e(fx)clipse plugin, the latter is in charge of generating the build.xml file.
ABOUT THE APP
The app, amongst other things, provides an interface where the user can create categories and associate these with labels. All modifications are saved within a single file (the data is stored as a serialized object.) and are supposed to be loaded automatically when the app is reopened.
THE PROBLEM
When build as an executable jar using a .xml file (Ant), the project runs fine within the folder where it gets created. I can run my application, modify data, and save everything once I’m done. When I reopen the app everything gets loaded as it should.
However, if I copy the folder elsewhere, I can no longer save any data. Everything else seems to work; the app will even load the data that was saved when it was in its original directory. I assume that this means that the app can still see the data file, but can no longer write to it.
WHAT IVE TRIED
I’ve read that warping the .jar around an installer may fix the issue; however, one of the goals for the app was to make it as portable as possible. Meaning that it should be possible to move it around from one directory/computer to another, ideally in a manner that is cross-platform friendly, without the need of installing it.
I’ve tried various things to get it to work. I’ve shifted the whole project to Netbeans (to produce a different build), I’ve modified the save/load method file path to make sure the right document is targeted, I’ve tweaked the .xml file the best I could, and I even tried to build the project using the javafxpackager. No matter what I do, when the build works, I get the same results.
Right now, I’m thinking that there may still be something wrong with the .xml file but I’ve got a hard time understanding how to modify it. Perhaps the problem is somehow caused by the way the data gets serialized. I know that at one point when I moved things around within my project, both the save and load methods could no longer interact with the data.
What I find strange is that when the project is moved the load method still works. If the problem is caused by changing the file path, how come only the save method ceases to function?
APP FILES AND STRUCTURE
+src
-(Main.java)
+controller
-(misc.javas)
+modelData
-(Library.java) -->the object that is serialized
+modelLogic
-(misc.javas)
+view
-(misc.javas)
+files
-(library.data) -->the file where the serialized object is saved
+lib
-(empty.empty)
So, is their anything I can do to solve my problem?
Thanks in advance.
In the end, the problem was rather simple. When I was moving the app, I was always putting it on the desktop, which, in the case of my PC, sets by default all content as read-only (in relation to the app's privileges). Because of this, the app could not modify any files that were within folders on the desktop.
Therefore, all I had to do was to move the app to another directory, such as C:\randomFolder, and the problem was solved.
So, if anyone has a similar problem, moving the app elsewhere may be the solution. Alternatively, taking full ownership of the folder and its content can also work.
When possible, it is usually better to have the app ask its user for a specific location to save its data.

Categories