The Artima Developer Community
Sponsored Link

Java Answers Forum
importing a package from a sibling directory

9 replies on 1 page. Most recent reply: Sep 21, 2003 5:04 PM by Joe Parks

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 9 replies on 1 page
Laurence Bier

Posts: 8
Nickname: sandman99
Registered: Sep, 2003

importing a package from a sibling directory Posted: Sep 16, 2003 9:06 PM
Reply to this message Reply
Advertisement
I have a file AccountManipulation.java in folder accountmanipulationpackage. AccountManipulation.java is a package used by a java program located two folders up.

AccountManipulation.java itself imports a package customerdatapackage ("import bankutilities.customerdatapackage.*;") which is located in customerdatapackage, a folder on the same level as accountmanipulationpackage. Both accountmanipulationpackage and customerdatapackage are located in the bankutilities folder.

The import, however, triggers a "package bankutilities.customerdatapackage does not exist" - customerdatapackage does exist and folder name matches spelling.

I have no issues with the app which imports both these packages from the root.

Any ideas?


mausam

Posts: 243
Nickname: mausam
Registered: Sep, 2003

Re: importing a package from a sibling directory Posted: Sep 16, 2003 9:39 PM
Reply to this message Reply
Did u declare the package for all the java files in customerdatapackage

like
package bankutilities.customerdatapackage;

then start
ur import statements like...

import *.*.* >>>>>

Else make sure to add the folder in the classpath

Laurence Bier

Posts: 8
Nickname: sandman99
Registered: Sep, 2003

Re: importing a package from a sibling directory Posted: Sep 17, 2003 9:39 PM
Reply to this message Reply
>Did u declare the package for all the java files in >customerdatapackage

>like
>package bankutilities.customerdatapackage;

Yes.

>then start
>ur import statements like...

>import *.*.* >>>>>

I'm not clear on what you mean here. I tried:

import *.customerdatapackage;

and I get:

<identifier> expected

>Else make sure to add the folder in the classpath

Rahul

Posts: 52
Nickname: wildhorse
Registered: Oct, 2002

Re: importing a package from a sibling directory Posted: Sep 17, 2003 10:33 PM
Reply to this message Reply
You need to use a fully qualified class name to use a package's class or can import all public classes from the package using the wildcard .*

e.g. import bankutilities.customerdatapackage.CustomerClass;
or
import bankutilities.*;

Joe Parks

Posts: 107
Nickname: joeparks
Registered: Aug, 2003

Re: importing a package from a sibling directory Posted: Sep 18, 2003 12:41 PM
Reply to this message Reply
> or
> import bankutilities.*;

This will not work. You must go down to the package within which the imported class resides (bankutilities.customerdatapackage.*

From which directory are you invoking javac?
It should be from the directory above bankutilities.

Laurence Bier

Posts: 8
Nickname: sandman99
Registered: Sep, 2003

Re: importing a package from a sibling directory Posted: Sep 18, 2003 8:42 PM
Reply to this message Reply
This is still not working - I'm not sure what I'm doing wrong.

There is one main file with two packages. The main file is at: C:\TabbedPaneApp.java. The two packages are at:

C:\bankutilities\accountmanipulationpackage\AccountManipulation.java

and:

C:\bankutilities\customerdatapackage\CustomerData.java

CustomerData.java compiles without any problems.

When I try using either import bankutilities.customerdatapackage.*; or import bankutilities.customerdatapackage.CustomerData; I get the error, "package bankutilities.customerdatapackage does not exist".

At the first line of CustomerData.java is "package bankutilities.customerdatapackage;"

Is there anything that stands out here?

Laurence Bier

Posts: 8
Nickname: sandman99
Registered: Sep, 2003

Re: importing a package from a sibling directory Posted: Sep 18, 2003 8:45 PM
Reply to this message Reply
This is still not working - I'm not sure what I'm doing wrong.

There is one main file with two packages. The main file is at: C:\TabbedPaneApp.java. The two packages are at:

C:\bankutilities\accountmanipulationpackage\AccountManipulation.java

and:

C:\bankutilities\customerdatapackage\CustomerData.java

CustomerData.java compiles without any problems.

When I try using either import bankutilities.customerdatapackage.*; or import bankutilities.customerdatapackage.CustomerData; I get the error, "package bankutilities.customerdatapackage does not exist".

At the first line of CustomerData.java is "package bankutilities.customerdatapackage;"

Is there anything that stands out here?

Joe Parks

Posts: 107
Nickname: joeparks
Registered: Aug, 2003

Re: importing a package from a sibling directory Posted: Sep 19, 2003 6:23 AM
Reply to this message Reply
The only way that I am able to duplicate your error message is by invoking javac from within one of the package directories. For example
C:\bankutilities\accountmanipulation>javac AccountManipulation.java

If, using your directory structure, I invoke javac from c:\ then everything compiles correctly.
In fact, if I call
C:\>javac bankutilities\accountmanipulation\AccountManipulation.java
CustomerData.java gets compiled automatically if its class file is out of date.

If you still cannot get this to work, can you copy and paste your entire DOS session in a reply?

-Joe

Laurence Bier

Posts: 8
Nickname: sandman99
Registered: Sep, 2003

Re: importing a package from a sibling directory Posted: Sep 20, 2003 2:08 PM
Reply to this message Reply
Thank you for all the time you've put into this.

>If, using your directory structure, I invoke javac from >c:\ then everything compiles correctly.
>In fact, if I call
>C:\>javac >bankutilities\accountmanipulation\AccountManipulation.java
>CustomerData .java gets compiled automatically if its class >file is out of date.

>If you still cannot get this to work, can you copy and >paste your entire DOS session in a reply?

Hmmm...strange and amazing. When I compile it from the command line it works - I only have issues when I compile it from my IDE (textpad). I am able to compile files that are deeper than C:\ without any problems.

Thank you very much again for your patience and perseverance on this one.

Joe Parks

Posts: 107
Nickname: joeparks
Registered: Aug, 2003

Re: importing a package from a sibling directory Posted: Sep 21, 2003 5:04 PM
Reply to this message Reply
You can configure TextPad to get past this by changing the "Initial Folder" property of the tool, "Compile Java".

Flat View: This topic has 9 replies on 1 page
Topic: Rounding In Java Previous Topic   Next Topic Topic: Applet: Writing to File

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use