Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

ClassNotFoundException

 
Matt Holloway
Ranch Hand
Posts: 53
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I know this seems to have to do with my CLASSPATH...

java.lang.ClassNotFoundException: com.mysql.jdbc.Driver

I have a MySQL database setup. When I use Eclipse, I can perform the following:

and all goes well, I can then connect to the database, yada, yada..

When I use NetBeans, the same code gives the above error... What I am really trying to accomplish is to make this connection in a JSP page running on TomCat 5.2... I have put the jar file from MySQL in the web-inf folder just in case that might help, but nope.

Any help would be appreciated.

Thanks.
 
Matt Holloway
Ranch Hand
Posts: 53
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Okay... I figured it out, here is the fix in case anybody else runs into this.

In the <%tomcat_home%>\bin folder, there is a file called setclasspath.bat, if you add the path to the MySQL jar file, save the file then stop/restart tomcat, it will work.

<%tomcat_home%> is the folder path to your tomcat install
[ February 27, 2005: Message edited by: Matt Holloway ]
 
David O'Meara
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm not sure that should work but since it does, good for you

The correct place for the driver JAR is in the web-inf/lib directory. When a web app starts, the libs in this directory are loaded and made available to that application only. Other web apps running in the same container will not be able to see it. The advantage is that you can separate the source code and dependancies for each application in the container and still have them running in the same container.

You should also be able to place it in the tomcat/common/lib, but as hinted above, all applications will see this code and it will cause problems if (for example) you have two web apps requiring different versions of the driver.

The next worst place to put it is the jre/ext/lib directory in your java installation. This makes the code available to everything run with that java command. In some cases it may make sense, but I tend to discourage it.

J2EE apps are supposed to 'ignore' the classpath so that they are only dependent on the java libraries, common container files and code specific to the nested application. This is why I can't understand how adding it to the tomcat classpath had any effect. I'd have to check the documentation.

Hope this helps.
Dave.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic