Creating and Using Packages

Discussion in 'Java' started by thufir, Jan 17, 2005.

  1. thufir

    thufir Guest

    Creating and Using Packages
    @
    <http://java.sun.com/docs/books/tutorial/java/interpack/QandE/packages-answers.html>

    I want to add "import robocode.*;" to Client.java
    C:\robocode\robocode.jar is the packages path.

    How should "comp" be changed, specifically, please?
    (The "type" command is like "cat", BTW)

    C:\>javac @comp

    C:\>type comp
    -d C:\java\classes\
    -g
    -sourcepath C:\java\sources\
    -classpath C:\java\classes\

    C:\java\sources\mygame\client\Client.java
    C:\java\sources\mygame\server\Server.java
    C:\java\sources\mygame\shared\Utilities.java



    Thanks,

    Thufir Hawat
     
    thufir, Jan 17, 2005
    #1
    1. Advertisements

  2. thufir

    JScoobyCed Guest

    For help on Java basic, you should use
    comp.lang.java.help

    comp should be like:

    -d c:\java\classes
    -g
    -sourcepath c:\java\sources
    -classpath .;c:\java\classes\;c:\java\robocode.jar
     
    JScoobyCed, Jan 17, 2005
    #2
    1. Advertisements

  3. thufir

    Tony Morris Guest

    Tony Morris, Jan 17, 2005
    #3
  4. thufir

    thufir Guest

    With all due respect, please demonstrate how that link answers my
    question.
     
    thufir, Jan 17, 2005
    #4
  5. thufir

    thufir Guest

    (I didn't change the follow up to c.l.j.basic.)
    Unfortunately, it gives the following error:


    C:\>javac @comp
    C:\java\sources\mygame\client\Client.java:2: package robocode does not
    exist
    import robocode.*;
    ^
    1 error


    C:\>type C:\java\sources\mygame\client\Client.java
    package mygame.client;
    import robocode.*;

    import java.io.*;
    import java.net.*;
    import java.util.*;

    import mygame.shared.Utilities;

    public class Client extends Thread {
    Socket clientSocket = null;

    public Client(Socket s) {
    clientSocket = s;
    }

    public void run() {
    if (clientSocket == null) {
    return;
    }

    PrintStream out = null;

    Utilities.printMsg("creating output stream");

    try {
    out = new PrintStream(clientSocket.getOutputStream());
    } catch (IOException e) {
    System.err.println("Error binding output to socket, " + e);
    System.exit(1);
    }

    Utilities.printMsg("writing current date");

    Date d = new Date();
    out.println(d);

    try {
    out.close();
    clientSocket.close();
    } catch (IOException e) {
    }
    }

    protected void finalize() {
    if (clientSocket != null) {
    try {
    clientSocket.close();
    } catch (IOException e) {
    }
    clientSocket = null;
    }
    }
    }



    C:\>type comp
    -d C:\java\classes\
    -g
    -sourcepath C:\java\sources\;C:\robocode\
    -classpath .;c:\java\classes\;c:\java\robocode.jar

    C:\java\sources\mygame\client\Client.java
    C:\java\sources\mygame\server\Server.java
    C:\java\sources\mygame\shared\Utilities.java


    C:\>dir C:\robocode\
    Volume in drive C has no label.
    Volume Serial Number is #######

    Directory of C:\robocode

    01/16/2005 08:49a <DIR> .
    01/16/2005 08:49a <DIR> ..
    01/16/2005 08:49a <DIR> .robotcache
    01/16/2005 08:26a <DIR> battles
    01/16/2005 08:38a 252 compiler.properties
    01/16/2005 08:38a <DIR> compilers
    01/16/2005 08:26a <DIR> javadoc
    01/16/2005 08:26a 15,055 license.html
    01/16/2005 08:26a 31 robocode.bat
    01/16/2005 08:26a 2,104 robocode.ico
    01/16/2005 08:26a 554,696 robocode.jar
    01/16/2005 08:29a 161 robocode.properties
    01/16/2005 08:26a 41 robocode.sh
    01/16/2005 04:58p 10,903 robot.database
    01/16/2005 09:09a <DIR> robots
    01/16/2005 08:26a <DIR> templates
    01/16/2005 08:26a 29,632 versions.txt
    01/16/2005 09:33p 430 window.properties
    10 File(s) 613,305 bytes
    8 Dir(s) 5,001,740,288 bytes free
    C:\>



    Thanks,

    Thufir Hawat
     
    thufir, Jan 17, 2005
    #5
  6. thufir

    thufir Guest

    thufir, Jan 17, 2005
    #6
  7. thufir

    JScoobyCed Guest

    My mistake, the last part of classpath was c:\java\robocode.jar, and
    needs to be changed to c:\robocode\robocode.jar

    I should have written:

    -d c:\java\classes
    -g
    -sourcepath c:\java\sources
    -classpath .;c:\java\classes\;c:\robocode\robocode.jar
     
    JScoobyCed, Jan 17, 2005
    #7
  8. thufir

    thufir Guest

    Whee, it compiles!

    Muchos gracias,

    Thufir Hawat

    (If you're at fault for that mistake, i'm 2x as responsible for just
    copy/paste :)
     
    thufir, Jan 17, 2005
    #8
  9. thufir

    Tony Morris Guest

    It teaches you what packages are, what packages aren't, what they do, what
    they don't do, what they are for, what they aren't for, and in your case,
    how to use them.
    It's clear that you are unfamiliar with the concept.
     
    Tony Morris, Jan 22, 2005
    #9
  10. thufir

    thufir Guest

    Tony Morris wrote:
    [..]
    [..]

    Yes, you are correct on all accounts. That link, however, doesn't
    directly answer my question, which is why I asked it. AFAIK the exact
    scenario I gave isn't covered explicitly. Therefore, It's somewhat
    akin to saying "here, read this book," because the answer to a question
    can be obtained through understanding the book in its entirety.
     
    thufir, Jan 23, 2005
    #10
  11. thufir

    Tony Morris Guest

    Are you expecting that someone will assist you with every query you have
    that is based on the lack of understanding of packages?
    Or, are you expecting a pointer in the right direction to become more
    informed about the topic so that in the event that you do encounter a
    problem in the future, you can use it as a reference?

    I assumed the second scenario - I am an optimist.
    I deal with people who lack initiative every day - I am also a realist.
     
    Tony Morris, Jan 25, 2005
    #11
  12. thufir

    thufir Guest

    Tony Morris wrote:
    [..]
    I'm not sure where that comes from, since I didn't have many queries on
    that topic.
    That link is only one of several references needed to answer the
    original question. Allow me to re-iterate, that link doesn't answer
    the question which I asked.
    Excellent. This works out well since I'd already read extensively on
    javac, classpath and packages, including the link you pointed me to.
    Despite my attempts, I didn't know how to put that information
    together.
    realist.
    [..]

    ok....?

    Tony, I guarantee you I'll have more questions, hopefully you'll answer
    some of them. By the way, the post you responded to was canceled by me
    long ago because of its rudeness, for which I apologize.
     
    thufir, Jan 25, 2005
    #12
  13. thufir

    thufir Guest

     
    thufir, Jan 25, 2005
    #13
    1. Advertisements

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.