Re: a little confused about packages...
- From: "Bjorn Abelli" <bjorn_abelli@xxxxxxxxxxxxxxxxxxxxx>
- Date: 29 Jun 2006 11:26:55 +0200
<jon23d@xxxxxxxxx> wrote...
javac TestPkg.java <--- this works fine
java TestPkg <---- this doesn't!
This is what I've used up until I started using packages,
and has worked fine...
When you use packages, the package name is a part of the full class name.
Let's say that you are in the directory
~/devel/java/TestPkg/
....when you compile with
javac TestPkg.java
This will create the following class file:
~/devel/java/TestPkg/TestPkg.class
Which means that you will have to move up one directory:
~/devel/java/
....to be able to execute it with:
java TestPkg.TestPkg
This is because the packages in Java are used for both logical and physical
structures.
The package name is in Java also a designator of the physical structure, how
to organize classes on the disk or in a jar, but as they are foremost a
designator in order to organize them logically according to their use, you
need the full name (incl. package name), when using them.
That is why you use "import" for some classes in other packages (the logical
organization), but might also need -cp in order to find them (the physical
organization).
When you compile and execute from within an IDE, you should be especially
careful, as most of such IDEs also creates the directory structure when
finding out that a class is within a package.
// Bjorn A
Inviato da X-Privat.Org - Registrazione gratuita http://www.x-privat.org/join.php
.
- References:
- a little confused about packages...
- From: jon23d
- Re: a little confused about packages...
- From: Petterson Mikael
- Re: a little confused about packages...
- From: jon23d
- a little confused about packages...
- Prev by Date: Re: a little confused about packages...
- Next by Date: Re: Represent work in progress on std out
- Previous by thread: Re: a little confused about packages...
- Next by thread: Re: a little confused about packages...
- Index(es):
Relevant Pages
|