Lolly
Lolly

Reputation: 36432

NoClassDefFound error from Java program in UNIX

I executing a Java class in Unix. The Java program that I am executing is a JDBC program connecting to SQL Server. I have the class file but when executing "Java" command I get this error. Below are the commands.

>cd /home/test

>ls 

JDBCConnection.class  JDBCConnection.java   jtds-1.2.5.jar

Running the below command gives me "NoClassDedFound" error.

java -cp jtds-1.2.5.jar JDBCConnection

Error message:

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

Upvotes: 0

Views: 174

Answers (3)

Ankur Shanbhag
Ankur Shanbhag

Reputation: 7804

NoClassDefFoundError in Java comes when Java Virtual Machine is not able to find a particular class at runtime which was available during compile time.

In your case, you have not added the current directory to the classpath which holds the JDBCConnection.class classfile.

Try this out :

java -cp jtds-1.2.5.jar:. JDBCConnection

Read more: http://javarevisited.blogspot.com/2011/06/noclassdeffounderror-exception-in.html#ixzz2jxtG7mt5

Upvotes: 1

SJuan76
SJuan76

Reputation: 24895

Add the current directory to the classpath

 java -cp .:jtds-1.2.5.jar JDBCConnection

Upvotes: 3

Klas Lindbäck
Klas Lindbäck

Reputation: 33273

Add . to the classpath:

java -cp jtds-1.2.5.jar -cp . JDBCConnection

Upvotes: 0

Related Questions