Reputation: 13
I use the "Create Jar File..." option and choose my main class. When I try to execute the program from the Jar, my JOptionPane window will show up, but the program will just end there and not show my JFrame. I have tried putting the jar inside the project folder and running it from there, but some of my objects will not draw when I start it. Is there something I could be doing wrong or something I could do to fix my problem?
Upvotes: 1
Views: 2137
Reputation: 1152
I had a similar problem with my first .jar exported from BlueJ. I resolved it by executing the jar via command line with the addition of the -jar flag (java -jar MyProgram.jar
). The -jar flag tells the launcher that it's dealing with a .jar archive, rather than being invoked to run just a class file. Assuming Java is properly installed on your machine you can easily do it this way, even just via the 'run' dialog in windows. If you're not totally comfortable with command line interfaces it'd be easiest to give it an 'absolute path' - on windows you could put your .jar in C:\ and just do java -jar C:\YourThing.jar
via the 'run' dialog. Take a look at the docs for the java
launcher, they're pretty easy going: http://docs.oracle.com/javase/7/docs/technotes/tools/windows/java.html
If you really want to be able to double-click your .jar, the answer is a little more fiddly. Have a read of this other question (Running JAR file on Windows) where people have provided a variety of different ways of doing it, none of which I can personally vouch for but I'm sure will all work.
Upvotes: 1