java - Maven:在 war/WEB-INF/lib 中找不到本地依赖文件

标签 java maven

我添加了本地依赖库(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。我需要使用这种依赖声明来集中解决问题。

最佳答案

来自Maven documentation :

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/

相关文章:

java - Jenkins 配置文件 Maven 多个 Nexus 存储库下载

jakarta-ee - struts2 junit 2.3.12 插件 - 无法在 struts2 junit4 中编写成功测试

java - Maven Spring Boot 插件 : how to run spring boot from another project

java - 在本地开发中使用 Docker

java - 如何使用 JUnit 与 Spring 和 Hibernate 来模拟事务的结束以隔离 LazyInitializationException?

Java应用程序不断检查表中添加的新行

java - 使用 try/catch block 尝试读取文件时出现未处理的异常错误

java - 在二维数组中查找相似行的代码

maven - 如何轻松交换 Maven 设置配置文件?

java - 在java中添加AutoCloseable重要吗?