WAR 中不存在外部 JAR
我必须使用 Maven 存储库上不存在的 JAR。
我通过创建 libs 文件夹来放置 JAR,然后进入 pom.xml 并执行以下操作:
<dependency>
<groupId>aaa.bbb.ccc</groupId>
<artifactId>ABC</artifactId>
<scope>system</scope>
<version>1.0</version>
<systemPath>${project.basedir}/libs/ABC.jar</systemPath>
</dependency>
这有效,当我执行 mvn clean install 时,我可以在我的“Maven 依赖项”列表。
但是,执行 Maven 命令后,这些 JAR 在目标文件夹中创建的 Application.war 的依赖项列表中不可见。
你知道为什么会发生这种情况吗?我无法理解它,到目前为止我还没有找到解决方案。
I have to use JAR's which don't exist on Maven repo.
I did that by creating libs folder where I put my JAR's and after that I went into pom.xml and did this:
<dependency>
<groupId>aaa.bbb.ccc</groupId>
<artifactId>ABC</artifactId>
<scope>system</scope>
<version>1.0</version>
<systemPath>${project.basedir}/libs/ABC.jar</systemPath>
</dependency>
And this works, when I execute mvn clean install I can see these external JAR's in my "Maven Dependencies" list.
However after executing Maven command these JARs are not vissible in dependencies list on my Application.war which was created in target folder.
Do you know why this is happening? I'm failing to understand it and I didn't find solution so far.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
正如 khmarbaise 所说,我的问题的解决方案是将我的依赖项添加到我的本地 Maven 存储库,而不是使用系统作用域和系统路径属性。
将第 3 方 JAR 添加到本地 Maven 存储库的指南:https://mkyong.com/maven/how-to-include-library-manully-into-maven-local-repository/
As khmarbaise said, solution to my problem was adding my dependencies to my local Maven repository instead of using system scope and system path properties.
Guide for adding 3rd party JARs to your local Maven repository: https://mkyong.com/maven/how-to-include-library-manully-into-maven-local-repository/
我也尝试过同样的操作,发现如果我通过依赖项,则会出现 NoClassDefFound 错误,因此,如果您想将外部 jar 放置在 .war\WEB-INF\lib\ 中,
您只需执行以下步骤:-
1.在项目下创建一个“lib”文件夹,如下所示:“\src\main\webapp\WEB-INF\lib”
2.复制您想要包含在 WAR 包文件夹中的所需“jar”等。
3.像平常一样调用您的 Maven 构建。我使用“mvn install”,它会创建构建 war 文件。
I was also trying the same and found if i go via dependency then issue with NoClassDefFound error, So if you want to have external jar to be placed in .war\WEB-INF\lib\
you need to simply below steps:-
1.Create a “lib” folder under your project like this: “\src\main\webapp\WEB-INF\lib”
2.Copy needed “jars” etc that you want included inside your WAR bundle folder.
3.Invoke your maven build as you normally do. I use “mvn install”, which creates builds the war file.