I am working on Java project (A terraria like sandbox game) and I have come across something that I just don't understand. I have been exporting the project as .jar's as I go along to upload and share with my friends, but the last time I did this, the .jar won't run, but when I run it in eclipse, it runs fine. When I try to run the jar all it does is lose focus on the explorer window for a split second, then goes back. I have tried many things, like changing the main class, changing the META, and moving the files to specific packages, but nothing is working.
The project is 9 classes, so I won't paste all the code for it here, but the latest, non-working source code can be found here (http://www.mediafire.com/?fiw6wq73j7cff4t), the non-working jar here (http://www.mediafire.com/?bhjo162oh3hi2j9), and the working jar here (http://www.mediafire.com/?h918s8xpyxw4psr). If someone with more experience in java could please take a look at this it would be much appreciated.
One of the things I tried was not adding the JPanel (the game), and just leaving the splash screen, and the jar worked. This shows that it must be a problem in the coding somewhere.
Thanks for the time,
I.D.
Couldn't find message comes from your ReadMap class. So check which circumstance leads to this error. Most likely you did not add all classes or other files to your JAR, so file is not found. Check that all needed files are added to exported JAR in Eclipse export dialog. It's also a good idea to provide more debugging info (stacktrace is ok), especially when you are studying. BTW, cool game :)
Related
So I've made up a little programm for my mom to use. I exported it into a runnable .jar, which is a first for me, so I obviously screwed it up.
Actually the file works just fine on my computer. But when I try it on hers, double clicking on the file just gives me an error : "could not find Main class : controller.Main". And the programm won't start
I used eclipse GUI to export it (right click on projet -> export -> runnable JAR), and it gave out a file working well on my computer.
If it is of any help, my programm uses a bunch of resources files, but I included them in the right place in the folder that I gave to my mother so it should not be the problem (besides, it would glitch out when trying to use the images, but not stop it from launching, according to some personnal tests)
What can be the Reason for it to work on my device, but not another one (both Windows) ? And how to fix this ?
N.B: I have included a MANIFEST.MS file in my project before exporting, but Eclipse didn't make any explicit mention to it when exporting, so I think it didn't take it into account. Besides, I reffered to my main class as Main (and not controller.Main as in the error message I got on my mother's computer). This was probably wrong of me, but I think it shows that Eclipse didn't care much for my manifest and kinda made his own.
Thanks in advance !
If you want a link to download the folder, to check it out yourself, let me know ! (it's a bit heavy though, there's quite a lot of images)
EDIT : I get different error messages with different computer. One computer would give me this first message :
first computer error
Another computer gives me those 2 error messages (one after another)
2nd computer error (1/2)
2nd computer error 2/2
And of course, it still runs fine on mine, just with a double click !
My .jar file (opened as an archive) contains :
3 folders corresponding to my packages : controller, model, view
1 folder META-INF containing the MANIFEST.MF generated by eclipse, looking like so :
Manifest-Version: 1.0
Main-Class: controller.Main
Class-Path: .
Ok ! I could figure it out. So there were actually 2 problems on top of each other :
first, I think Martin's suggestion was correct. After researches on the new error message, it became clear that native calls had probably had Something to do with the problem, although I have no idea what native Library I was using. I could solve this first part of the problem by selecting another option to handle libraries in the eclipse export feature : I chose the option "package required libraries into genereated JAR" (instead of "extract required libraries into generated JAR" before), and it make the error message go away !
Even though the message disappeared, the app would still not launch. But the problem was more obvious this time; I Simply compiled and exported the file with a java 9 JDK for eclipse, while trying to run it on a java 8 software (I think java 9 is only available in its developper version to this day). So I just downloaded java 8 JDK, configured the build path to use the latter, and it finally worked on the other computer.
Thanks to Martin who helped me get on track with the right questions !
I might be using the wrong term when talking about "sync" but that's the best way to descrie it I think. I'm trying to debug a project that I've been working on for a couple of days now but for some reason the .java class and the .class file aren't syncing (.class file isn't updating to any of the changes that I make to the .java class that I'm editing). Let me start from the beginning I guess, when I do add break points to my .java file (sometimes the breakpoints are skipped) that I'm debugging and run the debugger when the breakpoint is reached the .class file is opened in instead of the .java file.
I searched around and found the solution to that with the help of some topics on here, which was "Edit source lookup". So the part about .class opening instead of .java file instead was solved. The main problem now is when I do edit the .java file with anything and run the debugger it completely ignores my changes. For example, if I implement a System.out.println("Test: 1") before a breakpoint or even after it's not printing to the console. Another example is if I comment out a line of code and run the debugger, the debugger still executes that line of code that I just commented out.
I searched for some solutions but they didn't help much. Some things I've tried were but did'n work:
Why isn't Eclipse updating the classes?
1.) Make sure the Build automatically is checked
2.) Cleaning the project
3.) Refreshing the project, F5
4.) Go to Wwindows->Preferences->General->Workspace and making sure the first 2 checkboxes are checked.
5.) Saving
6.) Restarting ecslipse
If anyone knows how to maybe solve my propblem I will be indebted to you. By the way I'm using java 1.7
What you describe indicates problems in you project definition.
Make sure that your project (main runnable class) specifies correct dependencies - that it does not specify dependencies on other jar files but includes dependencies from your related projects
I have tried many time to add the correct libraries, make sure I have the right manifest, and even reset the project properties. The strangest thing about the jar file I render is that it runs just fine on my computer but will not on others. the source code is open and available here to anyone who is interested. https://github.com/nicklanetv/itdops/tree/master
Disclaimer:
Before I get the standard "this has been asked 1000 times", let me say that yes, I know. I have read and read and read. Looked at JarJar and One-JAR but the problem is: I am self-taught with only a couple of months of experience under me and I am not familiar with Ant or Maven or anything other than vanilla Java. I use NetBeans as my compiler, just to add.
I have written an application for use at my job. It is just a small app that takes certain input and writes it to an Excel file. I downloaded jexcelapi (jxl.jar) and placed that appropriately. I have no trouble running the file inside of NetBeans or from within the dist/ folder after it is built. Therein lies the problem: if I move the app to, say, the Desktop, I get an error from the JVM saying "A Java Exception has occurred." I know that this is due to the fact that the main class is added to the .JAR automatically but to add another lib, I will have to make a "Class-path" statement within my Manifest. I tried that unsuccessfully. I have tried moving the actual jxl.jar file to my jdk folder and I tried calling the entire file path that points directly to the jxl.jar file into my Manifest. The closest I can get is building the .JAR in NetBeans and it adds the lib folder to the dist folder where the app .JAR is.
I want to distribute this app as just a single .JAR without having to send all the users a copy of the jexcelapi lib. It doesn't have to be a .JAR within a .JAR; it can be whatever way is easiest and simplest. As stated before, I am not familiar with Ant and One-Jar draws on that. I am still learning; can someone point me in the right direction with this? Thank you!
There is a better one for novice programmers.
Launch4j gives what you need, even wraps it to exe file. Yu don't need to know programming at all to use this.
OFC there are ANT task if you ant to automatise the Launch4j , but for that you must leant a bit about ANT :)
After hours of exhausting search, I found something that was incredibly short, sweet, and right to the point. You cannot mess it up. Here is the link.
So I make a couple of images for my eclipse view plugin. Works perfectly. I wake up the next day and the program now tells me that it can no longer find those files. The files are definitely still in the same place I left them, and I haven't touched the code in 24 hrs. I've been messing with this for an hr now and I don't even know where the start debugging this, as my program was fine yesterday.
Sample.gif is in the "icons" folder of my plugin. I've tried moving it to the src folder, and that doesn't work either.
Error message:
org.eclipse.swt.SWTException: i/o error (java.io.FileNotFoundException: sample.gif (No such file or directory))
Code (when I remove this line and all lines of code that use testImage, the plugin runs again):
Image testImage = new Image(null, "sample.gif");
Anyone have any idea what could possibly be causing this, or what information i can provide for someone to give me a direction as to how to debug?
The problem is most likely to do with where the current directory is. When you use a pathname like "sample.gif", the normal behaviour when opening the file is to look in the current directory. If you run the application with a different current directory, the application will look for the file in a different place.
I'm however confused by the current directory concept
Here are some pages that describe the concept:
http://en.wikipedia.org/wiki/Working_directory
http://www.linfo.org/current_directory.html
where should the pictures go?
If you are only ever going to run your application from within eclipse, then you can put them anywhere ... and make sure that your application's Eclipse launcher configuration sets the current directory to a consistent place. (Your current problem is most likely due to the application launcher using the parent Eclipse's current directory, and THAT may depend on where you were when you launched Eclipse ... see linked pages above.)
If you are going to export the built application in some form so that users can use it outside of Eclipse, then the answer depends on the nature of the application and how it will be installed on the user's computer. (On possible solution is to put the images into the application's JAR file, and locate them via the classpath using the ClassLoader.getResource methods.)