2

So i created a javafx project, it has 3 packages, application, controller, and an images package that holds all the images im using. The program runs fine if i just compile and run, no errors. However, when i create a jar from it, by selecting the build.fxbuild, everything goes smoothly and it tells me it is successful but when i try to double click the jar file nothing opens but java starts running in the background until i force close it. Im running OSX yosemite, and im on java 1.8 if that helps at all. I've tried making the jar through the export option but it doesnt run either and just says that it cant open the file. The weird thing is i made another javafx project just to see if it would work, same settings but just something simple, a window that pops up and says a line, then exported to a jar by clicking build.fxbuild and when i double click the jar it made it works perfectly.

I'm at a loss for what is preventing my other javafx project from working as a jar file and the other similar posts ive found on here haven't solved it either. Any ideas?

dalva
  • 55
  • 7
  • Are you trying to read resources using a file protocol, rather than a class loader getResource api, or do you have `..` relative directory locations in your resource lookups? Other than that, it is hard to say what might be going wrong. – jewelsea Nov 03 '14 at 23:14
  • I use getResource. I learned about javafx a week ago to work on a school assignment so im not sure if maybe thats whats wrong but im using github so my main class and controller class is there if you wanna see for yourself, actually the entire project is there lol, im pretty proud of it :) just a tutorial for how to use binary search trees, works perfectly all i need to do is get the jar to work :/ https://github.com/blaugrana/COP-3530-Assignment-3 – dalva Nov 04 '14 at 01:02
  • I see `` in [MyApplication.fxml](https://github.com/blaugrana/COP-3530-Assignment-3/blob/master/src/application/MyApplication.fxml). I haven't tried it, but the `..` looks suspicious. – jewelsea Nov 04 '14 at 01:46
  • 1
    You can also try running from the terminal (Applications > Utilities > Terminal) with `java -jar /path/to/jar/file`. That will sometimes give you a more helpful error message. – James_D Nov 04 '14 at 01:50
  • yea i added the source for that using scene builder and thats how it added it =/ @James_D ive tried that but every path i specify it tells me it cant access the file. I have no idea what path to provide it for it to work. Should I cd into the folder that contains it and then just type the filename ? – dalva Nov 04 '14 at 02:41
  • That would work: cd into the directory where the jar file is then `java -jar jarfile.jar` – James_D Nov 04 '14 at 02:46
  • @James_D ok that managed to give me an error! Progress!! :D Here is the error, I think it occurs at line 15. Its saying location is required, but i have the fxml file in the same package...and it runs fine when i compile so what gives? Thanks for the help, heres a screenshot http://gyazo.com/be62c92540110a54ef05521316c61688 – dalva Nov 04 '14 at 03:16
  • In your code you have "/application/myApplication.fxml", but in the package explorer I see "MyApplication.fxml". (Though I wonder how it is working running from Eclipse). Check the contents of the jar file using `jar tf assignment3.jar` – James_D Nov 04 '14 at 03:21
  • @James_D wow nice catch! I think its because i've been working on this back and forth with my gf and didnt change it back properly, but the jar seems to have the right file, maybe its just not calling it once it runs? heres the screenshot. should i delete the build folder and remake the jar with the correct name for the fxml file? http://gyazo.com/397f7a2fb3082f4aac335dee6cd0f1f6 – dalva Nov 04 '14 at 03:30
  • The file and jar file entry are both "MyApplication.fxml", whereas in your code you are looking for "myApplication.fxml" (line 15). Change the source code to "MyApplication.fxml" and rebuild the jar file and it should work. I suspect you have an additional "myApplication.fxml" file kicking around on the file system (that's not being exported to the jar file), which is why it works in Eclipse. – James_D Nov 04 '14 at 03:33
  • @James_D holy crap IT WORKS!!!! http://gyazo.com/a244246aea1745ffda7948be8e7f2e14 dude....you have NO IDEA i spent all day trying to figure this problem out. THANK YOU for seeing what i couldn't see! Thanks a million! Finally my project is complete :) if you answer ill give u the check hehe. both of you tried, i appreciate that guys! – dalva Nov 04 '14 at 03:45

0 Answers0