The Java compiler uses maven to create a war package. How can this problem be solved?
When packaging with maven, the following two errors occur:
Error 1: the package javax. servlet does not exist. The 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 )...
I. Error 1 cause: the java compiler does not find the software package javax. servlet.
Solution: add the following dependency packages to 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 is downloaded, right-click --> maven --> Update Projects...
Sometimes an error is reported on the jsp page, and the related javax. servlet. http cannot be found. One way is to add the dependency in pom using the above method;
The second method is as follows:
Right-click the project --> Build Path --> Configure Build Path, and then
Click Next.
Ii. Error 2
[ERROR] compilation error:
[INFO] ----------------------------------------------------------- [ERROR] No compiler is provided in this environment. Perhaps you are running on a JRE rather than JDK? [INFO] 1 error [INFO] ------------------------------------------------------------- [INFO] fail [INFO] BUILD FAILURE
[INFO] Explain [INFO] Total time: 3.764 s [INFO] Finished at: 2018-03-19T15: 14: 00 + 08: 00 [INFO] Final Memory: 11 M/110 M
[INFO] ------------------------------------------------------------------------ [ERROR] Failed to execute goal org. apache. maven. plugins: maven-compiler-plugin: 3.1: compile (default-compile) on project book-donation: Compilation failure
[ERROR] No compiler is provided in this environment. Perhaps you are running on a JRE rather than a JDK?
1. Error cause: by default, eclipse selects jre to run the program, while maven install requires jdk. Therefore, an error cannot be found in the compiling environment.
2. Solution: Change jre to jdk.
3. Detailed steps: Right-click the project --> Build Path --> Configure Build Path ..., After the window is opened, select as shown in the following steps. In this step, change the jre to jdk and the jre to jdk.
After the steps are completed, Update the maven Project (right-click --> maven --> Update Projects ...), Then clean the following items (right-click --> Run...
--> Maven Clean), and then package (right-click --> Run... --> Maven install ).