Card 03/ 06

ExampleDifficulty: Intermediate1 min

A Server, Packaged Inside Your Own Jar

Running the jar this application builds into starts it listening on a real port — no separate Tomcat installation, no server to configure outside the application itself.

java
var context = SpringApplication.run(EmbeddedServerDemo.class, args);
var webContext = (WebServerApplicationContext) context;
int port = webContext.getWebServer().getPort();
System.out.println("Listening on port " + port + ", no server installed separately.");
text
Listening on port 8080, no server installed separately.
run in a container — the whole server lives inside the jar

The older shape — a WAR file, deployed into a Tomcat or another server that already exists on the target machine — still works, and some organisations still deploy that way. What changed is that it's no longer the default or the easy path: java -jar is enough, because the server is a dependency like any other, not infrastructure you provision separately.