gpt4 book ai didi

java - 线程 "main"java.net.BindException : Address already in use 中的异常

转载 作者:塔克拉玛干 更新时间:2023-11-03 00:11:53 24 4
gpt4 key购买 nike

我尝试在我的 Linux 服务器上安装一个 Java HTTP API。我尝试从命令提示符执行此命令以运行该服务:

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

然后我有这个错误:

Exception in thread "main" java.net.BindException: Address already in use at sun.nio.ch.Net.bind0(Native Method) at sun.nio.ch.Net.bind(Net.java:463) at 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) at sun.net.httpserver.ServerImpl.(ServerImpl.java:100) at sun.net.httpserver.HttpServerImpl.(HttpServerImpl.java:50) at sun.net.httpserver.DefaultHttpServerProvider.createHttpServer(DefaultHttpServerProvider.java:35) at com.sun.net.httpserver.HttpServer.create(HttpServer.java:129) at 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

怎么了?我该如何解决?

最佳答案

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

关于java - 线程 "main"java.net.BindException : Address already in use 中的异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35711964/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com