When packaging with maven, two errors occurred:
Error 1: Package javax.servlet does not exist, package javax.servlet.http does not exist
Error 2: No compiler is provided in this environment. Perhaps you are running on a JRE rather than a JDK? Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.1:compile (default-compile). . .
1. Error 1 Cause: The java compiler did not find the package javax.servlet.
Workaround: Add the following dependency package in pom.xml
<dependency> <groupId>javax.servlet</groupId> <artifactId>servlet-api</artifactId> <version>2.5</version> <scope>provided</scope></dependency><dependency> <groupId>javax.servlet</groupId> <artifactId>javax.servlet-api</artifactId> <version>3.0.1</version> <scope>provided</scope></dependency>
After the dependency download is completed, right-click ->maven ->Update Projects...
Sometimes the jsp page will also report an error, and it is also related to javax.servlet.http.http cannot be found. One method is to use the above method to add dependencies in the pom;
The second method is as follows:
Right-click on the project ->Build Path ->Configure Build Path, and then as shown in the figure:
Just Next in turn.
2. Error 2
[ERROR] COMPILATION ERROR:
[INFO] ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
[INFO] ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
[INFO] ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
[ERROR] No compiler is provided in this environment. Perhaps you are running on a JRE rather than a JDK?
1. Cause of error: eclipse selects jre to run the program by default, while maven's install requires jdk to be used, so an error that cannot be found in the compilation environment is reported.
2. Solution: Change jre to jdk
3. Detailed steps: Right-click the project ->Build Path ->Configure Build Path..., after opening the window, follow the steps below to select. This step is to change jre to jdk and jre to jdk
After the steps are completed, update the maven project (right-click ->maven ->Update Projects...), and then clean the following projects (right-click ->Run As...
―>Maven Clean), and finally pack (right-click―>Run As…―>Maven install).