Issue Resolved !!!
I was reading all db details from a property file that property file i was reading directly by refrering file name in netbeans but in Jar it was not able to find that file. so I used below code:
System.getProperty("user.dir")+"/config.properties"
I have created a MDI project which works absolutely fine from IDE netbeans in debug/ run mode but When I build it and access it. It shows error: No suitable driver found jdbc://postgresql
I verified jdbc jar file for postgreSQL and its available in dist\lib
location I have added jar file to library of my project
I tried accessing by Double clicking on myApp.jar build app and also accessed it via command prompt
>java -jar "myApp.jar"
It's initializing correctly but produces error when its trying to connect the database. I am using 1.7 version of java and 8.1 version of netbeans IDE.
I am using below code to connect :
String Host = "localhost";
String Port = 5432;
String DB = "test";
String dbURL = "jdbc:postgresql://" + Host+ ":" + Port + "/" + DB;
user = "test";
pass = "pass";
try {
Class.forName("org.postgresql.Driver");
con = DriverManager.getConnection(dbURL, user, pass);
}catch (ClassNotFoundException | SQLException e) {
JOptionPane.showMessageDialog(null,e.getMessage(), "Error", JOptionPane.ERROR_MESSAGE);
}
myApp.jar manifest file have below lines :
Manifest-Version: 1.0
Ant-Version: Apache Ant 1.9.4
Created-By: 1.7.0_71-b14 (Oracle Corporation)
Class-Path: lib/postgresql-9.2-1003.jdbc3.jar
X-COMMENT: Main-Class will be added automatically by build
Main-Class: myapp.FrmMain
I am running it from same original location:
NetBeansProjects\myApp\dist
I don't think this is duplicate of this as per ( Gord Thompson, Jeen Broekstra, Mike Laren, EdChum, pedrouan)
I as solution for that question is to add dependent jar file in library and I have already done that Even I can see dependent jar file in my \dist\lib\ folder as I had added that jdbc in library of netbeans project. Please find below that details of dist directory :
C:\Users\usernm>cd C:\Users\usernm\Documents\NetBeansProjects\my_App\dist
C:\Users\usernm\Documents\NetBeansProjects\my_App\dist>dir
Volume in drive C has no label.
Directory of C:\Users\usernm\Documents\NetBeansProjects\my_App\dist
10/07/2016 01:51 PM <DIR> .
10/07/2016 01:51 PM <DIR> ..
10/07/2016 01:51 PM <DIR> lib
10/07/2016 01:51 PM 108,932 my_App.jar
10/07/2016 01:51 PM 1,323 README.TXT
2 File(s) 110,255 bytes
3 Dir(s) 121,849,483,264 bytes free
C:\Users\usernm\Documents\NetBeansProjects\my_App\dist>cd lib
C:\Users\usernm\Documents\NetBeansProjects\my_App\dist\lib>dir
Volume in drive C has no label.
Directory of C:\Users\usernm\Documents\NetBeansProjects\my_App\dist\lib
10/07/2016 01:51 PM <DIR> .
10/07/2016 01:51 PM <DIR> ..
10/07/2016 01:51 PM 525,205 postgresql-9.2-1003.jdbc3.jar
1 File(s) 525,205 bytes
2 Dir(s) 121,848,958,976 bytes free
C:\Users\usernm\Documents\NetBeansProjects\my_App\dist\lib>