Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Running class inside package in java from Cmd?

 
Hamzah khammash
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 .
 
John Jai
Rancher
Posts: 1776
 
Sagar Dabas
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