views:

64

answers:

1

I made a simple Swing application with some database connectivity, using Notepad++ and executing it from the command prompt. It was executing perfectly.

Then I copied all of the code to Netbeans and tried to build to main project, in order to package my application as a .jar file.

A .jar file was created successfully, but when I tried to run it, it did not execute properly. For example, I had a button in my application that displays all records present in the database. It worked when I executed from the command prompt, but when the .jar file was executed, there was no response.

+2  A: 

Hard to tell without seeing some code or error/exception stack traces. The most typical cause for problems of this kind are incomplete classpaths. Maybe your database driver class is missing on the classpath.

Some things you might check:

  • Do you get some sort of error?
  • Is the jar executable? If yes - that's the case when you start the application with something like java -jar path/to/myjar.jar - the classpath must be specified in the jar files Manifest, any -cp value is simply ignored.

Looking at your last comment, I'm pretty sure, that this is a classpath problem. The database driver usually resides in a different jar file and if the classpath entry in your manifest.mf file is blank, then the driver can't be loaded. This should result in an exception but maybe this is catched somewhere.

Solution #1 - edit the manifest.mf file and add all required libraries according to this tutorial:

Class-Path: jar1-name jar2-name directory-name/jar3-name

Solution #2 - don't start the application with the -jar option but use the standard way:

java -cp yourLib.jar;database-driver.jar your.application.Main

(all library entries have to be given with a correct relative or absolute file path)

Andreas_D
no i dont get any type of error.the jar file is executable. i tried to extract the contents of .jar file and tried to open the manifest.mf file in the META-INF folder through notepad++. the field under the classpath column is empty.see i tell u the exact problem,when i double click on my .jar file, the main frame window appears as it should be. now dere is a button on the main frame that searches for word match in database and displays its meaning upon clicking it, bt the meaning is not shown. dis is probably due to the fact that .jar file is unable to connect with mysql server.
kaka09