0

I use druid as a Database connection pool in my maven project. I use 'maven package' to have a jar package. Then I just run it. However, it has a java.lang.NoClassDefFoundError exception. In detail, It is that

Exception in thread "main" java.lang.NoClassDefFoundError: com/alibaba/druid/pool/DruidDataSourceFactory.

I found error in my code dataSource = (DruidDataSource) DruidDataSourceFactory.createDataSource(properties); I have tried my best, but I still can't fix the bug. While I directly run the code in eclipse, it doesn't report the bug and runs well.

Thanks for your help

jackson
  • 23
  • 5

2 Answers2

0

When you run it on eclipse, it has all the jars that you need with Maven. However, when not running on eclipse, you need to package your project properly so that it has all the jars that it needs at runtime.

nmore
  • 2,474
  • 1
  • 14
  • 21
  • I use 'mvn package' to build my project.My 'pom.xml' has the druid dependcy. – jackson Aug 07 '14 at 09:54
  • Yes that is fine for building, but you have to export it properly with the jars. See http://stackoverflow.com/questions/1751551/maven-how-to-export-project-with-sources-and-dependencies for more info. – nmore Aug 07 '14 at 09:58
  • I use the method that you mentioned to have all dependencies with my jar.But the problem still exists – jackson Aug 07 '14 at 10:21
0

java.lang.NoClassDefFoundError means: com / alibaba / druid / pool / DruidDataSourceFactory cannot be found. It is likely that your current web project did not successfully import Druid.jar. Therefore, I suggest you check if your lib package is in the WEB-INF directory, not in the web directory, and if you set the lib package to Add As Library.

Oleksii Filonenko
  • 1,551
  • 1
  • 17
  • 27