processbuilder给定程序错误“找不到同一包中类的符号”

8ulbf1ek  于 2021-07-03  发布在  Java
关注(0)|答案(0)|浏览(191)

我正在创建一个带有套接字的客户机-服务器应用程序,当服务器死机时,客户机需要重新启动服务器,以便它可以继续使用该应用程序,并且其他用户可以连接到它。我正在尝试使用processbuilder重新启动,这是我目前的代码:

public void restartServer() {
        String command[] = {"javac",SERVER_FILE_LOCATION};
        ProcessBuilder processBuilder = new ProcessBuilder(command);

        try {
            Process process = processBuilder.start();

            if( process.getErrorStream().read() != -1 ){
                print("Compilation Errors",process.getErrorStream());
            }
            if( process.exitValue() != 0 ) {
                process = new ProcessBuilder(
                        new String[]{
                                "java",
                                "-cp",
                                "D:\\CE303\\Lab4\\assignment\\src\\Server\\",
                                "ServerProgram"}).start();

                if (process.getErrorStream().read() != -1) {
                    System.out.println("Errors " + process.getErrorStream());
                }
            }
            else{
                System.out.println("Output " + process.getInputStream());
            }
        }
        catch (Exception e) {
            System.out.println(e.getMessage());
        }
    }

print函数是处理错误并打印它的函数。我得到一个错误:


*************Compilation Errors***********************

:\CE303\Lab4\assignment\src\Server\ServerProgram.java:11: error: cannot find symbol
    private static final Market market = new Market();
                         ^
  symbol:   class Market
  location: class ServerProgram
D:\CE303\Lab4\assignment\src\Server\ServerProgram.java:11: error: cannot find symbol
    private static final Market market = new Market();
                                             ^
  symbol:   class Market
  location: class ServerProgram
D:\CE303\Lab4\assignment\src\Server\ServerProgram.java:26: error: cannot find symbol
                new Thread(new Server.ClientHandler(socket, market)).start();
                                     ^
  symbol:   class ClientHandler
  location: package Server
3 errors

由于某些原因,服务器无法识别这些类,即使它们在同一个包中并且是公共的。我不知道该怎么办我不知道我是否需要添加一些东西到环境Map或其他任何东西。
编辑:我添加了我试图用processbuilder运行的类。如果我从intellij运行这个类,它运行得很好,但是如果我从processbuilder运行它,它会给出上面的错误。

package Server;

import java.io.IOException;
import java.net.ServerSocket;
import java.net.Socket;

public class ServerProgram
{
    private final static int port = 8888;

    private static final Market market = new Market();

    public static void main(String[] args)
    {

        RunServer();
    }

    private static void RunServer() {
        ServerSocket serverSocket = null;
        try {
            serverSocket = new ServerSocket(port);
            System.out.println("Waiting for incoming connections...");
            while (true) {
                Socket socket = serverSocket.accept();
                new Thread(new Server.ClientHandler(socket, market)).start();
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题