I was trying to make my application work with jTDS (MS SQL Server 2008). So I did the following:
Order and Export
tab, I selected all entriesI then exported the jar. As it is not an runnable jar, I afterwards tested it and it can't seem to find my driver (java.lang.ClassNotFoundException: net.sourceforge.jtds.jdbc.Driver
).
When I test it in Eclipse by executing only something this:
public static void main(String[] args) {}
String classForName = "net.sourceforge.jtds.jdbc.Driver";
try
{
// embedding driver for sql connection
Class.forName(classForName);
con = java.sql.DriverManager.getConnection(getConnectionUrl(), user, pass);
if (con != null)
{
JOptionPane.showMessageDialog(null, "Connection Successful!");
}
}
catch (Exception e)
{
Log.writeStackTrace(e);
}
}
.. it then works like a charm. So in my thoughts, the problem seems to in including my jTDS jar. Did I miss something?
Damn, I'm just slightly too late!
The standard Java classloaders don't support nesting JARs within JARs. You can either combine your JARs together (as you've done!), or you can use a more sophisticated classloader with something like One-Jar (http://one-jar.sourceforge.net/).