Win a copy of The Journey To Enterprise Agility this week in the Agile and Other Processes forum! And see the welcome thread for 20% off.
  • 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:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
Sheriffs:
  • Paul Clapham
  • Junilu Lacar
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Ganesh Patekar
  • Tim Moores
  • Pete Letkeman
  • Stephan van Hulst
Bartenders:
  • Carey Brown
  • Tim Holloway
  • Joe Ess

Running class inside package in java from Cmd?  RSS feed

 
Greenhorn
Posts: 23
Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello
i have a class called Hamzah inside a package called hamzah i tried to run it from Command line but always i have NoClassDefFoundError the class compiled correctly and .class file produced but it didn't run
i try to do the following :


<C:\Users\h.khammash\Desktop\Studening workspace\TestCmd\src\com\hamzah>javac Hamzah.java>


Compiled successfully

and this for run :

C:\Users\h.khammash\Desktop\Studening workspace\TestCmd\src\com\hamzah>java -cp . Hamzah


Error here .
 
Rancher
Posts: 1776
 
Ranch Hand
Posts: 47
C++ Java PHP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
do this ....

1. For compiling go into the folder where you java file is :
==> C:\Users\h.khammash\Desktop\Studening workspace\TestCmd\src\com\hamzah>javac Hamzah.java>

2. Then come out all of your packages :
==> C:\Users\h.khammash\Desktop\Studening workspace\TestCmd\src\com\hamzah>cd..

3. Then use fully qualified name to run your class.
C:\Users\h.khammash\Desktop\Studening workspace\TestCmd\src\com>java hamzah.Hamzah

This is the method which I found, please somebody explain why do we have to do this. Does compiler don't know about packages whereas JVM know ?
 
Hamzah khammash
Greenhorn
Posts: 23
Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Sagar Dabas wrote:do this ....

1. For compiling go into the folder where you java file is :
==> C:\Users\h.khammash\Desktop\Studening workspace\TestCmd\src\com\hamzah>javac Hamzah.java>

2. Then come out all of your packages :
==> C:\Users\h.khammash\Desktop\Studening workspace\TestCmd\src\com\hamzah>cd..

3. Then use fully qualified name to run your class.
C:\Users\h.khammash\Desktop\Studening workspace\TestCmd\src\com>java hamzah.Hamzah

This is the method which I found, please somebody explain why do we have to do this. Does compiler don't know about packages whereas JVM know ?




I found a solution for this
C:\Users\h.khammash\Desktop\Studening workspace\TestCmd\src\>java -cp . com.hamzah.Hamzah
-cp must be exist to run.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!