`

maven scope的作用

阅读更多
建立的一个用maven管控的web工程,发现jstl-1.2.jar不会部署到lib下。很是奇怪。但tomcat 7.0里自带的库里又不包括。导致页面一声明jstl标签就报错。
后来才知道是pom里指定的scope。代码如下:
<dependency>
	<groupId>javax.servlet</groupId>
	<artifactId>jstl</artifactId>
	<version>1.2</version>
	<scope>provided</scope>
</dependency>


去掉<scope>provided</scope>就OK了。

查询maven的文档,了解到:
  • compile
  • This is the default scope, used if none is specified. Compile dependencies are available in all classpaths of a project. Furthermore, those dependencies are propagated to dependent projects.
  • provided
  • This is much like compile, but indicates you expect the JDK or a container to provide the dependency at runtime. For example, when building a web application for the Java Enterprise Edition, you would set the dependency on the Servlet API and related Java EE APIs to scope provided because the web container provides those classes. This scope is only available on the compilation and test classpath, and is not transitive.
  • runtime
  • This scope indicates that the dependency is not required for compilation, but is for execution. It is in the runtime and test classpaths, but not the compile classpath.
  • test
  • This scope indicates that the dependency is not required for normal use of the application, and is only available for the test compilation and execution phases.
  • system
  • This scope is similar to provided except that you have to provide the JAR which contains it explicitly. The artifact is always available and is not looked up in a repository.
  • import (only available in Maven 2.0.9 or later)
  • This scope is only used on a dependency of type pom in the <dependencyManagement> section. It indicates that the specified POM should be replaced with the dependencies in that POM's <dependencyManagement> section. Since they are replaced, dependencies with a scope of import do not actually participate in limiting the transitivity of a dependency.
分享到:
评论

相关推荐

    Maven中scope详细说明

    Maven 中的 Scope 详细说明 Maven 中的 Scope 是一种依赖范围控制机制,用于控制哪些依赖在哪些 classpath 中可用,哪些依赖包含在一个应用中。在 Maven 中,Scope 主要分为五种:compile、provided、runtime、test...

    maven 关于 scope test 和 继承传递的问题

    本文将深入探讨"Maven中scope test的使用以及依赖继承传递"这一主题,帮助开发者更好地理解和应用Maven的核心特性。 首先,`scope test`是Maven依赖管理中的一个关键概念。当我们在`pom.xml`文件中为某个依赖设置`...

    maven依赖关系中的&lt;scope&gt;provided&lt;/scope&gt;使用详解

    `&lt;scope&gt;`标签在Maven的依赖管理中扮演着决定依赖范围的角色,它定义了特定的依赖在项目的哪些阶段可用,并决定了依赖是否会被包含在最终的部署包中。本文将详细解析`&lt;scope&gt;provided&lt;/scope&gt;`的使用和意义。 `...

    Maven之scope依赖范围.docx

    在Maven项目管理中,`scope`依赖范围是至关重要的概念,它决定了一个依赖在项目的不同阶段如何被引入和使用。Maven有多种scope类型,每个类型都有特定的适用场景和目的,帮助开发者精确控制项目的依赖关系。 1. **...

    maven3.0 maven3.0

    &lt;scope&gt;test&lt;/scope&gt; ``` 通过以上介绍,我们可以看到Maven 3.0在项目管理和构建过程中扮演着重要角色,其改进和特性极大地简化了Java开发者的日常工作。通过熟练掌握Maven,开发者可以高效地构建、测试和...

    maven3.8下载包

    &lt;scope&gt;test&lt;/scope&gt; ``` Maven通过执行不同的生命周期阶段,如`clean`(清理项目)、`compile`(编译源代码)、`test`(运行测试)、`package`(打包应用)和`deploy`(部署应用),帮助开发者完成整个开发...

    maven依赖+继承+聚合

    此外,Maven还支持依赖范围(scope),如编译(compile)、测试(test)、运行(runtime)等,以控制依赖在不同阶段的作用。 接下来是"Maven继承"。在大型项目中,多个模块可能共享相同的配置或依赖。Maven的继承...

    第一个maven工程案例

    &lt;scope&gt;test&lt;/scope&gt; ``` 3. **Maven生命周期与构建过程** Maven拥有一个清晰的生命周期,主要包括`clean`、`default`(或`compile`、`package`、`install`、`deploy`)和`site`三大阶段。在`default`阶段...

    maven使用文档,maven使用文档

    7. **Dependency Scope (依赖范围)** - Maven 的依赖范围包括 compile、test、provided、runtime、system 和 import。 - 不同的依赖范围决定了该依赖是否会被包含在最终的构建产物中。 8. **排除依赖** - ...

    Maven完全适用手册

    **Maven完全适用手册概述** Maven是一款强大的Java项目管理和集成工具,它通过XML格式的配置文件(pom.xml)来管理项目的构建、报告和依赖关系。Maven2相较于其前身Maven1进行了大量改进,提供了更高效、简洁的体验...

    Maven Web基础搭建示例

    &lt;scope&gt;provided&lt;/scope&gt; &lt;!-- 添加其他依赖 --&gt; ... ``` ### 四、编写Web应用 在`src/main/java`下创建你的Java类,例如Servlet,实现业务逻辑。在`src/main/webapp/WEB-INF`下编写`web.xml`,配置Servlet...

    IDEA11 Maven3快速入门及应用

    - **scope**: 作用范围。 在实际开发中,还需要根据项目需求配置具体的依赖库,例如使用Java EE 6.0和Spring MVC等技术栈。 #### 配置Maven远程仓库(私服) 除了中央仓库之外,还可以配置Maven连接到远程仓库...

    5分钟熟悉Maven

    &lt;scope&gt;test&lt;/scope&gt; ``` - `&lt;groupId&gt;`:组织标识符,类似于Java包名的前缀。 - `&lt;artifactId&gt;`:项目名称。 - `&lt;version&gt;`:项目版本号。 - `&lt;dependencies&gt;`:项目的依赖关系列表。 #### 四、构建项目 *...

    Maven 使用入门.pdf

    - `scope`:依赖的作用范围,常见的有: - `compile`:默认作用域,适用于编译、测试和运行时。 - `provided`:已提供,在编译和测试时有效,但在运行时无效。 - `runtime`:运行时,适用于运行时而非编译时。 ...

    maven安装包

    &lt;scope&gt;test&lt;/scope&gt; ``` 6. **Maven仓库** Maven 使用仓库管理依赖,包括本地仓库(默认在用户主目录的`.m2\repository`下)、中央仓库(http://repo1.maven.org/maven2/)和私有仓库(企业内部使用)。 7...

    MavenHelper插件 帮你检查maven的各种冲突

    2. **合理管理scope**:理解并正确设置dependency的scope(如compile、runtime、test等),可以有效减少不必要的依赖引入。 3. **使用BOM(Bill of Materials)**:对于多个模块共用相同依赖的情况,可以考虑使用BOM...

    Maven开发包下载

    &lt;scope&gt;test&lt;/scope&gt; ``` 通过`mvn compile`命令,Maven会根据POM.xml中的配置,自动下载并管理依赖,编译项目源代码。其他常用命令包括`mvn test`(运行测试)、`mvn package`(打包项目)和`mvn install`...

    idea离线导入maven项目

    在这种情况下,IntelliJ IDEA(简称idea)提供了离线模式来导入Maven项目,充分利用本地已经存在的Maven仓库。以下是详细的操作步骤和相关知识点: 1. **准备离线Maven仓库** 首先,你需要在有网络连接的计算机上...

    maven 实用指南 中文

    2. **依赖范围(Dependency Scope)**:不同类型的依赖有不同的作用范围,如compile(编译时依赖)、runtime(运行时依赖)、test(仅用于测试)等。 3. **依赖冲突解决(Dependency Resolution)**:Maven遵循“最...

Global site tag (gtag.js) - Google Analytics