Dustin Sun
Dustin Sun

Reputation: 5532

java -classpath ./sqljdbc4.jar myclassname

if I run java -classpath ./sqljdbc4.jar myclassname error is

Exception in thread "main" java.lang.NoClassDefFoundError:myclassname

if I run java myclassname error is

java.lang.ClassNotFoundException: com.microsoft.sqlserver.jdbc.SQLServerDriver

It is on Linux. How to fix it?

Upvotes: 1

Views: 990

Answers (1)

JB Nizet
JB Nizet

Reputation: 691715

The directory or jar containing your classes package tree (i.e. the directory containing the com directory, in the following example) must be in the classpath. And the sqljdbc4.jar must also be. Put both in the classpath:

java -cp ../classes:./sqljdbc4.jar com.foo.bar.MyClassName

Also note that you need to use the fully qualified name of the main class (as the above example shows), and that class names in Java use CamelCase by convention.

Upvotes: 2

Related Questions