java Maven JDBC jar文件的正确作用域是什么?
对于我的开发站,我需要我的项目“查看”JDBC驱动程序。但是,当我将项目部署到服务器时,如果JDBC驱动程序位于/lib文件夹中,它们将导致容器行为异常
我试着将<scope>provided</scope>
设置为我不想在计算机上打包的驱动程序。war文件,但我无法让我的IDE运行该项目
在pom.xml
上声明JDBC驱动程序的正确作用域是什么,这样它们就不会打包部署,我就可以在我的开发站上使用它们了<scope>runtime</scope>
提前感谢,
# 1 楼答案
您的问题的简短答案是:您应该使用
provided
范围为什么不
runtime
?让我们检查一下Maven文档:提供
运行时
因此,Maven可能不会在compile的类路径中公开
runtime
范围的依赖项,因此您将无法在代码中直接使用它们。但是,像Class.forName("class.from.runtime.Scope")
这样的代码可以编译我想问题在于您的IDE没有捕获
pom.xml
更改。通常,通过“清理缓存”或“更新”/“同步”项目可以解决此问题。下面是如何在Eclipse和IDEA中执行此操作