I need to know about package ???

Discussion in 'Java' started by Siripong, May 8, 2004.

  1. Siripong

    Siripong Guest

    Dear All
    I am a new java programmer and now I have some problem about java.
    I have 2 files java programs.
    This is a first file (User.java)

    package usejava;

    import java.io.*;

    public class User
    {
    public String Name;

    public User()
    {
    Name = "I am the man";
    }
    }

    I can compile this file by this command

    javac User.java

    I can get file User.class .
    And second file is Login.java .

    import usejava.*;

    import java.io.*;

    public class Login
    {
    public static void main(String args[])
    {
    User u = new User();
    System.out.println(u.Name);
    }
    }


    When I compile second file I got error "Don't know package
    usejava.*"
    So I create jar file by this command.

    jar cf usejava.jar *.class

    And set CLASSPATH by this command.

    CLASSPATH=/root/usejava.jar;export CLASSPATH;

    And I compile second file again I got same error. Please let's me
    know what happend and how to fix this problem.

    Best Regards,
    Mod X
     
    Siripong, May 8, 2004
    #1
    1. Advertising

  2. Siripong

    Ben Wilson Guest

    Try recompiling your original file as follows:

    javac -d . User.java

    Your User.class is probably not in the directory "usejava" so javac can't
    find it when it goes to compile Login.java. Read up on the "-d" flag of
    javac for more information.



    "Siripong" <> escribba innemesiage
    news:...
    > Dear All
    > I am a new java programmer and now I have some problem about java.
    > I have 2 files java programs.
    > This is a first file (User.java)
    >
    > package usejava;
    >
    > import java.io.*;
    >
    > public class User
    > {
    > public String Name;
    >
    > public User()
    > {
    > Name = "I am the man";
    > }
    > }
    >
    > I can compile this file by this command
    >
    > javac User.java
    >
    > I can get file User.class .
    > And second file is Login.java .
    >
    > import usejava.*;
    >
    > import java.io.*;
    >
    > public class Login
    > {
    > public static void main(String args[])
    > {
    > User u = new User();
    > System.out.println(u.Name);
    > }
    > }
    >
    >
    > When I compile second file I got error "Don't know package
    > usejava.*"
    > So I create jar file by this command.
    >
    > jar cf usejava.jar *.class
    >
    > And set CLASSPATH by this command.
    >
    > CLASSPATH=/root/usejava.jar;export CLASSPATH;
    >
    > And I compile second file again I got same error. Please let's me
    > know what happend and how to fix this problem.
    >
    > Best Regards,
    > Mod X
     
    Ben Wilson, May 8, 2004
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. DP
    Replies:
    0
    Views:
    1,145
  2. Lasse Laegteskov
    Replies:
    1
    Views:
    496
    Rune Berge
    Jun 1, 2004
  3. Replies:
    2
    Views:
    294
    Victor Bazarov
    Jan 25, 2007
  4. Daniel
    Replies:
    11
    Views:
    701
    =?ISO-8859-1?Q?Arne_Vajh=F8j?=
    Apr 29, 2007
  5. Andries

    I know, I know, I don't know

    Andries, Apr 23, 2004, in forum: Perl Misc
    Replies:
    3
    Views:
    240
    Gregory Toomey
    Apr 23, 2004
Loading...

Share This Page