Search code examples
javajavac

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


Solution

  • Add the current directory to the classpath

     java -cp .:jtds-1.2.5.jar JDBCConnection