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 Working with Packages Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Working with Packages" Watch "Working with Packages" New topic

Working with Packages

Maureen Charlton
Ranch Hand

Joined: Oct 04, 2004
Posts: 218
I have created a directory called: C:\java\BankAccount

Within this directory I have 3 files.
- these files are not doing anything at the moment, all have a main bit with nothing in them

The 3 files within the directory C:\java\BankAccount have at the top:
package BankAccount;

I have a file called in the directory C:\java\
This file has the following at the top:
import BankAccount.*;

When I compile c:\java\
my book says it should compile i.e. produce .class files for all files in the BankAccount package i.e. c:\java\BankAccount\

This is not happening though and I haven't a clue as to why as I have done everything it says in the book.

Is anyone able to help me work out, from the information above, why my files in the package BankAccount are not compiling when I compile TestClass file?

Thanking you in advance.
joseph mcgratton
Ranch Hand

Joined: Feb 15, 2005
Posts: 41
hi there.

nobodies replied to you yet so i thought i would, although i probably wont be much use - im a newbie hehe. You mentioned your directories - as far as i remember in reading java books, everything must be in the same folder when you compile. would moving all files into 1 folder help?

Maureen Charlton
Ranch Hand

Joined: Oct 04, 2004
Posts: 218

Welcome to javaranch and many thanks for your response.

The files are intended to be in another directory/folder than the file.
Carol Enderlin
Ranch Hand

Joined: Oct 10, 2000
Posts: 1364
Does your TestClass use the classes that are in the BankAccount package?Are you getting any errors when you compile?

Maybe you could post some code and your compiler output.
Dave Cryder

Joined: Aug 11, 2004
Posts: 9
OK...I thinkI know what might be going on.

When import a package, you are basically telling the compiler "if you can't find what you need in this file, here is a list of places to check." If the class in the current file isn't actually using anything in the packages, it won't look for them, and it therefore won't notice that they are in need of recompiling.

Are you actually trying to declare any objects to be of the types in package BankAccount?

If this isn't what's causing it, it could be because of a problem with the classpath you are using, but that should produce a compile-time error.

Hope this helps.
Maureen Charlton
Ranch Hand

Joined: Oct 04, 2004
Posts: 218

Many thanks for your response.

All classes are empty at the moment i.e. nothing in them - maybe that's my problem. I will put something in them and see whether I have the same problem.

I just wanted to see whether it worked i.e. I thought it was good to have a number of classes, then put them in a package and compile a TestClass that would compile everything. Thought it would save me alot of time. - better than doing javac then java on each file!

I had no compiler error just received no class files in the package directory.
I agree. Here's the link:
subject: Working with Packages
It's not a secret anymore!