Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Agile forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

NoClassDefFoundError

 
Gemini Moses
Ranch Hand
Posts: 245
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I compiled and run my test.java file successfully on my local machine.

Now I am trying to run the same file on our unix box and coming acoross an error when I try to run the program

After setting the class path properly the file complied successfully and created test.class file.

Now when I try to run the file providing required parameters I am getting--

Exception in thread "main" java.lang.NoClassDefFoundError: oracle/jdbc/driver/OraclePreparedStatement

I did search the forums and it tells me this has something to do with classpath setting. But not getting any exact leads.

Can someone please help me.

Thanks!
 
Ernest Friedman-Hill
author and iconoclast
Marshal
Pie
Posts: 24208
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The Oracle driver JAR has to be on your class path. See http://faq.javaranch.com/view?HowToSetTheClasspath .
 
Ryan McGuire
Ranch Hand
Posts: 1055
4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Do you use the same classpath at run time that you did at compile time? That's the first thing to look at.

However additional files may be required at run time that weren't needed at compile time. If the class for your JDBC driver is set in a config file, your program may be using Class.forName(driverClassName) to instantiate an instance of the driver. The compiler has no way of catching this, so it won't show up until you run the program.

So where is OraclePreparedStatement.class? It's probably buried in a jar file that you have available on your local machine, since the app runs there. It might be in something like $ORACLE_HOME/jdbc/lib/ojdbc14.jar. Add that to your run time classpath.

Ryan
[ April 26, 2005: Message edited by: Ryan McGuire ]
 
Gemini Moses
Ranch Hand
Posts: 245
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for your reply.

I do not see ojdbc14.jar under the directory were I found
classes12.jar and 111.jar.

There is a file called-
ocrs12.jar in this directory.

I added this in classpath and run the file. but again the same error.

I can not search directories for ojdbc14.jar with my prevs. Will have to wait for Unix person to do this search. (I tried looking manually at few places that I could..)

If you have any other suggestions please let me know. I have been breaking my head over this problem for long now..

[ April 26, 2005: Message edited by: Gemini Moses ]
 
Ryan McGuire
Ranch Hand
Posts: 1055
4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Look for ANY ojdbc*.jar file. The 14 is just what version I have. Try this on your Unix machine:

(I assume you have some way of setting $ORACLE_HOME.) If that doesn't come up with any filenames, try...


...and look for any file that looks promising. You could get real clever and try this:


Ryan
 
Jon Egan
Ranch Hand
Posts: 83
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Gemini,

I wonder if I might be missing something - you mentioned "where I found classes12.jar"...

I know that previous versions of the Oracle JDBC driver were in a file named "classes12.zip" (and as far as I can remember, the ZIP went in the classpath, and worked like a JAR - been a while, so that sounds iffy now). And in the later version that I am familiar with, it is in ojdbc14.jar... seems reasonable that in the middle at some point it may have been named classes12.jar.

... so I wonder if the classes12.jar you already found is the one you need. But then, you've mentioned it, which makes me think this might be something you already have in your classpath?

Or else, like I said, I'm missing something...

One last thing, that might help tip someone off to the real problem: do you have "oracle.jdbc.driver.OraclePreparedStatement" explicitly in your program? Or is that coming from your program referencing "PreparedStatement", and the specific reference to OraclePreparedStatement is burried in their code? If you're not sure, you can inspect the stack trace for the NoClassDefFoundError.

One (more?) last thing: maybe you could just download the JDBC driver from Oracle's site instead of trying to find it on your system.

Good luck, hope this helps.

-- Jon
 
Gemini Moses
Ranch Hand
Posts: 245
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Jon & Ryan for your replies.

I could find ojdbc14.jar in directory under 9.2.0.3_for_OC/jdbc/lib
WHere as classes12.zip and 111.zip are under
9.2.0.1/jdbc/lib/

(Sorry it was typo by me in saying .jar instead of .zip)

I included these in my classpath. and now the error related to prepared statement is gone.

But now I am getting an error about the class that I am running
Exception in thread "main" java.lang.NoClassDefFoundError: test

test.java is the file that compiled which created test.class file.

I have included current directory in the classpath. My .java file does not have nay package statepement in it.

Do i need to add anything to path here?

Please help
Thanks!

Gemini
[ April 27, 2005: Message edited by: Gemini Moses ]
 
Gemini Moses
Ranch Hand
Posts: 245
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Guyes for your replies!

I got it working here...

I had inlcuded current directory in my CLASSPATH by passing actual directory address. Which did not work.

I changed it to include current drectory by passing . now. and that solved the problem.

Thanks again for all your help!

Gemini
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic