线程“main”中的异常java.net.BindException:地址已在使用中

时间:2016-02-29 23:39:06

标签: java linux server command port

我尝试在我的linux服务器上安装java HTTP API。我尝试从命令pompt执行此命令来运行服务:

java -Dfile.encoding=UTF8 -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

然后我有这个错误:

  

线程“main”中的异常java.net.BindException:地址已在使用中           在sun.nio.ch.Net.bind0(原生方法)           在sun.nio.ch.Net.bind(Net.java:463)           在sun.nio.ch.Net.bind(Net.java:455)           at sun.nio.ch.ServerSocketChannelImpl.bind(ServerSocketChannelImpl.java:223)           at sun.nio.ch.ServerSocketAdaptor.bind(ServerSocketAdaptor.java:74)           在sun.net.httpserver.ServerImpl。(ServerImpl.java:100)           在sun.net.httpserver.HttpServerImpl。(HttpServerImpl.java:50)           在sun.net.httpserver.DefaultHttpServerProvider.createHttpServer(DefaultHttpServerProvider.java:35)           在com.sun.net.httpserver.HttpServer.create(HttpServer.java:129)           在ExampleProgram.main(ExampleProgram.java:37)

这是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("localhost",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

有什么问题?我该如何解决?

1 个答案:

答案 0 :(得分:2)

如果您更改了问题应该消失的端口号,那么正在发生的事情是,端口8080上已经运行了某些东西。