简体   繁体   中英

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

将当前目录添加到类路径

 java -cp .:jtds-1.2.5.jar JDBCConnection

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

Add . to the classpath:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM