ここで深刻な問題が発生しました。どうすればよいかわかりません。この時間にいました。このエラーの取得:
java.lang.ClassNotFoundException: User
これが私のコードです:
public class BookingServerPublisher{
public static void main(String[] args){
System.out.println("Starting web Service,Press Ctrl + C to stop\n");
// 1st argument is the publication URL
// 2nd argument is an SIB instance
Endpoint.publish("http://127.0.0.1:9876/bs", new BookingServerImpl());
}
}
@WebService(endpointInterface = "bs.BookingServer")
public class BookingServerImpl implements BookingServer{
User users = new User();
public void initData(){
users.loadUsers();
}
}
@WebService
@SOAPBinding(style = Style.RPC)
public interface BookingServer{
@WebMethod void initData();
}
class BookingClient{
public static void main(String args[]) throws Exception{
URL url = new URL("http://localhost:9876/bs?wsdl");
// Qualified name of the service:
// 1st arg is the service URI
// 2nd is the service name published in the WSDL
QName qname = new QName("http://bs/", "BookingServerImplService");
// Create, in effect, a factory for the service.
Service service = Service.create(url, qname);
// Extract the endpoint interface, the service "port".
BookingServer eif = service.getPort(BookingServer.class);
eif.initData();
}
}
package bs;
import java.io.*;
import java.util.*;
public class User{
private static final long serialVersionUID = 1;
static ArrayList<User> userList = new ArrayList<User>(); //Dynamic List of all the User objects
String name;
String password;
String level;
boolean isAdmin = false;
User(){
super();
}
//Method for loading User objects from data file
static void loadUsers(){
try {
FileInputStream stream = new FileInputStream("UsersData");
ObjectInputStream read = new ObjectInputStream(stream);
while(stream.available() != 0){
Object obj = read.readObject();
if(obj instanceof User){
User users = (User) obj;
userList.add(users);
}
}
stream.close();
read.close();
}
catch (Exception e) {
e.printStackTrace();
}
}
//Method for saving User objects to data file
static void saveUsers(){
try {
FileOutputStream stream = new FileOutputStream("UsersData");
ObjectOutputStream write = new ObjectOutputStream(stream);
for(int i = 0; i < userList.size();i++){
if(userList.get(i) instanceof User){
write.writeObject(userList.get(i));
}
}
stream.close();
write.close();
}
catch (Exception e) {
e.printStackTrace();
}
}
}
すべてのファイルのパッケージは、次のbs
ように実行していますjava bs.BookingServerPublisher
。
java bs.BookingClient
'フォルダを含むbs
フォルダ、つまりbs
親ディレクトリから、BookingServerPublisher
コンソールはエラーをスローします。
誰でもこれで私を助けることができます。本当に感謝しています。