简体   繁体   English

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

[英]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.

相关问题 Maven:将 war/web-inf/classes 中的类作为 jar 添加到 war/web-inf/lib - Maven: Adding classes from war/web-inf/classes as a jar to war/web-inf/lib Maven大战并将版本号放在WEB-INF / lib中的jar中 - Maven war and put the version number in the jars in WEB-INF/lib 在WAR的WEB-INF / lib文件夹中重命名Maven依赖项 - Renaming Maven dependency in WAR's WEB-INF/lib folder JBoss 4.0.2 war部署中找不到WEB-INF / lib jar - WEB-INF/lib jars not found in JBoss 4.0.2 war deploy 从打包的war文件中排除本地WEB-INF / lib jar - Exclude local WEB-INF/lib jars from packaged war file 在 Maven 项目 POM 中输入<systempath>标签未包含在生成的战争文件 WEB-INF\lib 文件夹中</systempath> - Enteries in Maven Project POM with <systemPath> tag does not get included in the generated war file WEB-INF\lib folder Maven 依赖项在 WEB-INF/lib 中不可见 - Maven dependencies not visible in WEB-INF/lib 在JBOSS 7中,war文件可以访问ear / lib而非Web-inf / lib中的jar文件 - In JBOSS 7 can war file access a jar file located in ear/lib instead of web-inf/lib 如何使用Maven在WAR,WEB-INF / lib目录中包含特定的jar - How to Include specific jars in WAR, WEB-INF/lib directory with maven 如何使用Maven在WAR档案WEB-INF / lib中包含JAR? - How to include JARs in WAR archive WEB-INF/lib using Maven?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM