File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Beginning Java and the fly likes How to compile a package Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "How to compile a package" Watch "How to compile a package" New topic

How to compile a package

sumaraghavi ragha
Ranch Hand

Joined: Nov 17, 2006
Posts: 118
please tell me how to comile a simple pack.

MY directory structure is like this

in Bin i have created a directory called MYpack
inthat i have a class caleed

So please tell me how to compile it.hOW I HAVE TO CJANGE THE CLASSPATH SETTINGS

[edit]Disable smilies. CR[/edit]
[ June 05, 2008: Message edited by: Campbell Ritchie ]
marc weber

Joined: Aug 31, 2004
Posts: 11343

The file that you are compiling is, which is in the MYpack directory. This is the file location that you need to provide to javac.

But the resulting class file will be identified by its qualified name, which includes the package. So when specifying the class for java to run, use MYpack.mypack. Understand that the class "MYpack.mypack" is not in the MYpack directory, but is instead in the bin directory.

So change the current directory to c:\pro\java\jdk\bin, then compile with...

javac MYpack\

...and run with...

java MYpack.mypack
[ June 05, 2008: Message edited by: marc weber ]

"We're kind of on the level of crossword puzzle writers... And no one ever goes to them and gives them an award." ~Joe Strummer
marc weber

Joined: Aug 31, 2004
Posts: 11343

By the way, I hope this is not the "bin" directory that contains your JDK's files. You should not be mixing your own files with the JDK's.
Campbell Ritchie

Joined: Oct 13, 2005
Posts: 46337
Don't put your files in the bin directory; start new directory for your applications.

What package declaration have you got in your classes?

If the package name is the same as the folder they are in, compile with javac then go up one level in the directory structure and execute it with java mypackage.MyClass.
If the package name is different from the folder name compile with javac -d . and execute with java mypackage.MyClass rom the same directory.

You ONLY have to change the classpath if you are importing any other .jar files.
I agree. Here's the link:
subject: How to compile a package
jQuery in Action, 3rd edition