How to use Maven that I can't hear anymore

maven how to use

Introduction

From WebIDE Full-stack on SAP Cloud Platform It is used when you create a new Java application project.

Knowledge of build tools in the Java area stopped at ʻant` This is a summary of some research on how to use it.

What is maven

Maven is a tool for building Java programs. Describe the program information in pom.xml, install the necessary modules, and It compiles, deploys modules, etc. with commands.

Installation

Install using homebrew.

brew install maven

Description of project definition (pom.xml)

The following definitions can be described under the project element.

element Description
modelVersion pom version
groupId Project name (unique). It seems common to specify the root package name.
artifactId Deliverable name. Used for names such as JARs and WARs to create
version Project version
packaging Deliverable format. Specify jar or war
name Display name. Used when creating documents, etc.

Execution method

Delete build result

mvn clean

compile

mvn compile

Compile the source file Target source is under src / main / java /

Output the compiled class file to target / classes

test

mvn test

Test execution with a file that corresponds to the following pattern.

Artifact creation

mvn package

Create an artifact in target

The file name is determined by artifactId, version and packaging of pom.xml.

fill in pom.xml

Main element description method and set value

Dependency resolution

<dependencies>
    <dependency>
        <groupId>javax.servlet</groupId>
        <artifactId>javax.servlet-api</artifactId>
        <version>3.1.0</version>
        <scope>provided</scope>
    </dependency>
    <dependency>
    ~~~
    </dependency>
</dependencies>

element Description
dependencies Described in the element
dependency Describe one module per element
groupId Project name (unique). It seems common to specify the root package name.
artifactId Deliverable name. Used for names such as JARs and WARs to create
version Project version
scope Condition specification that the library adds to the classpath

What can be set in scope

Setting value for scope Timing of addition
compile Default value. Add to classpath in all situations
provided Add to classpath only at compile time
runtime Add to classpath during test or normal run
test Specify if required only during testing
system If you want to explicitly add system libraries to your classpath. Note that it does not search the repository.

Recommended Posts

How to use Maven that I can't hear anymore
About the matter that I was addicted to how to use hashmap
[Java] [Maven3] Summary of how to use Maven3
How to use Map
How to use with_option
How to use fields_for
How to use java.util.logging
How to use map
How to use collection_select
How to use Twitter4J
How to use active_hash! !!
How to use MapStruct
How to use hidden_field_tag
How to use TreeSet
[How to use label]
How to use identity
How to use hashes
How to use JUnit 5
How to use Dozer.mapper
How to use Gradle
How to use org.immutables
How to use java.util.stream.Collector
How to use VisualVM
How to use Map
[Rails] I don't know how to use the model ...
[Android Studio] I want to use Maven library on Android
How to use Chain API
[Java] How to use Map
How to use Priority Queuing
[Rails] How to use enum
How to use java Optional
How to use JUnit (beginner)
How to use Ruby return
[Rails] How to use enum
How to use @Builder (Lombok)
[Swift] How to use UserDefaults
How to use java class
How to use Swift UIScrollView
How to use Big Decimal
[Java] How to use Optional ②
[Java] How to use removeAll ()
How to use String [] args
[Java] How to use string.format
How to use rails join
How to use Java Map
Ruby: How to use cookies
How to use dependent :: destroy
How to use Eclipse Debug_Shell
How to use Apache POI
[Rails] How to use validation
How to use Java variables
[Rails] How to use authenticate_user!
[Rails] How to use "kaminari"
How to use GC Viewer
[Java] How to use Optional ①
How to use Lombok now
[Creating] How to use JUnit
[Rails] How to use Scope
How to use Maven to place resource files outside the JAR
How to use the link_to method
How to use arrays (personal memorandum)