wood burning stoves 2.0*
The moose likes Beginning Java and the fly likes packages Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "packages" Watch "packages" New topic
Author

packages

rajajee
Greenhorn

Joined: Mar 22, 2002
Posts: 4
Dear Jexperts;
how to run the main() in the following class?
package myPack;
public class TestPack {
public static void main (String [] args){
System.out.println("HelloWorld");
}
}
Dave Vick
Ranch Hand

Joined: May 10, 2001
Posts: 3244
rajajee
Welcome to the Java Ranch, we hope you’ll enjoy visiting as a regular however,
your name is not in keeping with our naming policy here at the ranch. Please change your display name to an appropriate name as shown in the policy.
Thanks again and we hope to see you around the ranch!!


Dave
Sigfred Zamo
Ranch Hand

Joined: Mar 04, 2002
Posts: 44
You must put your source file in a subdirectory called myPack.


Sigfred Zamo<br />Software Development<p><a href="http://www.sigfredo.ingenieros.net/index2.html" target="_blank" rel="nofollow">My page</a>
Anthony Villanueva
Ranch Hand

Joined: Mar 22, 2002
Posts: 1055
And then compile it with javac. Finally, run it with
java myPack.TestPack
The fully qualified named is mandatory for packaged .class files.
-anthony
Sal Velinus
Greenhorn

Joined: Mar 05, 2002
Posts: 25
Originally posted by Anthony Villanueva:
And then compile it with javac. Finally, run it with
java myPack.TestPack
The fully qualified named is mandatory for packaged .class files.
-anthony

Not if you're in the myPack directory when you run the program,or is that wrong?
Anthony Villanueva
Ranch Hand

Joined: Mar 22, 2002
Posts: 1055
Go up one level then run
java myPack.TestPack
-anthony
rajajee
Greenhorn

Joined: Mar 22, 2002
Posts: 4
Dear Anthony and all others;
Thanks for your replies. It does not work, however. Please try to compile and run the code yourself and then please let me 'a beginner' know your expert comments.
Once again thanks a lot.
Rajajee
Sigfred Zamo
Ranch Hand

Joined: Mar 04, 2002
Posts: 44
Well, suposse your java source home directory is c:\java. Suposse your classpath environment variable is set to CLASSPATH=c:\java.
If you make a dir: c:\java\TestPack and put your TestPack.java file in it and then compile it, you�ll have a TestPack.class file.
If you try to execute your class in c:\java\TestPack dir as shown:
java TestPack
the JavaVirtualMachine will find your class
(At least, my JVM could)
Cindy Glass
"The Hood"
Sheriff

Joined: Sep 29, 2000
Posts: 8521
Works just fine.
Prints out HelloWorld.
hmmm. . . If you say the TestPack is in packaqe myPack, then you have to be sure that it IS in myPack. Go look in that directory and see if the TestPack.class file is actually there. If not, put it there (it is not nice to lie to the JVM).
Then go to the directory that the myPack folder is in and run
>java myPack.TestPack


"JavaRanch, where the deer and the Certified play" - David O'Meara
Sigfred Zamo
Ranch Hand

Joined: Mar 04, 2002
Posts: 44
Sorry, I�m wrong, Cindy is correct.
It�s necesary execute your class in the root directory with his full name
dir1.dir2. (..) .yourclass
having your packaged class in the root/dir1/dir2/ .. /yourclass.class directory.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: packages