File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes Running class inside package in java from Cmd? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Running class inside package in java from Cmd?" Watch "Running class inside package in java from Cmd?" New topic
Author

Running class inside package in java from Cmd?

Hamzah khammash
Greenhorn

Joined: Jan 05, 2012
Posts: 23

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
Bartender

Joined: May 31, 2011
Posts: 1776
Might help you - http://www.coderanch.com/t/562879/java/java/Help-Package-understanding
Sagar Dabas
Ranch Hand

Joined: Nov 15, 2011
Posts: 47

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 ?


Live Curious!!!
Hamzah khammash
Greenhorn

Joined: Jan 05, 2012
Posts: 23

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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Running class inside package in java from Cmd?