私は、非常にシンプルなクライアント/サーバーを実行し、コマンドラインから実行しようとしています。それはEclipseからうまく動作しますが、cmdでは実行されません。ここでは、クライアントの:NoClassDefFoundからcmdを実行していてEclipseでは実行していない場合
package com.mycompany.pdr.client;
import java.io.BufferedOutputStream;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.net.Socket;
import java.net.UnknownHostException;
public class SimpleClientSend {
public static void main(String[] args) {
String host = "127.0.0.1";
int port = 11048;
String dataToSend = "HELLO SERVER";
System.out.println("> Trying to connect...");
System.out.println("> Opening connection to server [" + host + ":"
+ port + "]...");
Socket socket1Connection;
try {
socket1Connection = new Socket(host, port);
System.out.println("> Connected...");
System.out.println("> Trying to write data... [ " + dataToSend + " ]");
BufferedOutputStream bos = new BufferedOutputStream(
socket1Connection.getOutputStream());
/*
* Instantiate an OutputStreamWriter object with the optional
* character encoding. e.g. UTF-8
*/
OutputStreamWriter osw = new OutputStreamWriter(bos, "US-ASCII");
// Writing to server
osw.write(dataToSend);
osw.flush();
System.out.println("> Writing to server done...");
socket1Connection.close();
} catch (UnknownHostException e) {
System.out.println(e.getLocalizedMessage());
System.out.println("Unknown Host. Please check if the server is running at the IP & port");
//e.printStackTrace();
} catch (IOException e) {
System.out.println(e.getLocalizedMessage());
System.out.println("Could not send data. Giving up.");
//e.printStackTrace();
}
System.out.println("> End of connection...");
}
}
私のディレクトリ構造は次のとおりです。(MyWorkspace)/myProject/com/mycompany/pdr/client
エラー、私はクライアントのフォルダ内からjavac SimpleClientSend.java
を実行していない、と私はクラスファイルを取得します。私はjava SimpleClientSend
を実行し、私はがNoClassDefFoundメッセージが表示されます。
Exception in thread "main" java.lang.NoClassDefFoundError: SimpleClientSend (wrong name: com/iai/pdr/client/SimpleClientSend)
私はそこに他のすべての記事の提案(しかし、どのような点があればだが従うためにJavaを実行したときに、私は-cp .
を使用して試してみた私のクラスパスに既にありますか。? )、私はクライアントのフォルダの外からそれを実行しようとしたが、すべて私は同じエラーを与える。 Eclipseで、私がしなければならなかったのは、Javaファイルを空のプロジェクトに貼り付けることだけでした。私はここで間違って何をしていますか?
(MyWorkspace)/ myProject – vickirk
herp derp meから実行してみてください。うん答えを書くと私はそれを受け入れる – Indigenuity