• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Devaka Cooray
  • Tim Cooke
Sheriffs:
  • Rob Spoor
  • Liutauras Vilda
  • paul wheaton
Saloon Keepers:
  • Tim Holloway
  • Tim Moores
  • Mikalai Zaikin
  • Carey Brown
  • Piet Souris
Bartenders:
  • Stephan van Hulst

NoClassDefFoundError

 
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I know I'm beating a dead horse because everyone seems to have this problem and so have I in the past. Usually it is corrected by simply putting the correct .jar file in the classpath. Here is my code and classpath, if anyone can see an obvious problem I'm missing I would appreciate it.

private static Connection connect(String[] s)
{
Connection conn = null;
String sUrl = s[0];
String sUser = s[1];
String sPass = s[2];
try
{
System.out.println("Getting Driver...");
DriverManager.registerDriver( new oracle.jdbc.driver.OracleDriver());
//Class.forName("oracle.jdbc.driver.OracleDriver").newInstance();
//Class forName also gives an error
System.out.println("Got Driver!!");

conn = DriverManager.getConnection(sUrl,sUser,sPass);

} catch (Exception sqle) {
sqle.printStackTrace();
}
return conn;
}

C:\Oracle\product\10.1.0\Client_2\jdbc\lib\classes12.jar;C:\Oracle\product\10.1.0\Client_2\jdbc\lib\nls_charset12.jar;C:\JDeveloper\jdk\lib\rowset.jar;C:\Oracle\product\10.1.0\Client_2\jdbc\lib\classes12.zip

Any help would be greatly appreciated.
 
Patrick Ferguson
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Oh, and just to add, I have the project in both Eclipse and JDeveloper. It runs fine inside both IDE's, the problem is when I try to run it via command line.
 
author & internet detective
Posts: 41994
911
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Patrick,
The only thing I can think of is to double check the paths are the same in the IDE as the command line.
 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
IDEs supports inbuilt jars and which comes with installation. So those will support. When you run thru command line you may encounter problems.

So we need to know abt the jars which need to be run our application. So that set those as Environment variables.

.. Srikanth Kondeti
 
Ranch Hand
Posts: 163
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Patrick Ferguson:
I know I'm beating a dead horse because everyone seems to have this problem and so have I in the past. Usually it is corrected by simply putting the correct .jar file in the classpath. Here is my code and classpath, if anyone can see an obvious problem I'm missing I would appreciate it.

private static Connection connect(String[] s)
{
Connection conn = null;
String sUrl = s[0];
String sUser = s[1];
String sPass = s[2];
try
{
System.out.println("Getting Driver...");
DriverManager.registerDriver( new oracle.jdbc.driver.OracleDriver());
//Class.forName("oracle.jdbc.driver.OracleDriver").newInstance();
//Class forName also gives an error
System.out.println("Got Driver!!");

conn = DriverManager.getConnection(sUrl,sUser,sPass);

} catch (Exception sqle) {
sqle.printStackTrace();
}
return conn;
}

C:\Oracle\product\10.1.0\Client_2\jdbc\lib\classes12.jar;C:\Oracle\product\10.1.0\Client_2\jdbc\lib\nls_charset12.jar;C:\JDeveloper\jdk\lib\rowset.jar;C:\Oracle\product\10.1.0\Client_2\jdbc\lib\classes12.zip

Any help would be greatly appreciated.




classes12.jar and classes12.zip - you should only have one, not both.

classes12.jar is pretty old stuff. the latest version is ojdbc14.jar.

are you trying to connect to oracle 10g? I think you'll need a newer driver.

I'm not crazy about your code. Why do you feel the need to embed the driver class that way? you're tied to oracle forever that way.

how are you running this example? is that CLASSPATH-like string an environment variable? I'd recommend not setting CLASSPATH that way. app servers and IDEs often ignore it completely. if you're using an IDE, you could be seduced into thinking that your CLASSPATH is all set because you have a system environment variable.

ClassNotFoundException means CLASSPATH to me. I'd revisit whether or not you really have that JAR in the CLASSPATH.

I might write that method this way to make it more general:



I prefer spelling out the parameters rather than passing in an array because it makes clear to clients what they need to provide and the proper order.
 
Patrick Ferguson
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I appreciate your reply, but I'm not here for a coding lesson. This is basically a hello world type app while I try to get the oracle driver loaded. My real code is much different, but the point remains that it is failing when I try to load the oracle driver.

I have tried the classes12.jar in my path, as well as the ojdbc14.jar in my path. Each by themselves. I have probably tried 20 different classpath configurations, it's more like it can't read the driver out of the file. I checked file permissions on the .jar files and everything is open.

I am using an oracle 8i database.

I have not tried the process on UNIX yet (a place I have gotten similar applications to work), that's sort of a last resort.
 
Bartender
Posts: 10336
Hibernate Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Run your class from the command line with the -verbose flag. This will list all the classes the class loader loads. So, if your class is on the classpath you will see a "[Loaded oracle.jdbc.driver.OracleDriver from ....]" message. If you don't see the message there is something wrong with the classpath.

If you do, and you still can't load the class, then you have a very, very odd problem.
[ October 17, 2005: Message edited by: Paul Sturrock ]
 
Patrick Ferguson
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have already run with verbose and the oracle classes do NOT show, but I am 100% positive the ojdbc14.jar file is on the classpath.
 
Paul Sturrock
Bartender
Posts: 10336
Hibernate Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
So there is no "[Loaded oracle.jdbc.driver.OracleDriver from ....]" message appearing in the verbose output? Then it is (without doubt) a classpath problem.
 
Patrick Ferguson
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Well if it's for sure a classpath issue, do you know why it would not work when I have it in my classpath? This is a windows 2000 OS. And I KNOW I have it in my classpath, I'm looking at it right now.
 
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
One way to verify the Class can be found on the calsspath is to use javap. Like this:

If it is found you'll see methods and stuff. otherwise it will output:


Dave
 
Paul Sturrock
Bartender
Posts: 10336
Hibernate Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Well, the verbose output logs each class as it is loaded by a ClassLoader. ClassLoaders can only load resources which are in the classpath. So if there is no message, the class is not on the classpath.

You can double check this another way - write a quick program to load the class as a resource (i.e. with Class.getClassLoader().getResource("/oracle/jdbc/driver/OracleDriver.class") ;) . I the URL is null, the resource is not on the classpath (this has the extra bonus that if it isn't, the toString() method of URL logs the absolute path to the resource).

What do you do if the class still can't be found?
  • Double check the classpath is as you believe it to be - the output with -verbose will list the classpath too.
  • Check the integrity of the jar file you believe the class is in. (Long shot - perhaps you've managed to corrupt it in some way?)
  • Simplify things - write a program which you can run with only that jar in the classpath (the getResource example is a good candidate)



  • (javap: a new one to me - ah well, you learn something every day)

    [ October 18, 2005: Message edited by: Paul Sturrock ]
    [ October 18, 2005: Message edited by: Paul Sturrock ]
     
    David O'Meara
    Rancher
    Posts: 13459
    Android Eclipse IDE Ubuntu
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    All this time and no-one thought to check the driver class.

    You should be using oracle.jdbc.OracleDriver and not oracle.jdbc.driver.OracleDriver
    Hopefully this makes everything OK.

    Dave
     
    Patrick Ferguson
    Ranch Hand
    Posts: 30
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    I've tried both oracle.java.OracleDriver and oracle.java.jdbc.OracleDriver

    I also thought about a corrupt .jar file and I'm checking on that now.

    An interesting things is that when I run the javap on oracle.java.OracleDriver the class is not found, but when I run it on oracle.java.jdbc.OracleDriver it does find it.
     
    Patrick Ferguson
    Ranch Hand
    Posts: 30
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    Correction, I typed that incorrectly. It's oracle.jdbc.OracleDriver. And that one is found.
     
    Paul Sturrock
    Bartender
    Posts: 10336
    Hibernate Eclipse IDE Java
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    DOH!

    I guess they must have refactored their package structure. Ah well, if nothing else an abject lesson in being careful what you put in your classpath, particularly if you end up putting a similar class in twice.
     
    Patrick Ferguson
    Ranch Hand
    Posts: 30
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    No, I used the proper one in the classpath, I typed the wrong one just now.

    It's something very odd, and if it's a classpath issue I've never seen one like this.
     
    Patrick Ferguson
    Ranch Hand
    Posts: 30
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    Okay, after 3 days of fighting this I finally got it to work with this command.

    java -classpath C:\Oracle\product\10.1.0\Client_2\jdbc\lib\ojdb
    4.jar;C:\Oracle\product\10.1.0\Client_2\jdbc\lib\orai18n.jar;. CreateSyncFiles

    I don't know if it was the orai18n.jar or the period to signify the current directory(I think it was the orai18n.jar).

    But I'm getting drunk tonight in celebration!!

    Thanks everyone who had suggestions.
     
    When all four tires fall off your canoe, how many tiny ads does it take to build a doghouse?
    Gift giving made easy with the permaculture playing cards
    https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
    reply
      Bookmark Topic Watch Topic
    • New Topic