Error: Could not find or load main class Main

前端 未结 3 1445
天命终不由人
天命终不由人 2020-12-12 02:01

I\'ve the java class:

package com.server.main;

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

public class Main {
    pu         


        
相关标签:
3条回答
  • 2020-12-12 02:23

    Look here: http://docs.oracle.com/javase/tutorial/getStarted/problems/index.html

    I find there answer to my problem with compile and run java application in terminal.

    0 讨论(0)
  • 2020-12-12 02:25

    You need to refer from one level above the package directory that you are using. So your package here is com.server.main which means your directory structure is:

    src/  
        com/  
            server/  
                main/  
                    Main.java  
                    Main.class  
    

    You don't necessarily need to be at src directory (that's the reason we use -cp or -classpath option) and give the following command

    Use:

    java -cp C:\Users\workspace\Tests\src com.server.main.Main
    
    0 讨论(0)
  • 2020-12-12 02:26

    Your Main is in a package, I believe you need

    java -cp C:\Users\workspace\Tests\src com.server.main.Main
    

    You might also move to the top folder of your project and use . like

    cd C:\Users\workspace\Tests\src
    java -cp . com.server.main.Main
    

    Finally, you could add that folder to your CLASSPATH like

    set CLASSPATH=C:\Users\workspace\Tests\src
    java com.server.main.Main
    
    0 讨论(0)
提交回复
热议问题