There is a java source that connects to MsSQL. It compiles fine. In the debugger, it starts and runs.

When packing it in a jar (IDEA 11), and without it, it produces at the start of classNotFound on the line

Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver"); 

Command line launch:

 java myapp -classpath "c:\Program Files\Java\jdk1.7.0_03\lib\sqljdbc4.jar" 

or

 java -jar myapp.jar -classpath "c:\Program Files\Java\jdk1.7.0_03\lib\sqljdbc4.jar" 

Option with sqljdbc.jar instead, sqljdbc4.jar also does not channel. The libraries themselves on the specified path are and in the debug version work.

Tell me where to reset the brain?

Thank you in advance.

    3 answers 3

    Note the -jar option in the java command description :

    If you use this option, the user paths settings are ignored.

    So you either pack sqljdbc4.jar along with your code, or start the main class manually:

     java -classpath "c:\Program Files\Java\jdk1.7.0_03\lib\sqljdbc4.jar";myapp.jar com.example.Main 

      In the manifest, you must specify the relative paths to the libraries, relative to the jar-file.

       Manifest-Version: 1.0 Main-Class: Class-Path: lib/mylib.jar 
      • Thank you, too! It’s a pity you can’t both be right ... - SilverIce

      It may be useful. If a class is started outside jar, and you need to connect an external library, the following launch string is used:

      java -classpath sqljdbc4.jar;./ MyAppClass

      • It helped me when I started the class with the hotel jar library - Lurking Elk