Win a copy of Modern JavaScript for the Impatient this week in the Server-Side JavaScript and NodeJS forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
Bartenders:
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

Cannot find driver class

 
Ranch Hand
Posts: 53
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have this line of code in my Java application: Class.forName("com.ibm.as400.access.AS400JDBCDriver");

When I run my application, I'm getting an error that says that the class could not be found. I have the jar file that contains this class in my classpath. What could be the problem?
 
Bartender
Posts: 1051
5
Hibernate Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Are you certain the jar is on the classpath? And have you definitely given the correct fully qualified name?
 
Marshal
Posts: 70208
280
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It would appear from this link that the fully‑qualified name is correct.

Please show us how you are setting the classpath.
 
Alissa Horner
Ranch Hand
Posts: 53
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Campbell Ritchie wrote:It would appear from this link that the fully‑qualified name is correct.

Please show us how you are setting the classpath.



I opened up a command prompt on my computer and I typed in the command, echo %CLASSPATH%
My computer shows the CLASSPATH setting and you can see it below. The jar file, jt400-4.9.0.jar contains the class, com.ibm.as400.access.AS400JDBCDriver.
When I use the command, mvn -P server, I get a ClassNotFoundException. This is the class that is not found: com.ibm.as400.access.AS400JDBCDriver.

Here is the setting:

C:\>echo %CLASSPATH%
C:\Jar_Files\jt400-4.9.0.jar
 
Campbell Ritchie
Marshal
Posts: 70208
280
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Start by deleting that system classpath variable. Because you have set it up at all, you are losing access to classes in the working directory.
You should set the classpath for each application because each application will require a different classpath. So don't set it permanently. The best way is probably to use the -cp option when you call the java and javac tools at the command line. Or you can set it for the lifetime of the current command prompt window as shown in the Java® Tutorials. You will probably want to add .; or ;. (on Windows®) to the classpath to the .jar file. Have a look at the “environment” and “deployment” sections (try under Jar Files) of the Java® Tutorials, too.

What is the mvn instruction? Does that actually have anything to do with Java®?
 
Don't get me started about those stupid light bulbs.
    Bookmark Topic Watch Topic
  • New Topic