如何在Docker中从系统路径添加jar [英] How to add jars from systempath in Docker

查看:541
本文介绍了如何在Docker中从系统路径添加jar的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的maven pom文件中,我有一些依赖关系,这些依赖关系是我们来自其他项目的jar文件,这些文件不在存储库中.

In my maven pom file I have some dependencies which are our own jar files from other projects which are not in repository.We have used 'system' scoped dependencies like

<dependency>
        <groupId>efaadmin</groupId>
        <artifactId>efaadmin</artifactId>
        <scope>system</scope>
        <version>1.0</version>
        <systemPath>
        ${basedir}\src\main\webapp\WEB-INF\lib\efaadmin.jar
        </systemPath>
</dependency>

现在,在编写Dockerfile时,这些依赖关系已成为我们的绊脚石.

Now when writing Dockerfile these dependencies have become our stumbling block.

#
# Build stage
#

FROM maven:3.6.1-jdk-8-slim AS BUILD
COPY src /home/app/src
COPY pom.xml /home/app
COPY jars/*.jar /home/app/jars/
RUN  mvn -f /home/app/pom.xml

#
# Package stage
#
FROM tomcat:7.0-jdk8-openjdk-slim
ENV CATALINA_HOME /usr/local/tomcat
ENV PATH $CATALINA_HOME/bin:$PATH
COPY --from=build /home/app/target/DrySign.war $CATALINA_HOME/webapps/ 
COPY --from=build /home/app/target/jars/* $CATALINA_HOME/webapps/xxxxx/WEB-INF/lib/
EXPOSE 8080
CMD ["catalina.sh", "run"]

但是码头工人在抱怨:

'dependencies.dependency.systemPath' for efaadmin:efaadmin:jar must specify an absolute path but is ./jars/efaadmin.jar

如何处理?

推荐答案

这看起来像Docker的问题,看起来像Maven的问题. Maven需要用于系统范围依赖关系的绝对路径.您可以通过注释掉以下Dockerfile的所有行来测试这种情况

This does not look like an issue with Docker, it looks like an issue with Maven. Maven requires an absolute path for system scope dependencies. You can test this is the case by commenting out all the lines of your Dockerfile below

...
RUN  mvn -f /home/app/pom.xml
# comment out everything below this, I think you'll still see the failure

顺便说一句,为什么您为systemPath使用反斜杠而不是正斜杠?您的Maven系统范围的依赖项被解释为相对路径,而不是绝对路径.解决此问题后,您的构建应会按预期工作.

By the way, why are you using backslashes not forward slashes for your systemPath? Your Maven system scoped dependencies are being interpreted as relative paths, not absolute paths. When you fix this, your build should work as intended.

这篇关于如何在Docker中从系统路径添加jar的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆