Java Intro to Java Web Development with Spark Diving into Web Development Accepting Requests

Ivailo Hristov
Ivailo Hristov
6,297 Points

Process finished with exit code 100

[Thread-1] INFO org.eclipse.jetty.util.log - Logging initialized @838ms [Thread-1] INFO spark.embeddedserver.jetty.EmbeddedJettyServer - == Spark has ignited ... [Thread-1] INFO spark.embeddedserver.jetty.EmbeddedJettyServer - >> Listening on 0.0.0.0:4567 [Thread-1] INFO org.eclipse.jetty.server.Server - jetty-9.3.6.v20151106 [Thread-1] ERROR spark.embeddedserver.jetty.EmbeddedJettyServer - ignite failed java.net.BindException: Address already in use: bind at sun.nio.ch.Net.bind0(Native Method) at sun.nio.ch.Net.bind(Net.java:433) at sun.nio.ch.Net.bind(Net.java:425) at sun.nio.ch.ServerSocketChannelImpl.bind(ServerSocketChannelImpl.java:223) at sun.nio.ch.ServerSocketAdaptor.bind(ServerSocketAdaptor.java:74) at org.eclipse.jetty.server.ServerConnector.open(ServerConnector.java:326) at org.eclipse.jetty.server.AbstractNetworkConnector.doStart(AbstractNetworkConnector.java:80) at org.eclipse.jetty.server.ServerConnector.doStart(ServerConnector.java:244) at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:68) at org.eclipse.jetty.server.Server.doStart(Server.java:384) at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:68) at spark.embeddedserver.jetty.EmbeddedJettyServer.ignite(EmbeddedJettyServer.java:129) at spark.Service.lambda$init$1(Service.java:452) at java.lang.Thread.run(Thread.java:745)

Process finished with exit code 100

again and again, i already disconnecd two Main runners, refresh gradle project...

2 Answers

Alexander Nikiforov
Alexander Nikiforov
Java Web Development Techdegree Graduate 22,138 Points

Looks like you have to change port number.

ignite failed java.net.BindException: Address already in use: bind at sun.nio.ch.Net.bind0(Native Method) at 

That is the error message : "Address is already in use".

Try writing

public static void main(String[] args) {
  // code
  port(9000);
  // code
}

See docs here

The other option would be to find out which application is using port 4567 and try to kill it.

Will take more time and googling, but it is good to do it once for experience.

Ivailo Hristov
Ivailo Hristov
6,297 Points

i put port code here

package com.teamtreehouse.courses;

import spark.ModelAndView; import spark.template.handlebars.HandlebarsTemplateEngine;

import java.util.HashMap; import java.util.Map;

import static spark.Spark.get; import static spark.Spark.port; import static spark.Spark.post;

public class Main {

public static void main(String[] args) {
    port(9000);

    get("/", (req, res) ->{
        return new ModelAndView(null, "index.hbs");

    }, new HandlebarsTemplateEngine());


    post("/sign-in", (req, res) -> {
        Map<String, String> model = new HashMap<>();
        model.put("username", req.queryParams("username"));
        return new ModelAndView(model, "sign-in.hbs");
    }, new HandlebarsTemplateEngine());

}

}

but when i type my name and click Sign in - 404 not found and this message pop

[qtp1032579415-20] INFO spark.http.matching.MatcherFilter - The requested route [/sign%20in] has not been mapped in Spark for Accept: [text/html,application/xhtml+xml,application/xml;q=0.9,/;q=0.8]

Alexander Nikiforov
Alexander Nikiforov
Java Web Development Techdegree Graduate 22,138 Points

The message that you see:

[qtp1032579415-20] INFO spark.http.matching.MatcherFilter - The requested route [/sign%20in] has not been mapped in Spark for Accept: [text/html,application/xhtml+xml,application/xml;q=0.9,/;q=0.8]

Indicates that you make a request to /sign in ,i.e. sign, space, in, which is converted to %20.

So HTTP converts /sign in to /sign%20in.

I think there is a problem in your template file in index.hbs the button Sign in can be attached to a sign in instead of sign-in.

Please post index.hbs file

Ivailo Hristov
Ivailo Hristov
6,297 Points

The problem is that I have written sign in instead sign-in... newbie job. Thank you very much for your answer