我添加了本地依赖库(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>
一切正常,直到 Maven 生成 war Artifact 为止。
我在生成的war文件中查找过,但是,里面不存在jar依赖项。
有什么想法吗?
我知道我可以使用maven installfile
。我需要使用这种依赖声明来集中解决问题。
最佳答案
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.
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.
系统作用域似乎需要容器或 JDK 来提供依赖项作为提供的作用域。因此,依赖项不会打包到 WAR 文件中。
您可以使用 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>
关于java - Maven:在 war/WEB-INF/lib 中找不到本地依赖文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57255714/