settings.xml

Maven設定ファイルであるsettings.xmlを以下に示します。

<?xml version="1.0" encoding="UTF-8"?>
<settings xmlns="http://maven.apache.org/SETTINGS/1.1.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.1.0 http://maven.apache.org/xsd/settings-1.1.0.xsd">
 
  <offline>false</offline>
 
  <proxies> ★1
  	<proxy>
       	<id>http_proxy</id>
      		<active>true</active>
      		<protocol>http</protocol>
      		<host>proxy.contoso.com</host>
      		<port>8080</port>
      		<username>domain\userid</username>
      		<password>password</password>
      		<nonProxyHosts>localhost|FY25-00000</nonProxyHosts>
    	</proxy>
  </proxies>
 
  <profiles>
	  <profile>
		  <id>my profile</id>
		  <repositories> ★2
		  	<repository>
		      		<id>central maven repo</id>
		      		<name>central maven repo https</name>
		      		<url>https://repo.maven.apache.org/maven2</url>
		  	</repository>
		  </repositories>
	  </profile>
  </profiles>
</settings>

★1
proxy環境下にある場合、proxy認証情報を設定に追加します。

★2
リポジトリ-設定をprofileとして登録可能です。
例はcentralリポジトリ-を登録しています。

基本pom.xml

Mavenプロジェクトを生成して基本的に追加するプラグイン等を含めてpom.xmlを以下に示します。

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>com.contoso.sample</groupId>
  <artifactId>maven-sample</artifactId>
  <version>0.0.1-SNAPSHOT</version>
  <build>
  	<plugins>
  		<plugin>
  			<groupId>org.apache.maven.plugins</groupId>
  			<artifactId>maven-compiler-plugin</artifactId>
  			<version>3.8.1</version>
  			<configuration>
  				<source>${java.version}</source>
  				<target>${java.version}</target>
  			</configuration>
  		</plugin>
  	</plugins>
  </build>
  <properties>
  	<java.version>1.8</java.version>
  	<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
  </properties>
  <dependencies>
        <!-- 例としてlogback-classicを追加している -->
  	<dependency>
  		<groupId>ch.qos.logback</groupId>
  		<artifactId>logback-classic</artifactId>
  		<version>1.2.11</version>
  	</dependency>
  </dependencies>
</project>

TroubleShoot

Eclipseのmavenプロジェクトからpom.xmlに依存関係を追加してから、「Maven>プロジェクトの更新」を実行してもライブラリがダウンロードできない場合、解決方法を説明します。
この方法は、Eclipseのembeddedとは別にruntimeをインストールする必要があります。
cmdプロンプトから下記コマンドを実行します。

mvn dependency:get -Dartifact=org.apache.httpcomponents.client5:httpclient5:5.4.2

QR Code
QR Code study:maven:env (generated for current page)