0

I need to use Maven-invoker in my app. I run my app in an Alpine-based docker container. So, I put into Dockerfile commands to install Maven and add the Maven Home directory to the PATH environment variable.

When the container is up I can go inside and see, that Maven Home is not in the PATH. Once I run "source /etc/profile.d/maven.sh" manually in container I can see the maven home in the PATH, but it disappears when I open a new terminal.

My maven.sh contains following: export PATH=/usr/share/java/maven-3/bin:$PATH

Also I tried this:

export M2_HOME=/usr/share/java/maven-3
export MAVEN_HOME=/usr/share/java/maven-3
export PATH=${M2_HOME}/bin:${PATH}

My Dockerfile contains:

RUN apk add --no-cache maven
COPY maven.sh /etc/profile.d
RUN chmod +x /etc/profile.d/maven.sh
RUN source /etc/profile.d/maven.sh

I will be very grateful for help in solving this problem.

nikiforov.java
  • 229
  • 4
  • 12
  • What's your entrypoint? – Alexey R. Sep 29 '21 at 14:18
  • Why do oyu need M2_HOME, MAVEN_HOME? Just use `export PATH=/usr/shared/java/maven-3/bin:${PATH}`... – khmarbaise Sep 29 '21 at 14:22
  • Can you explain why: `Maven-invoker `? – khmarbaise Sep 29 '21 at 14:23
  • @AlexeyR., the entrypoint is `["./run.sh"]`; run.sh = `#!/bin/sh exec java ${JAVA_OPTS} -jar /app.jar ${@}` – nikiforov.java Sep 29 '21 at 14:54
  • @khmarbaise, I tried this as well. PATH holds added value only in a current terminal session. – nikiforov.java Sep 29 '21 at 14:56
  • @khmarbaise, I want to use a maven plugin in runtime. So I need to have Maven installed in my docker container. It works on my local computer – nikiforov.java Sep 29 '21 at 14:59
  • which plugins? And why inside the container? – khmarbaise Sep 29 '21 at 19:48
  • @khmarbaise, the purpose is to convert swagger documentation into PDF make it downloadable from a special web page. I use Swagger2MarkupConverter to convert documentation into askiidocs, and then I use asciidoctor-maven-plugin and asciidoctorj-pdf to convert that askiidocs to PDF. It works well during maven build circle. So , the idea is to install maven into a docker container and use maven-invoker to generate pdf documentation in runtime. – nikiforov.java Sep 30 '21 at 06:47
  • @khmarbaise, I solved this problem by adding ENV PATH=/usr/share/java/maven-3/bin:$PATH into Dockerfile. Now the maven.home is in PATH – nikiforov.java Sep 30 '21 at 07:28

1 Answers1

0

I solved this problem by adding ENV PATH=/usr/share/java/maven-3/bin:$PATH into Dockerfile. Now the maven.home is in PATH.

nikiforov.java
  • 229
  • 4
  • 12