[JAVA] A memorandum when running Apache Maven on an in-house proxy

I had a hard time running Apache Maven (hereinafter Maven) in an environment with an in-house Proxy, so I would like to summarize the Proxy setting method as a memorandum.

What is Apache Maven?

It is a build tool that manages libraries in Java, builds projects, executes tests, deploys, etc. I understand that it is equivalent to GNU Make in C language.

Verification environment

Ubuntu 16.04.5 LTS

Install Apache Maven

Install Maven. This verification is carried out on Ubuntu.


sudo apt install -y maven
Check if the installation is completed successfully

$ mvn -v
Apache Maven 3.3.9
Maven home: /usr/share/maven
Java version: 9-internal, vendor: Oracle Corporation
Java home: /usr/lib/jvm/java-9-openjdk-amd64
Default locale: ja_JP, platform encoding: UTF-8
OS name: "linux", version: "4.4.0-137-generic", arch: "amd64", family: "unix"

Proxy settings

Edit `` `/etc/maven/settings.xml``` if the internal Proxy wall is standing up

sudo vim /etc/maven/settings.xml
Description example (excerpt of necessary parts)

<!-- proxies
 | This is a list of proxies which can be used on this machine to connect to the network.
 | Unless otherwise specified (by system property or command-line switch), the first proxy | specification in this list marked as active will be used.
 |-->
<proxies>
  <!-- proxy
   | Specification for one proxy, to be used in connecting to the network.
   |-->
  <proxy>
    <id>http_proxy</id>
    <active>true</active>
    <protocol>http</protocol>
    <username>USER_NAME</username>
    <password>PASSWD</password>
    <host>HOST</host>
    <port>PORT</port>
    <nonProxyHosts>NON_PROXY</nonProxyHosts>
  </proxy>
  <proxy>
    <id>https_proxy</id>
    <active>true</active>
    <protocol>https</protocol>
    <username>USER_NAME</username>
    <password>PASSWD</password>
    <host>HOST</host>
    <port>PORT</port>
    <nonProxyHosts>NON_PROXY</nonProxyHosts>
  </proxy>
</proxies>

Operation check

Create a test project to check the operation of the installed Maven. If the Proxy settings are not completed correctly, an execution error will occur and a large number of Errors will be displayed.

Creating a test project

Create a Maven project for operation verification. Name it test-app.

mvn archetype:generate
Creation example

Choose archetype:
1: internal -> org.apache.maven.archetypes:maven-archetype-archetype (An archetype which contains a sample archetype.)
2: internal -> org.apache.maven.archetypes:maven-archetype-j2ee-simple (An archetype which contains a simplifed sample J2EE application.)
3: internal -> org.apache.maven.archetypes:maven-archetype-plugin (An archetype which contains a sample Maven plugin.)
4: internal -> org.apache.maven.archetypes:maven-archetype-plugin-site (An archetype which contains a sample Maven plugin site.
      This archetype can be layered upon an existing Maven plugin project.)
5: internal -> org.apache.maven.archetypes:maven-archetype-portlet (An archetype which contains a sample JSR-268 Portlet.)
6: internal -> org.apache.maven.archetypes:maven-archetype-profiles ()
7: internal -> org.apache.maven.archetypes:maven-archetype-quickstart (An archetype which contains a sample Maven project.)
8: internal -> org.apache.maven.archetypes:maven-archetype-site (An archetype which contains a sample Maven site which demonstrates
      some of the supported document types like APT, XDoc, and FML and demonstrates how
      to i18n your site. This archetype can be layered upon an existing Maven project.)
9: internal -> org.apache.maven.archetypes:maven-archetype-site-simple (An archetype which contains a sample Maven site.)
10: internal -> org.apache.maven.archetypes:maven-archetype-webapp (An archetype which contains a sample Maven Webapp project.)
Choose a number or apply filter (format: [groupId:]artifactId, case sensitive contains): 7:[Enter with default]
Downloading: https://repo.maven.apache.org/maven2/org/apache/maven/archetypes/maven-archetype-quickstart/1.1/maven-archetype-quickstart-1.1.pom
Downloaded: https://repo.maven.apache.org/maven2/org/apache/maven/archetypes/maven-archetype-quickstart/1.1/maven-archetype-quickstart-1.1.pom (2 KB at 2.4 
KB/sec)
Downloading: https://repo.maven.apache.org/maven2/org/apache/maven/archetypes/maven-archetype-bundles/4/maven-archetype-bundles-4.pom
Downloaded: https://repo.maven.apache.org/maven2/org/apache/maven/archetypes/maven-archetype-bundles/4/maven-archetype-bundles-4.pom (4 KB at 4.1 KB/sec)
Downloading: https://repo.maven.apache.org/maven2/org/apache/maven/archetype/maven-archetype/2.0-alpha-5/maven-archetype-2.0-alpha-5.pom
Downloaded: https://repo.maven.apache.org/maven2/org/apache/maven/archetype/maven-archetype/2.0-alpha-5/maven-archetype-2.0-alpha-5.pom (9 KB at 32.5 KB/sec)
Downloading: https://repo.maven.apache.org/maven2/org/apache/maven/maven-parent/16/maven-parent-16.pom
Downloaded: https://repo.maven.apache.org/maven2/org/apache/maven/maven-parent/16/maven-parent-16.pom (23 KB at 45.1 KB/sec)
Downloading: https://repo.maven.apache.org/maven2/org/apache/maven/archetypes/maven-archetype-quickstart/1.1/maven-archetype-quickstart-1.1.jar
Downloaded: https://repo.maven.apache.org/maven2/org/apache/maven/archetypes/maven-archetype-quickstart/1.1/maven-archetype-quickstart-1.1.jar (7 KB at 23.9 KB/sec)
Define value for property 'groupId': com.test
Define value for property 'artifactId': test-app
Define value for property 'version' 1.0-SNAPSHOT: :[Enter with default]
Define value for property 'package' com.test: :[Enter with default]
Confirm properties configuration:
groupId: com.test
artifactId: test-app
version: 1.0-SNAPSHOT
package: com.test
 Y: : y
[INFO] ----------------------------------------------------------------------------
[INFO] Using following parameters for creating project from Old (1.x) Archetype: maven-archetype-quickstart:1.1
[INFO] ----------------------------------------------------------------------------
[INFO] Parameter: basedir, Value: /home/user
[INFO] Parameter: package, Value: com.test
[INFO] Parameter: groupId, Value: com.test
[INFO] Parameter: artifactId, Value: test-app
[INFO] Parameter: packageName, Value: com.test
[INFO] Parameter: version, Value: 1.0-SNAPSHOT
[INFO] project created from Old (1.x) Archetype in dir: /home/user/test-app
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 01:15 min
[INFO] Finished at: 2020-03-19T09:24:46+09:00
[INFO] Final Memory: 19M/64M
[INFO] ------------------------------------------------------------------------

Reference: What to do if you cannot download from an external Maven repository server when running Maven in-house

Summary

The OSS I wanted to try was implemented in Java and was distributed in the state of the Maven project, so I installed Maven, but as expected, it was blocked by the in-house Proxy and the build did not remain at first. Since the settings related to Proxy differ depending on the application, I thought that it is necessary to keep a memo as soon as it is resolved when it collides.

Reference [Introduction to Java build tools Maven / Gradle / SBT / Bazel support (written by Tsuyano Palma; Shuwa System; 2017)](https://www.amazon.co.jp/Java80-Maven-Gradle-SBT-Bazel9C- ebook / dp / B079Z1PG6C / ref = tmm_kin_swatch_0? _encoding = UTF8 & qid = 1567397583 & sr = 8-1) https://www.codeflow.site/ja/article/maven__how-to-install-maven-in-ubuntu

Recommended Posts

A memorandum when running Apache Maven on an in-house proxy
Build a Maven in-house repository on Google Cloud Storage
When Maven is blocked by a company proxy and doesn't work
[Rejected] A memorandum because an error occurred during deployment on Heroku
Link Apache and Tomcat in a blink of an eye on CentOS 8
[Unauthorized Operation] A memorandum because an error occurred when creating an EC2 instance.
A memorandum when IME cannot be turned on with VS Code (Ubuntu 20.04)
A memorandum on how to use Eclipse
Build a Maven repository on AWS S3
Relative path when running tomcat on eclipse
A reminder when an aapt.exe error occurs
A memorandum when building an environment with Ruby3.0 x Rails6.1 x Docker x CentOS Stream