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=8080Run the jar
Run this command on the server. It starts the app from the jar file.
java -jar target/demo-0.0.1-SNAPSHOT.jarAsk the running app
This command asks the running app for /hello. The app answers with one line of text.
curl http://localhost:8080/helloExample
server.port=8080
java -jar target/demo-0.0.1-SNAPSHOT.jar
curl http://localhost:8080/helloKey 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?