Skip to content

Instantly share code, notes, and snippets.

@ericdahl
Last active August 29, 2015 14:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ericdahl/0dc63c44cd05a6f5bd9a to your computer and use it in GitHub Desktop.
Save ericdahl/0dc63c44cd05a6f5bd9a to your computer and use it in GitHub Desktop.
BindException: Address already in use with jetty
build/
.gradle/
import org.eclipse.jetty.server.Connector;
import org.eclipse.jetty.server.Server;
public static void main(String[] args) throws Exception {
def server = new Server(new InetSocketAddress(InetAddress.getLocalHost(), 9999))
server.start()
server.connectors.each { it.stop() }
server.stop()
server.start()
}
apply plugin: 'groovy'
apply plugin: 'application'
mainClassName = 'app'
sourceSets {
main {
groovy {
srcDirs = ['.']
}
}
}
repositories {
mavenCentral()
}
dependencies {
compile 'org.eclipse.jetty.aggregate:jetty-webapp:8.1.14.v20131031'
compile 'org.codehaus.groovy:groovy-all:2.2.0'
}
@ericdahl
Copy link
Author

[ecd@qk ~/repos/misc/gist-bindexception]$ uname -a
FreeBSD qk.local 10.0-STABLE FreeBSD 10.0-STABLE #0: Sun Mar 30 09:02:29 CDT 2014     root@qk.local:/usr/obj/usr/src/sys/GENERIC  amd64
[ecd@qk ~/repos/misc/gist-bindexception]$ gradle run
...
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:444)
     at sun.nio.ch.Net.bind(Net.java:436)
     at sun.nio.ch.ServerSocketChannelImpl.bind(ServerSocketChannelImpl.java:214)
     at sun.nio.ch.ServerSocketAdaptor.bind(ServerSocketAdaptor.java:74)
     at org.eclipse.jetty.server.nio.SelectChannelConnector.open(SelectChannelConnector.java:187)
     at org.eclipse.jetty.server.AbstractConnector.doStart(AbstractConnector.java:316)
     at org.eclipse.jetty.server.nio.SelectChannelConnector.doStart(SelectChannelConnector.java:265)
     at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:64)
     at org.eclipse.jetty.server.Server.doStart(Server.java:293)
     at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:64)
     at org.eclipse.jetty.util.component.LifeCycle$start.call(Unknown Source)
     at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:45)
     at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.:108)
     at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:112)
     at app.run(app.groovy:9)
...

and in contrast:

ecd@ubuntudev:~/repos/misc/gist-bindexception$ uname -a
Linux ubuntudev 3.2.0-23-generic-pae #36-Ubuntu SMP Tue Apr 10 22:19:09 UTC 2012 i686 i686 i386 GNU/Linux
ecd@ubuntudev:~/repos/misc/gist-bindexception$ gradle run
:compileJava UP-TO-DATE
:compileGroovy
:processResources UP-TO-DATE
:classes
:run
2014-05-28 21:00:31.044:INFO:oejs.Server:jetty-8.1.14.v20131031
2014-05-28 21:00:31.077:INFO:oejs.AbstractConnector:Started SelectChannelConnector@ubuntudev:9999
2014-05-28 21:00:31.176:INFO:oejs.Server:jetty-8.1.14.v20131031
2014-05-28 21:00:31.178:INFO:oejs.AbstractConnector:Started SelectChannelConnector@ubuntudev:9999

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment