File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Beginning Java and the fly likes Java Runtime Error Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Java Runtime Error" Watch "Java Runtime Error" New topic

Java Runtime Error

suraj sheikh

Joined: Mar 07, 2008
Posts: 23

After surfing the World Wide Web, i got very little. It seems this is the only play where i can get help

Here is the problem :

I have a java program :

And i am usign this to get a connection with the database from a servlet,

the directory structure is :
C:\My Projects\BoaIntegratedWorkflow>java MyOracleConnection

It compiles fine,

but when i try to execute it the unwanted thing happens,

Exception in thread "main" java.lang.NoClassDefFoundError: MyOracleConnection (wrong name: com/system33/model/MyOracleConnection)
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(Unknown Source)
at Source)
at Source)
at$000(Unknown Source)
at$ Source)
at Method)
at Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClassInternal(Unknown Source)

this is no less than BLUE SCREEN OF DEATH for me.

It works fine and fetches data if i drop package declararion/defination at the begining..


This is my last hope, or i have to move to COBOL, ha ha
[ August 08, 2008: Message edited by: David O'Meara ]
Sachin Joshi
Ranch Hand

Joined: Aug 06, 2008
Posts: 83

You need to set the CLASSPATH envirnoment variable for the directory where you are storing the .class file.

If your MyOracleConnection.class file is in C:\MyCode directory then use this command


Then execute the java command it should work.

You may need to do this every time you close and reopen the Command prompt window.

Other way to avoid doing it again and again would be to go to

Right Click on My Computer -> Properties -> Advanced -> Environment Variables
Here create a new variable CLASSPATH (remember all caps and no mistake in spelling )

Enter the value C:\MyCode here ....

Hope this would help...

Web Development Tips and Tutorials - By Sachin
David O'Meara

Joined: Mar 06, 2001
Posts: 13459

If it is packaged as com.system33.model then it should exist somewhere on the runtime classpath as the file com/system33/model/MyOracleConnection.class

Once it is on the runtime classpath, you would run it as java com.system33.model.MyOracleConnection

It appears that the class was compiled correctly, but neither its location on the file system nor the method of execution are correct
Sachin Joshi
Ranch Hand

Joined: Aug 06, 2008
Posts: 83

Another thing I just noticed....

Looks like you have a package structure com/system33/model/MyOracleConnection

in this case you need to run the file like this

java com.system33.model.MyOracleConnection
Nitesh Kant

Joined: Feb 25, 2007
Posts: 1638

I think you must go through these tutorials:


apigee, a better way to API!
I agree. Here's the link:
subject: Java Runtime Error
It's not a secret anymore!