Ho creato la struttura
c:\tmp\prova\mygame
con le sottocartelle
c:\tmp\prova\mygame\client
c:\tmp\prova\mygame\server
c:\tmp\prova\mygame\shared
in ..\client ho messo Client.java
in ..\server ho messo Server.java
in ..\shared ho messo Utilities.java
la CLASSPATH è C:\tmp\prova\mygame
Utilities.java
codice:
package mygame.Shared;
public class Utilities {
// set DEBUG = false and compile to stop debug messages
final static boolean DEBUG = true;
public static void printMsg(String msg) {
if (DEBUG) {
System.out.println(msg);
}
}
}
La compilazione è OK
Client.java
codice:
package mygame.client;
import java.io.*;
import java.net.*;
import java.util.*;
import mygame.Shared.*;
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;
}
}
}
Quando compilo Client l'errore è Client.java:36: Package mygame.Shared does not exists
Marzio