About the <scope>provided</scope> use of MAVEN dependencies

Source: Internet
Author: User

Today, when developing the Web, you need to use the SERVLET-API, and then add the dependencies in the Pom.xml

<Dependency>            <groupId>Javax.servlet</groupId>            <Artifactid>Servlet-api</Artifactid>            <version>3.0-alpha-1</version>        </Dependency>

When you start Tomcat via the plugin, an error is included:

 for a different type with the name "Javax/servlet/servletcontext" at    Java.lang.ClassLoader.defineClass1 ( Native Method) at    java.lang.ClassLoader.defineClass (classloader.java:    Java.security.SecureClassLoader.defineClass (Secureclassloader.java:142)    at Java.net.URLClassLoader.defineClass (URLClassLoader.java:449) at    java.net.urlclassloader.access$ (urlclassloader.java:71) at    java.net.urlclassloader$1.run (urlclassloader.java:361) At    java.net.urlclassloader$ 1.run (urlclassloader.java:355)

The reason for this is that there are also servlet-api packages in Tomcat, so that there is a conflict

Workaround: Add <scope>provided</scope>, because provided indicates that the package is only used when compiling and testing, so when Tomcat is started, it does not conflict, and the complete dependency is as follows:

<Dependency>            <groupId>Javax.servlet</groupId>            <Artifactid>Servlet-api</Artifactid>            <version>3.0-alpha-1</version>            <Scope>Provided</Scope>        </Dependency>

About <scope>provided</scope> use in Maven dependencies

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.