• 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
  • Liutauras Vilda
  • Tim Cooke
  • Paul Clapham
  • Jeanne Boyarsky
Sheriffs:
  • Ron McLeod
  • Frank Carver
  • Junilu Lacar
Saloon Keepers:
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Al Hobbs
  • Carey Brown
Bartenders:
  • Piet Souris
  • Frits Walraven
  • fred rosenberger

having different class and file names

 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have a single main class in my file. I give my file a name which is different from the class name. The class is not public. I use eclipse. It runs successfully (it wouldnt have, if it had a public modifier), when I run it through eclipse. But when i try to compile and run it through jdk, it compiles fine but gives the following exception:

Exception in thread "main" java.lang.NoClassDefFoundError: rat

The file name is "rat.java" and the class name is "tar". I need some explanation why this is so.
 
Ranch Hand
Posts: 70
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi -
After you compile - notice that the compiler will create a tar.class file, and when you run the program you need to enter then name of the .class file which is tar.class - after the java command

e.g 'java tar' (instead of 'java rat')

i guess this is because there is no .class file called rat and therefore the classloader is looking for the file with the extension .class file. which is the 1 created after compiling.

Hope this helps.

Regards,
Siphiwe M
 
Ratnankur Kushary
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Siphiwe Madi:
Hi -
After you compile - notice that the compiler will create a tar.class file, and when you run the program you need to enter then name of the .class file which is tar.class - after the java command

e.g 'java tar' (instead of 'java rat')

i guess this is because there is no .class file called rat and therefore the classloader is looking for the file with the extension .class file. which is the 1 created after compiling.

Hope this helps.

Regards,
Siphiwe M




Hi Siphiwe,

Thanks for your help. But this i already know. I really wanted to know how the eclipse IDE tackles this situation then. In eclipse we dont have to compile it explicitly, it is done real-time, i.e, the .class file is automatically created. But if it really cant find rat.class file as you said, then how does it run the program. The scenario is different from standard jdk.
[ September 07, 2007: Message edited by: Ratnankur Kushary ]
 
Siphiwe Madi
Ranch Hand
Posts: 70
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Ratnankur,

I'm not understanding when you say you run the program through JDK, can you explain to me that part?

Thanks.

Siphiwe
 
Ratnankur Kushary
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Siphiwe Madi:
Hi Ratnankur,

I'm not understanding when you say you run the program through JDK, can you explain to me that part?

Thanks.

Siphiwe



Hi Siphiwe,

Sorry for the late reply. Actually by running it through jdk, i mean from the command prompt when i execute "javac rat.java", it compiles fine. But when i run it using "java rat", it gave the exception. My question was that how does eclipse handle that situation?
 
Whoever got anywhere by being normal? Just ask this exceptional tiny ad:
Garden Master Course kickstarter
https://coderanch.com/t/754577/Garden-Master-kickstarter
reply
    Bookmark Topic Watch Topic
  • New Topic