[Java] [Maven3] Summary of how to use Maven3

Apache Maven Study notes.

About this article

This is a memo that summarizes materials related to Java beginners. The version will be Maven3.

official

Maven – Welcome to Apache Maven

How to read

Apache Maven (Apache Maven / Maven) (At first I thought it was a Marvel-like Marvel of American comics)

Add user settings

Maven – Settings Reference

settings.xml location

Windows Add settings.xml under C: \ Users \ user \ .m2.

Proxy settings

In case of proxy environment Add the following settings to settings.xml.

Proxy setting example


<?xml version="1.0" encoding="UTF-8"?>
<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">
    <proxies>
        <proxy>
            <id>proxy-http</id>
            <active>true</active>
            <protocol>http</protocol>
            <host>proxy.exsample.com</host>
            <port>8080</port>
            <!--<username></username>-->
            <!--<password></password>-->
        </proxy>
        <proxy>
            <id>proxy-https</id>
            <active>true</active>
            <protocol>https</protocol>
            <host>proxy.exsample.com</host>
            <port>8080</port>
            <!--<username></username>-->
            <!--<password></password>-->
        </proxy>
    </proxies>
</settings>

[java --About maven proxy authentication error in internal environment --Stack overflow](https://ja.stackoverflow.com/questions/22073/%E7%A4%BE%E5%86%85%E7%92%B0 % E5% A2% 83% E3% 81% AB% E3% 81% 8A% E3% 81% 91% E3% 82% 8Bmaven% E3% 81% AE% E3% 83% 97% E3% 83% AD% E3 % 82% AD% E3% 82% B7% E8% AA% 8D% E8% A8% BC% E3% 82% A8% E3% 83% A9% E3% 83% BC% E3% 81% AB% E3% 81 % A4% E3% 81% 84% E3% 81% A6)

Add application server settings

Application server configuration example such as Tomcat

Deployment destination server setting addition example


    <servers>
        <server>
            <id>localhost</id>
            <username>user</username>
            <password>pass</password>
        </server>
    </servers>

[Windows] [IntelliJ] [Java] [Tomcat] Create an environment for Tomcat9 with IntelliJ --Qiita

Generate environment from archetype

Generate a simple configuration (Java Main Class + JUnit configuration)

Basically, I think you should use maven-archetype-quickstart in ʻorg.apache.maven.archetypes`. An archtype that includes the main function and JUnit settings.

However, JUnit is as old as 3.8.1, so it may be better to upgrade to 4.x or 5.x.

Maven Repository: junit » junit

Run on the command line

Maven execution example


$ mvn archetype:generate \
  -DarchetypeGroupId=org.apache.maven.archetypes \
  -DarchetypeArtifactId=maven-archetype-quickstart \
  -DinteractiveMode=false \
  -DgroupId=${groupId} \
  -DartifactId=${artifactId}

Others / plug-ins

Explicitly specify the compiled version of Java

Use maven-compiler-plugin.

pom.xml


  <build>
    <plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-compiler-plugin</artifactId>
        <version>3.6.1</version>
        <configuration>
          <source>1.8</source>
          <target>1.8</target>
          <encoding>UTF-8</encoding>
        </configuration>
      </plugin>
    </plugins>
  </build>

Apache Maven Compiler Plugin – Introduction Maven Repository: org.apache.maven.plugins » maven-compiler-plugin

How to change Java version for Maven in IntelliJ? - Stack Overflow What to do if Java Compiler is version 1.5 on heroku push and compile error occurs when using lambda expression --Qiita

Run the program from maven

How to run Java program from Maven --Qiita

Add ʻexec: java` to the command line

Combine jar files including libraries into one

If you want to combine externally dependent jars into one jar file, you should use Maven Assembly Plugin.

Collect externally dependent jars with Maven Assembly Plugin --A Memorandum

When using Maven that comes with the IDE

IntelliJ IDEA Windows Maven execution binary exists around the following, so put it in the PATH here.

C:\Program Files\JetBrains\IntelliJ IDEA Community Edition 2017.1.2\plugins\maven\lib\maven3\bin

For multi-configuration projects

Run-time options for multi-module configuration projects · Getting started with Maven3

reference

Maven – Welcome to Apache Maven Maven3 Tutorial

Recommended Posts

[Java] [Maven3] Summary of how to use Maven3
Summary of Java communication API (1) How to use Socket
Summary of Java communication API (3) How to use SocketChannel
Summary of Java communication API (2) How to use HttpUrlConnection
[java] Summary of how to handle char
[Java] How to use Map
[java] Summary of how to handle character strings
[Java] How to use Map
[Java] Summary of how to abbreviate lambda expressions
How to use java Optional
How to use java class
[Java] How to use Optional ②
[Java] How to use removeAll ()
[Java] How to use string.format
How to use Java variables
[Java] How to use Optional ①
[Java] How to use compareTo method of Date class
Summary of how to implement default arguments in Java
How to use Java HttpClient (Get)
[Java] How to use join method
[Processing × Java] How to use variables
[Java] How to use LinkedHashMap class
[JavaFX] [Java8] How to use GridPane
How to use class methods [Java]
[Java] How to use List [ArrayList]
How to use classes in Java?
[Processing × Java] How to use arrays
How to use Java lambda expressions
[Java] How to use Math class
How to use Java enum type
How to use trained model of tensorflow2.0 with Kotlin / Java
How to make a Java calendar Summary
Multilingual Locale in Java How to use Locale
[Java] How to use the File class
[Java] How to use the hasNext function
How to use submit method (Java Silver)
[Java] How to use the HashMap class
Summary of how to write annotation arguments
[Easy-to-understand explanation! ] How to use Java instance
[Java] How to use the toString () method
Studying how to use the constructor (java)
[Processing × Java] How to use the loop
How to use Java classes, definitions, import
[Easy-to-understand explanation! ] How to use Java polymorphism
[Processing × Java] How to use the class
How to use Java Scanner class (Note)
[Processing × Java] How to use the function
[Easy-to-understand explanation! ] How to use ArrayList [Java]
[Java] How to use the Calendar class
[Java] Learn how to use Optional correctly
[Easy-to-understand explanation! ] How to use Java overload
try-catch-finally exception handling How to use java
Summary of how to use the proxy set in IE when connecting with Java
[Easy-to-understand explanation! ] How to use Java encapsulation
[Ruby on Rails] "|| =" ← Summary of how to use this assignment operator
How to use Map
How to use rbenv
How to use letter_opener_web
How to use with_option
How to use fields_for
How to use java.util.logging