The Java compiler uses maven to create a war package. How can this problem be solved?

Source: Internet
Author: User

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 ).

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.