• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

How to compile a package

 
Ranch Hand
Posts: 118
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
 
Sheriff
Posts: 11343
Mac Safari Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Mac Safari Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Marshal
Posts: 79177
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
I've read about this kind of thing at the checkout counter. That's where I met this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic