错误:找不到或加载主类

时间:2016-02-29 17:59:02

标签: java linux class command-line command

首先感谢您的帮助。我查看并尝试过像我这样的所有游戏,但没有一个能帮我解决问题。我尝试了这个命令,以便在包含ExampleProgram.java的当前文件夹中进行编译:

java -Xms16m -Xmx64m -cp ".:boilerpipe-1.2.0.jar:lib/nekohtml-1.9.13.jar:lib/xerces-2.9.1.jar:lib/langdetect.jar:lib/jsonic-1.2.8.jar" ExampleProgram.java

然后它给出了这个错误:

  

错误:无法找到或加载主类ExampleProgram.java

这是ExampleProgram.java:

import java.io.InputStream;
import java.io.FileReader;
import java.io.FileInputStream;
import java.io.InputStreamReader;
import java.io.IOException;

import org.xml.sax.InputSource;

import de.l3s.boilerpipe.document.TextDocument;
import de.l3s.boilerpipe.extractors.ArticleExtractor;
import de.l3s.boilerpipe.sax.BoilerpipeSAXInput;


// Language detect librarys
import com.cybozu.labs.langdetect.*;

import net.arnx.jsonic.JSON;
import net.arnx.jsonic.JSONException;


import java.io.*;
import java.net.*;


import java.util.concurrent.Executors;
import com.sun.net.httpserver.Headers;
import com.sun.net.httpserver.HttpExchange;
import com.sun.net.httpserver.HttpHandler;
import com.sun.net.httpserver.HttpServer;

class ExampleProgram {

  public static void main(String[] args) throws Exception {

EveryDetector evr = new EveryDetector();
InetSocketAddress addr = new InetSocketAddress("127.0.0.1",8080);
HttpServer server = HttpServer.create(addr, 0);

MyHandler hndl = new MyHandler();
hndl.setDetector(evr);

MyHandlerExtractContent hnd2 = new MyHandlerExtractContent();
hnd2.setDetector(evr);

MyHandlerDetectLanguage hnd3 = new MyHandlerDetectLanguage();
hnd3.setDetector(evr);

server.createContext("/",hndl);
server.createContext("/extractcontent",hnd2);
server.createContext("/detectlanguage",hnd3);
server.setExecutor(Executors.newCachedThreadPool());
server.start();
System.out.println("Server is listening on port 8080" );


 }
}

来源:https://github.com/remdex/boilerpipe-and-language-detect-api-server

如何解决我的问题?

2 个答案:

答案 0 :(得分:1)

在此public之前添加class ExampleProgram字词:

public class ExampleProgram {
   public static void main(String[] args) throws Exception {

请记住,主要课程必须始终为public

答案 1 :(得分:1)

class ExampleProgram更改为public class ExampleProgram,因为编译器无法使用main方法定位类。

请注意,您只能拥有一个' public' class,否则会混淆编译器。