Eclipse Project Wont Work After changing to executable jar file? - java

i have been having a problem for a while where when i export my eclipse project into an executable jar file it wont run correctly. I think the resources folder is the source of this problem but i'm not sure, because all that happens whenever i run it is the JFrame pops up. for some reason i cant take screenshots because my computer is a piece of crap, but I've shared what i know. thank you, all help is much appreciated!
UPDATE:
this has been tagged as duplicate, but i have tried their methods and it wouldn't work. i need instructions specific for my situation.This is the link to the picture of my file explorer took a little while back when i had the same problem, because i cant take the picture now it is not up to date.

Related

Exporting java body with imagine into jar w/ images

I wrote code that works whenever i run in Eclipse, but whenever i try to export it into a runnable Jar, my images dont show up.
For my images this is the code being used pic1=ImageIO.read(FourCournersRunner.class.getResource("/Images/1.png"));
When exporting the project I've chosen "Package required libraries into generated JAR":
Please also show the code where you display the image in GUI, the problem might lie in there.
Did you also package the Images folder to the .jar file?
The problem might be caused by the way you set up build path too.
In short, I don't think the code you provide right now can reproduce the problem.

My Jar Files Won't Open, and My Motivation to Solve the Issue is Dying

Sorry for the crappy title.
I've been building games in Java since February, teaching myself as I go along. Recently, I worked on a dungeon crawler for over a month using Java FX, and I was quite pleased with the result. I was, in fact, so pleased with the game that I decided to publish it on my Game Jolt account, which I had previously used to produce games I made in Visual Basic.
I went through the process of building a .jar file as an Artifact in Intellij IDEA, and eventually, one was produced. When I tried to run the file however, it started to open but then crashed. I couldn't figure out why even after rummaging through my Console looking for errors to no avail (I'm using a Mac,) and after attempting to open the jar on a PC I found around the house, I concluded it was an error with the app. I soon found that I hadn't signed the jar, causing a security error, so I went through the process of trying to self-sign. When I tried to do that, it worked, but the jar still wouldn't open.
Evidently, there is a underlying issue with my app that needs to be remedied. I have no idea where to start looking, largely because I have tried several times to create new files, including a Hello World application, none of which resulted in a functioning application.
So, here's the entire project.
If any of you would like to have a look through it and point me in the right direction, I would appreciate it, and credit you on my Game Jolt page. This has been giving me headaches for far too long, and I'm about to give up and learn a new bloody language. Please help, it's always appreciated.
Sincerely, a 15-year-old Java-lover who just wants to produce a damn dungeon crawler, fgs.
UPDATE: As per #AndreyAkhmetov's advice, I removed the Class-Path from my manifest file. Unfortunately however, I still don't get anything opening when trying to launch the application. Hope this helps, everyone. Thanks for the feedback so far!
I have made a pull request to fix your game ;).
your problem is how to load resources. You can use maven to organize your project and resources. It helps to make your project platform independent and easy to share.
you should use this structure:
Crawler /
src /
main/
java/
resources/
Images/
pom.xml
The pom.xml is a configuration file and all your resources like Images are in the resources folder. Then you can load it using this:
InputStream loadimg = Main.class
.getClassLoader()
.getResourceAsStream("Images/chest.png");
chest.setImage(new Image(loadimg));
also you should change the directories where you load saved files, from this c\\... to this ./saved.txt. Then the jar can be executed from anywhere.
To create an artifact you can do
$ mvn package
or if you are using Intellij, in the side bar click on Maven then on lifecycle and package.
That will create a target folder with the jar inside, you can execute it by clicking on it or with this command to see the console errors.
java -jar Crawler.jar
Try to split your components from your Main class, it is too large and difficult to read and understand.
Nice game, good luck!

Unable to create an Executable JAR on Eclipse. Couldn't find main

I've seen many other answers to similar questions, however, none of the solutions I've seen will do the trick, I've tried them all but I keep getting the same error message:
"JAR creation failed. [...] Could not find main method from given
launch configuration."
It might have something to do with my Java app using external images with Swing, since I got some problems while trying to create the JAR before getting to the final step.
The main method is there, it works if I run it from there and it has the right format, parameters etc. just in case you're wondering.
I'd appreciate some help, since it would be really useful for me to keep track of finished releases of my software. It's a Java application with no external libraries, just some images and that's it. I don't really need anything fancy, just a runnable package that I can send to some people to test for errors.
Well, for what I understand, you just need something that will run, not necessarily a "Runnable JAR" as Eclipse calls it, and what I assume you're trying to do.
I ran into this very same issue some time ago, and although I'm not sure it is the optimal solution, I'd say it will meet your requirements and it worked perfectly for me.
First off, as you probably have done before, right click on the project folder, then click Export.
Here is where we make things differently, instead of "Runnable JAR File", just select "JAR File".
The menu here is a little bit different from that on the Runnable JAR screen. Just select the resouces you'd like to export, then the JAR file destination and click next. Adjust the settings there and when you get to the final screen, select the application entry point (in this case, your Main class).
Click finish and that should work this time.
I don't really know what causes this behaviour or why it works this way, but for me, it just did every time I couldn't manage to do it using the "Runnable JAR" option.
To run the JAR package, it should be as easy as going to the console on any computer with Java installed and type:
java -jar [pathToYourFileHere]
Good luck and let me know if it works. Hope it is what you needed!

Eclipse doesn't place the classes in the bin folder anymore

I was making a game for school, and it works all and stuff but now I have a big problem.
I wanted to add doors, and keys. I finished the door part and wanted to test it. It didn't work. It's not about the code, everything is fine. I saw that my classes were not build in the bin folder.
the bin folder of the program:
http://speedcap.net/sharing/screen.php?id=files/37/bf/37bf1527e7a2028bfaf9188e9571c465.png
The classes (in Eclipse):
http://speedcap.net/sharing/screen.php?id=files/38/a0/38a0f0e0a3b376c40d7689bc0e6a23aa.png
Also as you can see, in eclipse there is a "!" on top of the project.
Now the problem is: How do I fix this?
Any help would be appreciated.
Greetings Carolien.
EDIT:
I got everything fixed now thanks for helping (feeling really dumb now -_-) it was something with order and export (still dont know what but i clicked select all and suddenly everything was fixed)
Is there a specific reason for moving everything to the res folder? You might need to move everything back into your src folder. Also you should check the box in the build path "Allow output folders for source folders".

Why is there no manifest.mf in the “dist/” directory and why is jar file not working?

I'm new to NetBeans and I cannot find the MANIFEST.MF that this link tells me there should be when I click "Clean and Build" in the IDE.
However, I only see a .jar file and a README.TXT. Anyone have any idea about this?
I am completely new to NetBeans, so simple terms would be much appreciated!
Also, when I run my project in the IDE, it creates and displays a jFrame but when I double click the jar file, nothing shows up. I have done setVisible() and I have set the default close operation, so that is not the problem. When I was searching for an answer, I found out that this could be because I did not specify my main class in my manifest. So this may be tied in with the top question so that is why I am combining these two questions.
Thanks in advance, guys!
I am using NetBeans 7.2 Beta
I realised that the manifest.mf file is not located in the "dist/" directory but in the root directory of the project. I am able to locate it now. However, I am still unable to figure out why the jar was not working. It is working now. Maybe my machine was just acting up or maybe I was using up too much RAM so my computer did not want to run another program? Anyway, everything is solved now. Thanks for everyone to answered!
Extract the .jar file using WinRar and then check inside the META-INF folder for MANIFEST.MF.

Categories

Resources