How to add jars from systempath in Docker

2019-08-20 11:56发布

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>

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"]

But docker is complaining:

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

How to deal with this?

2条回答
可以哭但决不认输i
2楼-- · 2019-08-20 12:14

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

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.

查看更多
兄弟一词,经得起流年.
3楼-- · 2019-08-20 12:18

I can now build the Dockerfile. Here is my revised Dockerfile:

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/
ENV JAR_HOME /home/app/jars
RUN  mvn -f /home/app/pom.xml clean install


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/jars/*.jar $CATALINA_HOME/webapps/WEB-INF/lib/
EXPOSE 8080
CMD ["catalina.sh", "run"]
查看更多
登录 后发表回答