So, i done search for this question..
My directories and files structure looks like (all *.java files have server package):
run2 (shell script)
[server] (folder)
\
\ Server.java
ClientThread.java
ServerConnectionManager.java
.. some other files ...
run2 contains:
find . -name "*.class" -type f -delete
javac -classpath .:server:server/lib/mysqlconn.jar server/Server.java
java -classpath .:server:server/lib/mysqlconn.jar server.Server
As you see, it runs Server. Go look there:
package server;
// imports
public class Server {
public static final int BUFFSIZE = 32;
public static void main (String[] args) throws IOException {
ServerConnectionManager server = new ServerConnectionManager(1234);
server.start();
server.acceptConnections();
server.shutdown();
}
}
Nothing weird in this class, right? Anyway, i think like that.
In this class, as we see, Server create instance of ServerConnectionManager
and call some functions.
Go look at acceptConnections:
public void acceptConnections() {
while(true) {
try {
Socket clientConnection = connection.accept();
ClientThread client = new ClientThread(clientConnection);
/*clients.add(client);
client.start();
System.out.println("[INF] Client connected");
System.out.println("[INF] Summary: " + clients.size() + " clients connected");*/
} catch (IOException e) {
System.out.println("[ERR] Accepting client connection failed");
}
}
}
I commented some lines. I really not need them now.
More about problem:
When i run run2 - server runs and works fine. netstat shows what server wait for connections.
But when i run client, and try connect to server, it shows to me next error:
Exception in thread "main" java.lang.NoClassDefFoundError: server/ClientThread
at server.ServerConnectionManager.acceptConnections(ServerConnectionManager.java:36)
at server.Server.main(Server.java:15)
Caused by: java.lang.ClassNotFoundException: server.ClientThread
at java.net.URLClassLoader$1.run(URLClassLoader.java:372)
at java.net.URLClassLoader$1.run(URLClassLoader.java:361)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:360)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
... 2 more
I can't understand, why i have this exception ?
Look at directories and files. ClientThread.java exists and placed into server directory and have server package. Compilation doesn't show any error.
What i doing wrong?
There is connection class for client
package client;
// imports
public class ClientConnectionManager {
public Socket connection;
public String host;
public Integer port;
public Boolean connected;
public ClientConnectionManager(String h, Integer p) {
host = h;
port = p;
}
public void connect() {
try {
connection = new Socket(host, port);
} catch (IOException e) {
System.out.println("[INF] Failed connect to server");
}
}
public void disconnect() {
try {
connection.close();
} catch (IOException e) {
System.out.println("[ERR] Connection closing failed");
}
}
}

package server;
// some imports just not removed yet
import java.io.IOException;
import java.net.*;
import java.lang.*;
import java.io.*;
import java.util.*;
import java.sql.*;
class ClientThread extends Thread {
public Socket clientSocket;
public OutputStream out;
public InputStream in;
public Tasks tasks;
public User user;
public ClientThread(Socket socket) {
clientSocket = socket;
try {
out = clientSocket.getOutputStream();
in = clientSocket.getInputStream();
} catch (IOException e) {
System.out.println("Cant initialize I/O in for client socket");
}
}
public void run() {
ServerDatabaseConnectionManager database = new ServerDatabaseConnectionManager();
database.connect();
tasks = new Tasks(database.connection);
user = new User(database.connection);
/** listen for requests from client*/
try {
out.write(new String("_nelo_").getBytes());
} catch (IOException e) {
System.out.println("Cant send auth cmd");
}
ServerInputHandler listen = new ServerInputHandler(this);
listen.start();
}
}
ClientThreadclass or other. Error in shell script :( When i removed next line, all works fine -find . -name "*.class" -type f -delete. Thankyou, your answers so userfull. Please, order your comments as anwer and i mark it as accepted