Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / First Aid / February 2004

Tip: Looking for answers? Try searching our database.

can not create package

Thread view: 
vertigo - 27 Feb 2004 10:35 GMT
Hello
The most simple example: i have two files:
Test.java:

import mypackage.*;
public class Test
{
    public static void main(String args[])
    {
        Greeting g= new Greeting("Hello ");
        g.greet("Name");
    }
}

and Greeting.java:
package mypackage;
public class Greeting
{
    private String salutation;
    public Greeting (String s)
    {
        salutation=s;
    }
    public void greet(String whom)
    {
        System.out.printlen(salutation+whom);
    }
}
when i try to compile it:
javac Test.java
it says that package mypackage does not exist. Why ?

Thanx
Kannan Ekanath - 27 Feb 2004 10:58 GMT
Is your class path set correctly ?
Your Greeting.java should be in the location
<some-dir>/mypackage/Greeting.java
the class path should include the directory <some-dir> under which
the java compiler should be able to find mypackage.Greeting

Thanks
Kannan

> Hello
> The most simple example: i have two files:
[quoted text clipped - 29 lines]
>
> Thanx
Andrew Thompson - 27 Feb 2004 15:27 GMT
>> Hello
>> The most simple example: i have two files:
[quoted text clipped - 27 lines]
>> javac Test.java
>> it says that package mypackage does not exist. Why ?

> Is your class path set correctly ?
> Your Greeting.java should be in the location
> <some-dir>/mypackage/Greeting.java
> the class path should include the directory <some-dir> under which
> the java compiler should be able to find mypackage.Greeting

Perhaps Kannan was simplifying for
the sake of a starter, but that
(above) is not the whole story.

Let us stick with that structure for
the moment though, 'source in same place
you want class'.

To compile the Greeting.java with a
.bat file located in that same directorym
you might put this in the .bat file

javac -classpath .. *.java

This tells javac that the 'root'
of the package, where Test resides.

HTH

Signature

Andrew Thompson
* http://www.PhySci.org/ Open-source software suite
* http://www.PhySci.org/codes/ Web & IT Help
* http://www.1point1C.org/ Science & Technology

vertigo - 27 Feb 2004 16:59 GMT
> javac -classpath .. *.java
>
> This tells javac that the 'root'
> of the package, where Test resides.

thanx, it is working :)
Oscar kind - 27 Feb 2004 16:48 GMT
> The most simple example: i have two files:
> Test.java:
>
> import mypackage.*;
> public class Test
[...]

> and Greeting.java:
> package mypackage;
> public class Greeting
[...]

> when i try to compile it:
> javac Test.java
> it says that package mypackage does not exist. Why ?

Where is Greeting.java located? It should be in a subdirectory named
"mypackage". Thus the directory you call javac from has this structure:
    Test.java
    mypackage/Greetings.java

Oscar

Signature

Oscar Kind                                    http://home.hccnet.nl/okind/
Java/J2EE Developer                             email available on website



Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.