[英]Maven: Local dependecy file not found into war/WEB-INF/lib
I've added my local dependency library ( jar
file): 我添加了本地依赖库(
jar
文件):
<dependency>
<groupId>com.oracle.jdbc</groupId>
<artifactId>ojdbc7</artifactId>
<version>12.1.0.2</version>
<scope>system</scope>
<systemPath>${project.basedir}/libs/ojdbc7-12.1.0.2.jar</systemPath>
</dependency>
Everything works fine, up to when maven generates war artifact. 一切正常,直到maven生成战争伪像为止。
I've look up inside generated war file, but, jar dependency is not there inside. 我在生成的war文件中查找,但是里面没有jar依赖项。
Any ideas? 有任何想法吗?
I know I'm able to use maven installfile
. 我知道我可以使用
maven installfile
。 I need to focus the problem using this kind of dependency declaration. 我需要使用这种依赖关系声明来解决这个问题。
From Maven documentation : 从Maven文档中 :
system : This scope is similar to provided except that you have to provide the JAR which contains it explicitly.
system :此作用域与提供的作用域相似,只是您必须提供显式包含它的JAR。 The artifact is always available and is not looked up in a repository.
该工件始终可用,并且不会在存储库中查找。
provided : This is much like compile, but indicates you expect the JDK or a container to provide the dependency at runtime.
提供的 :这很像编译,但是表明您希望JDK或容器在运行时提供依赖项。 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.
例如,在为Java Enterprise Edition构建Web应用程序时,您将对Servlet API和相关Java EE API的依赖关系设置为提供的范围,因为Web容器提供了这些类。 This scope is only available on the compilation and test classpath, and is not transitive.
该作用域仅在编译和测试类路径上可用,并且不可传递。
It seems that system scope needs the container or JDK to provide the dependency as the provided scope. 似乎系统范围需要容器或JDK提供依赖关系作为提供的范围。 Because of that, the dependency is not packed into the WAR file.
因此,该依赖项未打包到WAR文件中。
You can pack the dependencies into the lib folder using maven-war-plugin
like this: 您可以使用
maven-war-plugin
将依赖项打包到lib文件夹中,如下所示:
<plugin>
<artifactId>maven-war-plugin</artifactId>
<version>2.4</version>
<configuration>
...
<webResources>
<resource>
<directory>libs</directory>
<targetPath>WEB-INF/lib</targetPath>
<includes>
<include>ojdbc7-12.1.0.2.jar</include>
</includes>
</resource>
</webResources>
</configuration>
</plugin>
A WAR is an web archive for Servlet Containers like Tomcat, Glassfish, JBoss (...). WAR是Servlet容器(如Tomcat,Glassfish,JBoss(...))的Web存档。 They are specified by the Servlet Specifications.
它们由Servlet规范指定。 The specs point out that the Datasources (Database) is in the Field of the Servlet-Containers.
规范指出,数据源(数据库)在Servlet容器的字段中。
(...) type javax.sql.DataSource for which the reference to the data source is injected by the container prior to the component being made available to the application.
(...)键入javax.sql.DataSource,在使组件对应用程序可用之前,容器将为其引用数据源。
You should place the database-driver to the servlet-container, not the web-application. 您应该将数据库驱动程序放置到servlet容器而不是Web应用程序。
Dependencies in compile scope are automatically added to the target's WEB-INF/lib as part of the Maven build. 作为Maven构建的一部分,编译范围中的依赖项会自动添加到目标的WEB-INF / lib中。 Dependencies in system scope are not, dependencies with a system scope must be explicitly provided by definition.
系统范围的依赖性不是,系统范围的依赖性必须通过定义明确提供。 More information on below URL
有关以下网址的更多信息
Maven 2 assembly with dependencies: jar under scope "system" not included 带有依赖项的Maven 2程序集:不包括作用域“系统”下的jar
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.