|
| 1 | +--- |
| 2 | +title: Solutions for Maven Tomcat Plugin Issues |
| 3 | +lang: en |
| 4 | +layout: post |
| 5 | +audio: false |
| 6 | +translated: false |
| 7 | +generated: true |
| 8 | +image: false |
| 9 | +--- |
| 10 | + |
| 11 | +You got the key clue right in your own log: |
| 12 | + |
| 13 | +> `[INFO] Skipping non-war project` |
| 14 | +
|
| 15 | +Nothing started because the **tomcat7-maven-plugin only runs webapps packaged as a WAR** with the classic `src/main/webapp` layout. Your project is almost certainly packaged as a JAR right now, so the plugin just exits after the build. |
| 16 | + |
| 17 | +There’s a second gotcha: you’re running **Tomcat 11** (Jakarta `jakarta.*` APIs), but your dependencies are **Spring 5.2.x** (uses `javax.*`). That mismatch means even if Tomcat started, a plain deploy to Tomcat 11 would fail without a migration. Use Tomcat 9 (javax) for Spring 5, or upgrade the app to Spring 6/Jakarta for Tomcat 10/11. |
| 18 | + |
| 19 | +Here are clean paths you can choose—pick one and it’ll work: |
| 20 | + |
| 21 | +### Path 1 — Keep Spring 5, run locally with Jetty plugin (fastest) |
| 22 | + |
| 23 | +No WAR needed; good for hacking. |
| 24 | + |
| 25 | +1. Add plugin: |
| 26 | + |
| 27 | + ```xml |
| 28 | + <plugin> |
| 29 | + <groupId>org.eclipse.jetty</groupId> |
| 30 | + <artifactId>jetty-maven-plugin</artifactId> |
| 31 | + <version>9.4.54.v20240208</version> |
| 32 | + </plugin> |
| 33 | + ``` |
| 34 | +2. Run: |
| 35 | + |
| 36 | + ```bash |
| 37 | + mvn jetty:run -Djetty.port=8080 |
| 38 | + ``` |
| 39 | + |
| 40 | +This uses `javax.*`, matching Spring 5. |
| 41 | + |
| 42 | +### Path 2 — Keep Spring 5, build a WAR, and use the Tomcat7 plugin |
| 43 | + |
| 44 | +1. In `pom.xml` set WAR packaging: |
| 45 | + |
| 46 | + ```xml |
| 47 | + <packaging>war</packaging> |
| 48 | + ``` |
| 49 | +2. Ensure webapp layout exists: |
| 50 | + |
| 51 | + ``` |
| 52 | + src/main/webapp/ |
| 53 | + src/main/webapp/WEB-INF/web.xml # optional if you have a Servlet 3 initializer |
| 54 | + ``` |
| 55 | +3. (Optional) Add plugin config: |
| 56 | + |
| 57 | + ```xml |
| 58 | + <plugin> |
| 59 | + <groupId>org.apache.tomcat.maven</groupId> |
| 60 | + <artifactId>tomcat7-maven-plugin</artifactId> |
| 61 | + <version>2.2</version> |
| 62 | + <configuration> |
| 63 | + <path>/</path> |
| 64 | + <port>8080</port> |
| 65 | + </configuration> |
| 66 | + </plugin> |
| 67 | + ``` |
| 68 | +4. Run: |
| 69 | + |
| 70 | + ```bash |
| 71 | + mvn tomcat7:run # for exploded webapp |
| 72 | + # or |
| 73 | + mvn package && mvn tomcat7:run-war |
| 74 | + ``` |
| 75 | + |
| 76 | +### Path 3 — Keep Spring 5, deploy to a standalone Tomcat 9 |
| 77 | + |
| 78 | +This matches `javax.*` without changing code. |
| 79 | + |
| 80 | +```bash |
| 81 | +brew install tomcat@9 |
| 82 | +/opt/homebrew/opt/tomcat@9/bin/catalina start |
| 83 | +``` |
| 84 | + |
| 85 | +Build and drop your WAR into `.../tomcat@9/libexec/webapps/`. |
| 86 | + |
| 87 | +### Path 4 — Upgrade the app to Spring 6/Jakarta, stick with Tomcat 11 |
| 88 | + |
| 89 | +If you want modern Tomcat: |
| 90 | + |
| 91 | +* Upgrade to Spring Framework 6.x / Spring Boot 3.x. |
| 92 | +* Change imports from `javax.*` to `jakarta.*`. |
| 93 | +* Then Tomcat 10/11 is fine. |
| 94 | + |
| 95 | +--- |
| 96 | + |
| 97 | +#### Why `mvn tomcat7:run` printed success but “nothing happened” |
| 98 | + |
| 99 | +* Maven phases completed successfully, but the plugin saw **non-WAR packaging**, so it **didn’t start** an embedded Tomcat. That’s exactly what “Skipping non-war project” means. |
| 100 | + |
| 101 | +--- |
| 102 | + |
| 103 | +If you tell me which path you prefer, I’ll give you the exact `pom.xml` and minimal files for that setup (including a tiny controller and how to hit it at `http://localhost:8080/hello`). |
0 commit comments