We will build a Spring Framework development environment in the on-premises environment.

** This page is unfinished **: cold_sweat:

Introduction

It is a story about building the development environment of Spring Framework, which is a Java-based application framework, into an on-premises environment that cannot connect to the Internet.

The following themes will be broadly covered.

--Building Maven repository server -Build a mirror of Spring Initializr

The command example is written based on Linux, so replace / in the path delimiter as appropriate for your environment.

Necessary knowledge, etc.

Build Maven repository server

You can distribute a Maven local repository that caches Spring Framework dependent libraries (such as the .m2 directory in your home directory), but I would like to build a Maven repository server for maintainability.

As a repository manager for Maven, Nexus (Professional Edition of Sonatype, which is also officially used. repository), OSS Edition) seems to be famous, but considering the resources required and ease of construction, [Apache Archiva]( I would like to use https://archiva.apache.org/).

Required environment

item Description
JDK 1.8
Disk space When deploying Apache Archiva, it is about 80 Mbytes, but when actually caching the repository, it is better to reserve it in Gbytes.
OS Linux、Mac OS、Solaris、Windows

2020/5/1 postscript

In the following procedure, it says "Deploy to an environment that can connect to the Internet." However, in an environment that can connect to the Internet, use Maven directly without using Apache Achiva and download it to local ~ / .m2. , ~ / .M2 / repository It was pointed out that the contents should be copied to apache-archiva-2.2.4 / repositories / internal in the target environment by some means.

Download Apache Archiva

You can download it from https://archiva.apache.org/download.html.

You can choose between the standalone version (tar.gz or zip) that includes Tomcat and the WAR version.

If you have a Java application server such as Tomcat that is already running, it seems better to use the WAR version, but you need to create a configuration file and deploy dependent libraries. See the links below for more information.

Here, we chose the standalone version, which is easy to build.

Deploy Apache Archiva

Deploy not only to your target on-premises environment, but also to an environment where you can connect to the Internet to migrate the contents of your repository to your target environment. Follow the steps below for each environment.

First, unzip the archive. Considering that the directory hierarchy of the repository will be deep, in the case of Windows, it is better to expand it to the shallowest possible hierarchy such as directly under the drive.

The following is an example of unzipping the zip version with the unzip command. (The version number is at the time of posting.)

$ unzip apache-archiva-2.2.4-bin.zip

After deployment, start Apache Archiva.

$ cd apache-archiva-2.2.4/bin
$ ./archiva console

Please refer to the following document as the method of making it a service differs depending on the environment.

It's in English, but if you know the title and the command execution example, I think it will be possible.

Once Apache Archiva is launched, access http: // localhost: 8080 / in your web browser. If the following screen is displayed, it is OK.

archiva.png

Creating an admin user

Click the red button labeled Create Admin User near the top right of the Apache Archiva web interface. A form for creating an administrator user will be displayed. Enter the following required items.

--Password: Enter your password. --Confirm Password: Enter the same password as above for confirmation. --Email Address: Even if you do not use email, you can use a dummy, so enter an email address-like character string.

Click the Save button when you are done.

Password expiration date

By default, the password expiration date is set to 90 days. If you want to change this setting, do the following:

--From the menu on the left side, click ʻUsers Runtime Configuration --Open thePropertiestab --Open the third page with page navigation --Change the following values and click theSave` button --security.policy.password.expiration.days: Enter expiration date in days --security.policy.password.expiration.enabled: Enter false if no expiration date

Settings to get artifacts (libraries) from Apache Archiva

Place a file called settings.xml in a directory called .m2 in your home directory with the following contents. (Change the localhost part to an appropriate host name.)

settings.xml


<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
	https://maven.apache.org/xsd/settings-1.0.0.xsd">
  <localRepository/>
  <interactiveMode/>
  <offline/>
  <pluginGroups/>
  <servers/>
  <mirrors>
    <mirror>
      <id>archiva.default</id>
      <url>http://localhost:8080/repository/internal/</url>
      <mirrorOf>external:*</mirrorOf>
    </mirror>
  </mirrors>
  <proxies/>
  <profiles/>
  <activeProfiles/>
</settings>

By default, only Maven Central is set as the remote repository. If you want to use other repositories as well, please refer to the links below.

Get the required artifacts (libraries)

In an environment where you can connect to the Internet, use the mvn command as usual in the Maven project. Run the Goal or Phase you normally use. (For Spring Boot projects, you can use the included mvnw.)

$ ./mvn spring-boot:run
$ mvn clean
$ mvn package
$ mvn test

Make sure that it is downloaded from the host set above.

The Spring Tool Suite (Spring Tools for Eclipse) also uses the above settings.

Copy the repository to the target environment and update the index

apache-archiva-2.2.4 / repositories / internal Copy the following to apache-archiva-2.2.4 / repositories / internal in the target environment by some means.

Log in to the Apache Archiva web interface, select Repositories from the menu on the left side, and select Directorories Scanning from the drop-down list labeled ʻAction`.

dir_scan.png

It will take a while, so after a while, select Browse from the menu on the left side and check if the copied directory etc. is displayed.


Build a mirror of Spring Initializr

Build a mirror of the Spring Initializr (https://start.spring.io/) that can generate a template for your Spring Boot application.

If you write pom.xml by yourself or know the necessary file structure, you probably don't need it, but Spring Boot is halved (overstated?), And Spring Tool Suite (Spring Tools for Eclipse). We will build it in consideration of the affinity with.

: warning: The following work is performed in an environment where you can connect to the Internet unless otherwise specified. Also, if the above settings are made via Apache Archiva, the required libraries cannot be obtained, so cancel the settings once. (Client side)

: notebook_with_decorative_cover: I've been working on CentOS 8.1 on Virtual Box with a 20GB hard disk, but while I'm trying various things, I'm getting a lot of / tmp usage and the build fails. did. Clean the inside of / tmp as appropriate.

Clone start.spring.io

The Spring Initializr Source (https://github.com/spring-io/start.spring.io) is maintained on GitHub. Clone as follows.

$ git clone https://github.com/spring-io/start.spring.io.git

Modification of application.yml (Fixed bootVersions on 2020/05/30)

If you package the cloned project as it is, the version of Spring Boot that can be selected as follows when booting in an environment where you cannot connect to the Internet will be different from the original version. (Because metadata cannot be obtained from https://spring.io/project_metadata/spring-boot.)

no_internet.png

Modify the bootVersions section of start.spring.io/start-site/src/main/resources/application.yml. In my case, I don't need the SNAPSHOT version, so I modified it as follows.

index 25dc9cb..2cd2e56 100644
--- a/start-site/src/main/resources/application.yml
+++ b/start-site/src/main/resources/application.yml
@@ -1431,12 +1432,17 @@ initializr:
       id: groovy
       default: false
   bootVersions:
-    - name : Latest SNAPSHOT
-      id: 2.2.0.BUILD-SNAPSHOT
-      default: false
-    - name : 2.1.1.
-      id: 2.1.1.RELEASE
+    - name : 2.3.0
+      id: 2.3.0.RELEASE
       default: true
+    - name : 2.2.7
+      id: 2.2.7.RELEASE
+      default: false
+    - name : 2.1.14
+      id: 2.1.14.RELEASE
+      default: false
 
 ---
 

: warning: It is necessary to modify to make sure that there is one default: true. If all are set to false, the screen will be displayed for a moment and then it will be blank. (Experienced people talk): warning:

You can also change the default value of Group, com.example, to jp.co.example by adding the group-id section after the bootVersions section as shown below. ..

  group-id:
    value: jp.co.example

: warning: Match the indent to bootVersions. : warning:

2020/05/29 Addendum: Do not go to the original site to get metadata

It is described only in Old Reference Manual, but ʻinitializr.env.springBootMetadataUrl` is empty or If you make it null, you won't be going to get the metadata at home.

--- a/start-site/src/main/resources/application.yml
+++ b/start-site/src/main/resources/application.yml
@@ -24,6 +24,7 @@ spring:
 
 initializr:
   env:
+    springBootMetadataUrl: ""
     boms:
       azure:
         groupId: com.microsoft.azure

reference

You can set initializr.env.springBootMetadataUrl to empty (or null), or to a location that you know will resolve correctly.

	@Override
	public InitializrMetadata update(InitializrMetadata current) {
		String url = current.getConfiguration().getEnv().getSpringBootMetadataUrl();
		List<DefaultMetadataElement> bootVersions = fetchSpringBootVersions(url);
		if (bootVersions != null && !bootVersions.isEmpty()) {
			if (bootVersions.stream().noneMatch(DefaultMetadataElement::isDefault)) {
				// No default specified
				bootVersions.get(0).setDefault(true);
			}
			current.updateSpringBootVersions(bootVersions);
		}
		return current;
	}
		private String springBootMetadataUrl = "https://spring.io/project_metadata/spring-boot";
/* (Omission) */
		public String getSpringBootMetadataUrl() {
			return this.springBootMetadataUrl;
		}

Build

Build as described in README.adoc.

$ cd start.spring.io
$ ./mvnw clean install

It will take some time, so wait patiently.

Operation check

When the build finishes without any problems, try starting it. If possible, it's a good idea to test without an internet connection.

$ cd start-site
$ ../mvnw spring-boot:run

Once started, access http: // localhost: 8080 / with a web browser. (If you have run other services with the same address in the past, please update.)

change_group.png

The design differs depending on the width of the screen, but I think it can be displayed as above. Make changes to ʻArtifact, add Dependencies, and verify that ʻExplore and Generate work.

Packaging

If all goes well with the above, package it. Connect to the internet and execute the following command.

$ ../mvnw package

This also takes time to test, so please wait patiently.

Successful packaging will generate a file called start-site-exec.jar in the target directory.

Deploy to target environment

Place start-site-exec.jar in the target environment in some way. Start with the following command.

$ java -jar start-site-exec.jar

If you want to change the default listen port 8080, add --server.port = port number at the end. The following example boots with the port number changed to 3000.

$ java -jar start-site-exec.jar --server.port=3000

: notepad_spiral: If you want to start it as a service, please refer to the link below.

-Spring Boot application as a service (It may be difficult to read because it looks like machine translation.)

Use from Spring Tool Suite

Initializr settings

  1. From the menu, select Window Preferences to open the settings screen.
  2. From the category on the left, select Spring Boot → ʻInitializr`.
  3. From ʻInitializr URLs, Removethe defaulthttps://start.spring.io and use New` to add the URL of the Initializr for your target environment.

sts_settings.png

If you can make changes as shown in the screen example, click ʻApply and Close`.

Creating a Spring Starter Project

Right-click in an empty area of Package Explorer NewSpring Starter Poject.

You can perform the same work as the Internet connection environment with the URL set as follows.

New_Spring_Starter_Project.png

Reference link

Recommended Posts

We will build a Spring Framework development environment in the on-premises environment.
We will build a Spring Framework development environment in the on-premises environment.
Build a browser test environment using Capybara in the Docker development environment
Addressing an issue that caused an AlreadyBuiltException in Spring Security
I implemented an OAuth client with Spring Boot / Security (LINE login)
We will build a Spring Framework development environment in the on-premises environment.
Build a "Spring Thorough Introduction" development environment with IntelliJ IDEA
Install Rails in the development environment and create a new application
Building a Lambda development environment in Eclipse
Build a PureScript development environment with Docker
Build a Java development environment on Mac
Build a simple Docker + Django development environment
I tried to build a Firebase application development environment with Docker in 2020
Build a development environment for Docker + Rails6 + Postgresql
Build a WordPress development environment quickly with Docker
Build a simple Docker Compose + Django development environment
[Win10] Build a JSF development environment with NetBeans
Build a development environment for Docker, java, vscode
Create a Spring Boot development environment with docker
Build a Java development environment with VS Code
Install Ubuntu 20.04 in virtual box on windows10 and build a development environment using docker
Build a Ruby on Rails development environment on AWS Cloud9
Build Docker + Laravel PHP + Vue.js development environment in 5 minutes
[Note] Build a Python3 environment with Docker in EC2
A review note of the Spring Framework Resource interface
[Environment construction] Build a Java development environment with VS Code!
Try to build a Java development environment using Docker
A record of studying the Spring Framework from scratch
Spring Boot 1.x will reach EOL in the next year.
Easily monitor the indoor environment-⑦ Summarize in a simple tool-
Introducing Spring Boot2, a Java framework for web development (for beginners)
Build WebAPP development environment with Java + Spring with Visual Studio Code
Build Spring for Android 2.0.0 environment
Ruby ① Build a Windows environment
One file of Docker x Laravel threat! Build a local development environment with the minimum configuration
[Node.js] Docker-compose up makes it easy to build a development environment
Use MailHog for checking emails in the development environment (using Docker)
Get a proxy instance of the component itself in Spring Boot
Build a development environment where Ruby on Rails breakpoints work on Windows
How to install the language used in Ubuntu and how to build the environment
Build a development environment for Django + MySQL + nginx with Docker Compose
A story stuck with log output in Docker + Play framework environment
Steps to build a Ruby on Rails development environment with Vagrant
Coexistence of Flyway in the embedded database (h2) of the development environment and the release database (SQL Server) with Spring Boot
Build a Docker-based development environment on Windows 10 Home 2020 ver. Part 2 VS Code should make the Docker development environment comfortable
Spring Boot application development in Eclipse
Build a Node.js environment with Docker
Build a Tomcat 8.5 environment with Pleiades 4.8
Java Spring environment in vs Code
Play Framework 2.6 (Java) development environment creation
Create a database in a production environment
About the current development environment (Java 8)
Build Java development environment (for Mac)
Build a XAMPP environment on Ubuntu
Build jooby development environment with Eclipse
Build Unity development environment on docker
Create a Spring Boot app development project with the cURL + tar command
Build a hot reload development environment with Docker-compose using Realize of Go
[Copy and paste] Build a Laravel development environment with Docker Compose Part 2
How to build a Ruby on Rails development environment with Docker (Rails 6.x)
Build a local development environment for Rails tutorials with Docker (Rails 6 + PostgreSQL + Webpack)
[Copy and paste] Build a Laravel development environment with Docker Compose Participation
Build a development environment on AWS EC2 with CentOS7 + Nginx + pm2 + Nuxt.js