Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What are the scope scopes that Maven depends on

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/01 Report--

What is the scope of scope that Maven depends on? in view of this question, this article introduces the corresponding analysis and solution in detail, hoping to help more partners who want to solve this problem to find a more simple and feasible method.

In POM, it was introduced, which mainly manages the deployment of dependencies. Currently, five values are available:

Compile, the default, applies to all phases and will be released with the project.

Provided, similar to compile, expects JDK, container, or consumer to provide this dependency. Such as servlet.jar.

Runtime, used only at run time, such as the JDBC driver, is suitable for the run and test phases.

Test, used only during testing, is used to compile and run test code. Will not be released with the project.

System, similar to provided, needs to explicitly provide a jar,Maven that contains dependencies and does not look for it in Repository.

The scope of dependencies controls which dependencies are available in which classpath and which are contained in an application. Let's take a closer look at each range:

Compile (compilation scope)

Compile is the default scope; if no scope is provided, the scope of the dependency is the compilation scope. Compilation scope dependencies are available in all classpath, and they are also packaged.

Provided (scope provided)

Provided dependencies are used only when the JDK or a container has provided the dependency. For example, if you develop a web application, you may need the available Servlet API in compiling classpath to compile a servlet, but you don't want to include the Servlet API; in the packaged WAR. The Servlet API JAR is provided by your application server or servlet container. Provided scoped dependencies are available when compiling classpath (not at run time). They are not transitive and will not be packaged.

Runtime (Runtime scope)

Runtime dependencies are required when running and testing the system, but not at compile time. For example, you may only need JDBC API JAR at compile time and JDBC only at run time

Driver implementation.

Test (Test range)

Test scope dependencies are not needed at normal compile and run time, and they are only available during the test compilation and test run phase.

System (system wide)

The system scope dependency is similar to provided, but you must explicitly provide a path to the JAR file on the local system. This is done to allow compilation based on local objects that are part of the system class library. Such a component should be available all the time, and Maven will not look for it in the repository. If you set a dependency scope to system scope, you must also provide a systemPath element. Note that this scope is not recommended (you should always try to reference dependencies from public or custom Maven repositories).

The answers to the questions about the scope scope of Maven dependency are shared here. I hope the above content can be of some help to you. If you still have a lot of doubts to be solved, you can follow the industry information channel to learn more about it.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report