[英]using external jar dependency in docker
I am using external jars added through scope = system with ${basedir}/src/main/java/... added as a systempath under the dependency sub group in pom.xml.我正在使用通过 scope = system 添加的外部 jars = system with ${basedir}/src/main/java/... 作为系统路径添加到 pom.Z0F635D0E0F3874FFF8B581C132ZE6 中的依赖项子组下。 Whenever I use the project locally from IntelliJ, there are no warnings or error.
每当我从 IntelliJ 本地使用项目时,都没有警告或错误。 However when i try to start the.jar file from a docker container i get exceptions about the dependency.
但是,当我尝试从 docker 容器中启动 .jar 文件时,我得到了关于依赖项的异常。
I have tried adding the jars though Libraries under project structure in IntelliJ and just adding the jars in libs folder under the root.我已经尝试通过 IntelliJ 中项目结构下的库添加 jars,并在根目录下的 libs 文件夹中添加 jars。 First i was providing the absolute path but then i changed it to ${basedir} because the absolute path wasn't mapped as a volume on the docker container.
首先我提供了绝对路径,但后来我将其更改为 ${basedir} 因为绝对路径没有映射为 docker 容器上的卷。 Is there any way i can pack the external jars with the project jar so i could use it in a docker container?
有什么办法可以将外部 jars 与项目 jar 打包在一起,以便我可以在 docker 容器中使用它?
IIUC you have at least two options: IIUC 你至少有两种选择:
Assuming the JARs are in ${PWD}/jars
on your host machine and you wish them in ${WORKDIR}/jars
in the container:假设 JARs 在您的主机上的
${PWD}/jars
中,并且您希望它们在容器中的${WORKDIR}/jars
中:
FROM [[original-image]]
WORKDIR ...
COPY ./jars ./jars
Then, ensure your code references the JARs via the [[WORKDIR]]/jars/[[some-jar]]
然后,确保您的代码通过
[[WORKDIR]]/jars/[[some-jar]]
引用 JARs
NB [[WORKDIR]]
is whatever you set as the container's working directory.注意
[[WORKDIR]]
是您设置为容器工作目录的任何内容。
docker run ... --volume=${PWD}/jars:[[WORKDIR]]/jars ...
NB [[WORKDIR]]
is whatever you will use as the container's working directory.注意
[[WORKDIR]]
是您将用作容器工作目录的任何内容。 This is the location where the JARs will be mounted in the container.这是 JARs 将安装在容器中的位置。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.