** This page is unfinished **: cold_sweat:
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.
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/).
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 |
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.
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 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.
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.
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 the
Propertiestab --Open the third page with page navigation --Change the following values and click the
Save` button
--security.policy.password.expiration.days: Enter expiration date in days
--security.policy.password.expiration.enabled: Enter false if no expiration date
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.
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.
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`.
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 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.
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
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.)
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:
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
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 as described in README.adoc.
$ cd start.spring.io
$ ./mvnw clean install
It will take some time, so wait patiently.
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.)
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.
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.
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.)
Window
→ Preferences
to open the settings screen.Spring
→ Boot
→ ʻInitializr`.,
Removethe default
https://start.spring.io and use
New` to add the URL of the Initializr for your target environment.If you can make changes as shown in the screen example, click ʻApply and Close`.
Right-click in an empty area of Package Explorer
→ New
→ Spring Starter Poject
.
You can perform the same work as the Internet connection environment with the URL set as follows.
Recommended Posts