Skip to content

Build your customized maven in Arm architecture

Background:

A new project is launched and this project will deploy on the arm64 architecture server, which is not the same as the x86 platform. luckily, our product is written by java, which is a cross-platform language. what we need to do is build java in the ARM environment. 

To do this, we need Maven with a specific version of java and set up Maven source from closely location instead of Apache’s official source. 

CI/CD pipeline has already implemented, all of the codes have complied, built, and pushed to the Docker registry automatically. therefore, we need a docker version of Maven.

This is what you will learn from the article. 

 

Dockerfile

FROM arm64v8/alpine:3.9
WORKDIR /usr
RUN mkdir /usr/local/jdk
COPY ./jdk-8u271-linux-aarch64.tar.gz /usr/local/jdk

RUN tar -zxvf /usr/local/jdk/jdk-8u271-linux-aarch64.tar.gz -C /usr/local/jdk
RUN rm -rf /usr/local/jdk/jdk-8u271-linux-aarch64.tar.gz

RUN mkdir /usr/local/maven
COPY ./apache-maven-3.6.3-bin.tar.gz /usr/
RUN tar -zxvf /usr/apache-maven-3.6.3-bin.tar.gz -C /usr/local/maven
RUN rm -rf /usr/apache-maven-3.6.3-bin.tar.gz

ENV JAVA_HOME /usr/local/jdk/jdk1.8.0_271
ENV JRE_HOME $JAVA_HOME/jre

ENV M2_HOME /usr/local/maven/apache-maven-3.6.3
ENV PATH $PATH:$JAVA_HOME/bin:$CATALINA_HOME/bin:$M2_HOME/bin
ADD settings.xml /usr/local/maven/apache-maven-3.6.3/conf

Maven Settings:

  1. specify local repository location
<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
          xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd">
  <!-- localRepository
   | The path to the local repository maven will use to store artifacts.
   |
   | Default: ${user.home}/.m2/repository
  <localRepository>/path/to/local/repo</localRepository>
  -->


  <localRepository>/data/maven-cache/repository</localRepository>#this is local Repository
  1. Local source
    <mirror>
      <id>mirrorId</id>
      <mirrorOf>repositoryId</mirrorOf>
      <name>Human Readable Name for this Mirror.</name>
      <url>http://my.repository.com/repo/path</url>
    </mirror>
     -->
 # Local source
     <mirror>
       <id>voiceaimaven</id>
       <mirrorOf>central</mirrorOf>
       <name>voiceai maven</name>
       <url>http://192.168.10.15:8081/repository/maven-public/</url>
    </mirror>

  </mirrors>

Leave a Reply