简体   繁体   中英

Exception in thread “main” java.net.BindException: Address already in use

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

Then I have this error:

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)

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" );


 }
}

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

What is wrong? How can I fix it?

看起来正在发生的事情是,如果更改端口号,则端口8080上已经在运行某些设备,那么问题就应该消除了。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM