aspose file tools*
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


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "How to compile a package" Watch "How to compile a package" New topic
Author

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
C:pro\java\jdk\bin

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

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

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

Joined: Aug 31, 2004
Posts: 11343

The file that you are compiling is mypack.java, 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\mypack.java

...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
sscce.org
marc weber
Sheriff

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
Sheriff

Joined: Oct 13, 2005
Posts: 36599
    
  16
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 MyClass.java 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 . MyClass.java MyOtherClass.java 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: http://aspose.com/file-tools
 
subject: How to compile a package
 
Similar Threads
problem in saving a servlet prog..
How works the classpath
Unable to compile servlets
classpath problem
PATH & CLASSPATH?