ClassNotFoundException upon running JAR, no errors while running in IntelliJ IDEA

Use java -cp instead of java -jar and put all of you dependencies jars to classpath.

Another way is pack all of dependencies to single jar, that allowing you to run application using java -jar.

EDIT:

In Java *.jar file contains a bulk of classes. When you build your own app, typically, result jar file contains only your classes, but still have to load classes from external libraries you use (so-called dependencies).

It can be done two different ways:

  1. You create a folder for your application, for example, called lib and place your application jar and all dependencies into. Then you run application using java -cp lib:/\* com.company.Main or (thanks @NilsH, I miss this variant) you make MANIFEST.MF file and specify Main-Class and Classpath attributes inside as described here

  2. You use special tool (like maven-dependency-plugin if you use maven for build) to pack all classes, either your own, either external to single jar. You got one huge file and can run it using java -jar cliTest.jar.

Generally, first approach is preferred and using a MANIFEST.MF file is a good form.


Well I should have built the JAR without the sqljdbc4.jar embedded.

The second thing I should have run the command like so :

java -classpath sqljdbc4.jar;cliTest.jar com.company.Main

.. and then all worked!