• 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:
  • Campbell Ritchie
  • Bear Bibeault
  • Devaka Cooray
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Knute Snortum
  • Junilu Lacar
  • paul wheaton
Saloon Keepers:
  • Ganesh Patekar
  • Frits Walraven
  • Tim Moores
  • Ron McLeod
  • Carey Brown
Bartenders:
  • Stephan van Hulst
  • salvin francis
  • Tim Holloway

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.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!