【问题标题】:packaging maven project with external jar使用外部 jar 打包 maven 项目
【发布时间】:2017-01-21 07:15:30
【问题描述】:
我一直在尝试从我的项目(在 Intellij IDEA 中)制作一个可运行的 jar,它依赖于 oracle(驱动程序 -> ojdbc6)jar。当我将项目与所有依赖项一起打包时,唯一会被排除的就是 jar。这意味着当我运行它时,我的数据库查询将失败。
我发现了几个类似的问题*,但我没有执行它们,因为我不知道 oracle jar 的 groupid 和 artifact id。
*喜欢这个:build maven project with propriatery libraries included
ps:通过IDEA的功能(项目结构->模块)添加的jar wad,使用此解决方案项目可以正常运行。问题从包装开始。
【问题讨论】:
标签:
maven
intellij-idea
jar
【解决方案1】:
短解决方案:尝试使用以下方法:
<dependency>
<groupId>LIB_NAME</groupId>
<artifactId>LIB_NAME</artifactId>
<version>1.0.0</version>
<scope>system</scope>
<systemPath>${basedir}/WebContent/WEB-INF/lib/YOUR_LIB.jar</systemPath> // give the path where your jar is present
</dependency>
确保 groupId、artifactID 和版本号是唯一的。
长解:
- 将 jar 文件下载到您的计算机。
- 使用提示导航到您下载 jar 的文件夹。
- 运行以下命令将 jar 安装到本地存储库。
mvn install:install-file -DgroupId=com.oracle -DartifactId=ojdbc6 -Dversion=11.2.0.3 -Dpackaging=jar -Dfile=ojdbc6.jar -DgeneratePom=true
-
最后,将依赖添加到 pom.xml 中。
<dependency>
<groupId>com.oracle</groupId>
<artifactId>ojdbc6</artifactId>
<version>11.2.0.3</version>
</dependency>
另外,不要忘记在运行项目时使用 -U 选项。