PROGRAMMING

  MINTE9
REMEMBERS




Last update:   13-03-2022

Maven

With Maven, you can have better dependency management.
 
sudo apt-get update
sudo apt-get -y install maven

mvn -v
    # Apache Maven 3.8.2

# To install on Windows download maven binary zip from apache website.
# Add /bin folder to your path and test maven installation.

Project

Setup a Java project for Maven to build.
 
/**
 * Maven import library example (joda.time)
 */

package com.minte9.demo;
import org.joda.time.LocalTime;

public class DemoCurrentTime {
    public static void main(String[] args) {
        
        LocalTime currentTime = new LocalTime();
        System.out.println(
            "The current local time is: " + currentTime
        );
  }
}

Pom

Create Maven pom.xml project definition (next to src folder).
 

Compile

Compile and run the project.
 
cd D:\developments\myproject
mvn package
    # mvn clean
    # mvn install
    # mvn compile

java -jar ./target/demo-maven-0.1.0.jar 
    # The current local time is: 16:57:00.610

M2

The .m2 repository is located in your home directory.
 
/home/catalin/.m2

# C:\Users\Catalin\.m2\repository
Windows    (2/2)

Windows

Extract to directory and add to PATH environment.
 
PATH D:\apache-maven-3.8.4\bin

Version: mvn --version
    # Apache Maven 3.8.4

Settings

D:\apache-maven-3.8.4\conf\settings.xml
 
<?xml version="1.0" encoding="UTF-8"?>
<settings 
    xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.1.0 
        http://maven.apache.org/xsd/settings-1.1.0.xsd" 
    xmlns="http://maven.apache.org/SETTINGS/1.1.0"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <mirrors>
      <mirror> 
          <id>Artifactory</id> 
          <name>Artifactory Public Mirror</name> 
          <url>
              https://artifacts.myapps.com:443/artifactory/maven-central-remote/
          </url> 
          <mirrorOf>central</mirrorOf> 
      </mirror>
  </mirrors>
</settings>

Certificate

Se Environment PATH generate and import certificate.
 
D:\openssl-1.1.1k-vs16-x86\bin

D:\>openssl version
OpenSSL 1.1.1k

cd D:\apache-maven-3.8.4
openssl s_client -showcerts -connect artifacts.myapps.com:443 | 
    openssl x509 -outform PEM > artifacts_ca.cer

echo %JAVA_HOME%
C:\Program Files (x86)\Java\jdk1.8.0_281

keytool -import -trustcacerts -keystore 
    "%JAVA_HOME%\jre\lib\security\cacerts" -storepass 
    myappspassword -alias Artifact -import -file artifacts_ca.cer
    # important: JAVA_HOME\jre

mvn -version
    Apache Maven 3.8.4 
    Maven home: D:\apache-maven-3.8.4
    Java version: 1.8.0_281,  runtime: jdk1.8.0_281\jre

Project

 
cd D:\maven\demo
mvn package

D:\maven\demo>java -jar target\demo-maven-0.1.0.jar
The current local time is: 12:04:45.864

Questions     github Maven
Spring Boot