6

I'm using IntelliJ Idea. I've built 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 directory of the sqljdbc42.jar file is in the manifest. I'm on Windows, and I'd like to run this by clicking on the '.jar' file. The application .jar file and the sqljdbc42.jar files are both in the same directory. On the command line, executing...

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
2
  • 1
    What command did you run on the command line? Where is sqljdbc42.jar located in the filesystem? Commented Oct 2, 2015 at 17:27
  • 1
    when you run your program in IDE, IDE adds this jar to the classpath, but when you you run this program by yourself you don't do that, so you get the error message. Add this driver jar file to the classpath, when you start your program. Commented Oct 2, 2015 at 17:28

1 Answer 1

3

Try running your application with:

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

Replace the : with a ; under Windows.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.