线程"main"中的异常java.net.BindException:地址已在使用中 [英] Exception in thread "main" java.net.BindException: Address already in use

查看:721
本文介绍了线程"main"中的异常java.net.BindException:地址已在使用中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试在Linux服务器上安装Java HTTP API.我尝试从命令提示符执行以下命令以运行服务:

I try to install a java HTTP API on my linux server. I try to execute this command from command pompt to run the service:

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) 在sun.nio.ch.ServerSocketChannelImpl.bind(ServerSocketChannelImpl.java:223) 在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)

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:

Here is 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-和语言检测API服务器

怎么了?我该如何解决?

What is wrong? How can I fix it?

推荐答案

正在发生的情况是,如果更改端口号,则8080端口上已经在运行某些东西,那么问题就应该消除了.

What looks like is happening is that something is already running on port 8080 if you change the port number your problem should go away.

这篇关于线程"main"中的异常java.net.BindException:地址已在使用中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆