Creating and Using Packages

T

thufir

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
 
J

JScoobyCed

thufir said:
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

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
 
T

thufir

(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
 
J

JScoobyCed

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
 
T

thufir

Whee, it compiles!

Muchos gracias,

Thufir Hawat

(If you're at fault for that mistake, i'm 2x as responsible for just
copy/paste :)
 
T

Tony Morris

thufir said:
With all due respect, please demonstrate how that link answers my
question.

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.
 
T

thufir

Tony Morris wrote:
[..]
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.
[..]

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.
 
T

Tony Morris

thufir said:
Tony Morris wrote:
[..]
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.
[..]

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.

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.
 
T

thufir

Tony Morris wrote:
[..]
Are you expecting that someone will assist you with every query you have
that is based on the lack of understanding of packages?

I'm not sure where that comes from, since I didn't have many queries on
that topic.
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?

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.
I assumed the second scenario - I am an optimist.

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.
I deal with people who lack initiative every day - I am also a
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.
 
T

thufir

Tony said:
thufir said:
Tony Morris wrote:
[..]
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.
[..]

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.

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.
 

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. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top