Java Intro to Java Web Development with Spark Diving into Web Development Sending Responses

I am getting an error when I try to run this code, it says ERROR spark.Spark - ignite failed

When I try to run my code this is what I get this at the end

[Thread-1] ERROR spark.Spark - ignite failed Address already in use: bind
    at Method)
    at org.eclipse.jetty.server.AbstractNetworkConnector.doStart(
    at org.eclipse.jetty.server.ServerConnector.doStart(
    at org.eclipse.jetty.util.component.AbstractLifeCycle.start(
    at org.eclipse.jetty.server.Server.doStart(
    at org.eclipse.jetty.util.component.AbstractLifeCycle.start(
    at spark.embeddedserver.jetty.EmbeddedJettyServer.ignite(
    at spark.Service.lambda$init$2(

Process finished with exit code 100

Java Code:


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

import static spark.Spark.get;

public class Main {
    public static void main(String[] args){

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

index.hbs code:

<!doctype html>
<html lang="en">
    <meta charset="UTF-8">
    <meta name="viewport"
          content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Hello Students</title>
    <h1>Welcome Students!</h1>

Fahad Mutair I have updates the question with some code.

2 Answers

Luca Cunico
Luca Cunico
Pro Student 14,196 Points

Hello, The error you got is because you have another server running. Close all run tasks and try again.

You can see this by reading this line: Address already in use: bind
Naval Kulkarni
Naval Kulkarni
13,782 Points

Follow this stackoverflow thread and your problem will be solved. i was getting the same error. Some java.exe process wass listening on port 4567, once i ended it, the error was gone.

Here is the link: