Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to compile a package

 
sumaraghavi ragha
Ranch Hand
Posts: 118
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 11343
Java Mac Safari
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
marc weber
Sheriff
Posts: 11343
Java Mac Safari
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 48981
60
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic