|
| 1 | +--- |
| 2 | +title: Web Application Deployment Options Explained |
| 3 | +lang: en |
| 4 | +layout: post |
| 5 | +audio: false |
| 6 | +translated: false |
| 7 | +generated: true |
| 8 | +image: false |
| 9 | +--- |
| 10 | + |
| 11 | +Got it — let me explain those options clearly for you. |
| 12 | + |
| 13 | +### Option 1: Quick Development Setup (Recommended) |
| 14 | + |
| 15 | +This is the easiest way to start the project during development. |
| 16 | +If your `pom.xml` includes a Tomcat or Jetty plugin, you can run the app directly with: |
| 17 | + |
| 18 | +```bash |
| 19 | +mvn tomcat7:run |
| 20 | +``` |
| 21 | + |
| 22 | +or |
| 23 | + |
| 24 | +```bash |
| 25 | +mvn jetty:run |
| 26 | +``` |
| 27 | + |
| 28 | +This launches the web app in an embedded Tomcat/Jetty without building a WAR or deploying manually. If you don’t already have the plugin, you’d need to add it to `pom.xml` first. |
| 29 | + |
| 30 | +--- |
| 31 | + |
| 32 | +### Option 2: Build and Deploy WAR |
| 33 | + |
| 34 | +This is the more “traditional” approach. You package the application into a WAR file: |
| 35 | + |
| 36 | +```bash |
| 37 | +mvn clean package |
| 38 | +``` |
| 39 | + |
| 40 | +This produces something like `target/playground-server-1.0.war`. |
| 41 | +You then copy that WAR into a standalone Tomcat/Jetty server’s `webapps/` folder, restart the server, and access the deployed app in the browser. |
| 42 | + |
| 43 | +--- |
| 44 | + |
| 45 | +### Option 3: Use Embedded Server (Manual Setup) |
| 46 | + |
| 47 | +Currently your `Application.main()` just starts the Spring context — it doesn’t actually start a web server. |
| 48 | +If you want the app itself to launch Tomcat (without relying on an external one), you’d need to modify your main class to set up and start an embedded Tomcat instance programmatically. |
| 49 | + |
| 50 | +This gives you a self-contained runnable JAR, but it requires extra setup code. |
| 51 | + |
| 52 | +--- |
| 53 | + |
| 54 | +### Option 4: Spring Boot Migration |
| 55 | + |
| 56 | +This project has **some Spring Boot test setup**, but isn’t a real Spring Boot app yet. That’s why running: |
| 57 | + |
| 58 | +```bash |
| 59 | +mvn spring-boot:run |
| 60 | +``` |
| 61 | + |
| 62 | +doesn’t work. |
| 63 | + |
| 64 | +If you want, you can migrate: |
| 65 | + |
| 66 | +* Add the proper Spring Boot starter dependencies. |
| 67 | +* Change your main class to `@SpringBootApplication`. |
| 68 | +* Then you’d be able to just run with `mvn spring-boot:run` or even `java -jar target/app.jar`. |
| 69 | + |
| 70 | +This is the most modern approach, but requires some changes to your code and `pom.xml`. |
| 71 | + |
| 72 | +--- |
| 73 | + |
| 74 | +✅ **In short**: |
| 75 | + |
| 76 | +* If you just want to test quickly → use **Option 1**. |
| 77 | +* If you’re deploying to an existing server → use **Option 2**. |
| 78 | +* If you want a self-contained app without external Tomcat → use **Option 3**. |
| 79 | +* If you want to modernize and simplify long-term → use **Option 4**. |
| 80 | + |
| 81 | +--- |
| 82 | + |
| 83 | +Do you want me to show you the **exact `pom.xml` snippet** for Option 1 (Tomcat/Jetty plugin) so you can just run `mvn tomcat7:run` right away? |
0 commit comments