kaka09
kaka09

Reputation: 1

Program stopped working after creating a .jar file with Netbeans

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.

Upvotes: 0

Views: 667

Answers (2)

Mahipal Singh
Mahipal Singh

Reputation: 1

just copy the database driver into C:\Program Files\Java\jre7\lib\ext and then run the jar file.

Upvotes: 0

Andreas Dolk
Andreas Dolk

Reputation: 114757

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)

Upvotes: 2

Related Questions