Home > Software engineering >  How to add Maven Home (M2_HOME) in PATH in Alpine Linux based docker container
How to add Maven Home (M2_HOME) in PATH in Alpine Linux based docker container

Time:10-02

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.

CodePudding user response:

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

  • Related