[java] Problem with JAR files created in Netbeans

Started by
3 comments, last by Son of Cain 16 years, 3 months ago
Hi guys! First off, I don't really have much experience using Netbeans so I apologize if this question has a very obvious answer. For our final project in class my team and I needed to create a multi-player game in Java. We chose to implement Battleship. Everything was going fine until we decided to test the game outside of Netbeans (by running the JAR file directly). We were shocked to discover how different the functionality of the JAR was to how our application appeared to function when we tested it in Netbeans. For example, we rendered the Battleship grid using a bunch of JButtons. In order to draw "ships", we changed the icon on the button from a picture of water to a gray square. In Netbeans this worked fine, but when the JAR file was run the gray icon would be drawn underneath the water rather than replacing it as the setIcon method ought to have done. These problems kept compounding themselves until we had a game what would work great if you ran it from Netbeans, but was nearly unusable in JAR form. We were using no strange libraries and we even had the chance to test it on four different plantforms (Windows XP, Windows Vista, Mac OS X, and Linux) and with three different versions of Netbeans (5.5, 5.5.1, and 6.0), yet none of that made any difference. I really like Java, but I don't want to invest any time in developing a game if I am going to keep running into the same problems over and over again. Can anybody please explain what the issue is with the difference in functionality, along with how it can be remedied?
Advertisement
I am not sure about this, but if you are using the NetBeans GUI builder Matisse, then there may be a *.jar file that is part of NetBeans that you also need to include. I read this the last time I used the GUI builder, but I put my application in a jar using any, and I didn't have any trouble. I am not sure this is it.

Could it be that the jar file is missing some stuff?

I think, therefore I am. I think? - "George Carlin"
My Website: Indie Game Programming

My Twitter: https://twitter.com/indieprogram

My Book: http://amzn.com/1305076532

I'm afraid this isn't going to be very helpful, but I've seen the same type of behavior using Netbeans. I never did like how it totally took over my ant build scripts, and I always did notice different behavior while running from the Netbeans IDE. I also wasn't a fan of how sun tried to make it so much like VB 6.0, abstracting away all the details of building and compiling, to 'just press play'.

The only thing I can suggest is to figure out exactly what is going on when you run from within Netbeans, it probably uses a different command line, adding other jars to the classpath or something. I know it doesn't do a regular ol' java.exe <classname> like you're probably doing outside the editor.

Good luck, and if this has left a bitter taste in your mouth, I strongly suggest eclipse, I believe it has some sort of swing gui builder plugin available. I made the changeover awhile ago, and have never looked back.
Try not relying on Netbeans and make your own jar file:

Create a manifest.txt, type in Main-Class: nameofmainclass

now go to command prompt and type in java cvfm name.jar manifest.txt *.java
Netbeans is a gret tool, very productive, and it indeed tries to do a lot of things for you. But as with any dangerous toy, you gotta know your ground when playing. I use it since it was no better than notepad, with crap performance, and most recently (since version 4.x), I dumped Eclipse for it, without regrets.

My bet is the same as Glass_Knife - it is most likely a library problem. I suggest you write yourself a good ant build file (if you haven't already), and always use that to build jars, classpath' resources, etc..

Post some code, if you can. That can help us identify what might be going wrong.
a.k.a javabeats at yahoo.ca

This topic is closed to new replies.

Advertisement