🎓 A1Learner
🔍
0 of 50 lessons completed

Deploying the App

Deploying means running the jar on a server so anyone can reach the app. The java -jar command starts the app from the jar file.

Pick the port

This line sets the port in application.properties. The app listens on port 8080.

server.port=8080

Run the jar

Run this command on the server. It starts the app from the jar file.

java -jar target/demo-0.0.1-SNAPSHOT.jar

Ask the running app

This command asks the running app for /hello. The app answers with one line of text.

curl http://localhost:8080/hello

Example

server.port=8080

java -jar target/demo-0.0.1-SNAPSHOT.jar

curl http://localhost:8080/hello

Key points

  • A server is a computer that stays on and answers requests.
  • Copy the jar file to the server.
  • The java -jar command runs the app from the jar.
  • The server.port setting picks the port the app listens on.
  • Application.properties holds settings like the port.

In this example, the setting server.port=8080 picks the port for the app. The java -jar command starts the app from the jar file. The app listens on port 8080. The curl command asks the running app for /hello. The app answers Hello, Spring Boot!

Note

The app listens on port 8080 unless the setting changes it.

Try it Yourself

Edit the code, then press Run.

Running is simulated

Exercise

Which command runs the packaged app?