ClassNotFoundException when using an external jar

I am using IntelliJ Idea . I created my application and created it as a .jar file. This program uses an external .jar file for its database driver.

When I run the program from the IDE, it works fine. When I try to run my .jar file outside of the IDE, it reports the following exception:

 Exception in thread "main" java.lang.NoClassDefFoundError: com/microsoft/sqlserver/jdbc/SQLServerException at ca.vdts.dbupdate.Main.main(Main.java:10) Caused by: java.lang.ClassNotFoundException: com.microsoft.sqlserver.jdbc.SQLServerException at java.net.URLClassLoader$1.run(Unknown Source) at java.net.URLClassLoader$1.run(Unknown Source) at java.security.AccessController.doPrivileged(Native Method) at java.net.URLClassLoader.findClass(Unknown Source) at java.lang.ClassLoader.loadClass(Unknown Source) at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source) at java.lang.ClassLoader.loadClass(Unknown Source) 

The sqljdbc42.jar file sqljdbc42.jar is in the manifest. I am on Windows and I would like to launch it by clicking on the .jar file. The application .jar file and sqljdbc42.jar files are in the same directory. At the command line, execution ...

 C:\Users\admin\IdeaProjects\DBUpdate\out\artifacts\DBUpdate>java -classpath .\sqljdbc42.jar;DBUpdate.jar -jar DBUpdate.jar 

... results in the same error:

 Exception in thread "main" java.lang.NoClassDefFoundError: com/microsoft/sqlserver/jdbc/SQLServerException at ca.vdts.dbupdate.Main.main(Main.java:10) Caused by: java.lang.ClassNotFoundException: com.microsoft.sqlserver.jdbc.SQLServerException at java.net.URLClassLoader$1.run(Unknown Source) at java.net.URLClassLoader$1.run(Unknown Source) at java.security.AccessController.doPrivileged(Native Method) at java.net.URLClassLoader.findClass(Unknown Source) at java.lang.ClassLoader.loadClass(Unknown Source) at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source) at java.lang.ClassLoader.loadClass(Unknown Source) ... 1 more 
+6
source share
1 answer

Try to run the application:

 java -classpath sqljdbc42.jar:Application.jar -jar Application.jar 

Replace : with ; under Windows.

+3
source

All Articles