Based on Window, Docker, IDEA to install Nexus, create a private maven warehouse and upload jar packages to the private warehouse

Problem phenomenon:

Recently, a maven warehouse needs to be built on the window server in the project, so I learned this knowledge.


problem analysis:

1.  First start docker / docker desktop, here is an explanation based on the learning experience on docker desktop.

 

2. Cmd window input:

docker search nexus

 

3. Choose the first one, the one that uses the most people, and enter:

docker pull sonatype/nexus3

 

4. To view the downloaded image, enter:

docker images

 

5. Create the folder E:/nexus3/nexus-data locally, then create the container, configure the self-restart and mapping path and start, enter:

docker run -it -p 8081:8081 --restart=always -v E:/nexus3/nexus-data:/nexus-data/ sonatype/nexus3

 

6. Login server ip: 8081

 

7. Under the server E:\nexus3\nexus-data, there will be an  admin.password file, open it, and copy the content (no need to decode), copy the content to Password, and then fill in the Username with admin, log in After success, you will need to modify the password and initialize the configuration.

The translation means:

 

8. Generally, select  Enable anonymous access (enable anonymous access) .

End of configuration:

 

9. Create a private warehouse:

 

10. Modify the local maven configuration file settings.xml:

Add the following code to the servers tag:

<server> 
	<id>仓库名(如:thpower-bladex)</id> 
	<username>仓库账号(如admin)</username> 
	<password>仓库密码(如admin123)</password> 
</server> 

Save and close the settings.xml file.

11. Upload the .jar dependency package to the created private warehouse thpower-bladex:

11.1 First, add the following code to the pom file in the module that needs to upload the .jar package (all the jar packages of the project must be uploaded, you can add the following code in the pom.xml at the outermost layer of the project):

11.2 Open the Terminal window of IDEA and enter the following command:

mvn clean install deploy

If the following red letter is reported as an error :

xxx 401 Unauthorized -> 

It means that the service authentication error ( not authenticated, that is, not logged in ), it may be because the machine's maven environment has more than one version, please check whether the path configured by the MAVEN_HOME variable in the environment variable is the version used by IDEA , and adjust it to the same version Try again later, it should be fine.

If the following red letter is reported as an error:

It is because if the maven-jar-plugin plug-in is added to the plugin, maven will run the maven-jar-plugin plug-in twice, the first run is to package the jar of the current project, and the second run is to execute the settings set in the plugin jar, in this case, two jar packages with the same name will be generated , and the classifier attribute will be used here . classifier  is different from the name used to identify a jar packet classifier , the value of this attribute is added to the name of the project behind a jar.

Add the following code to the plugins tag in pom.xml:

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-jar-plugin</artifactId>
    <version>3.1.0</version>
    <executions>
        <execution>
            <id>service-jar</id>
            <phase>package</phase>
            <goals>
                <goal>jar</goal>
            </goals>
            <configuration>
                <classifier>bak</classifier> <!-- 生成deploy-0.0.1-SNAPSHOT-bak.jar -->
                <classesDirectory>${project.build.directory}/此处写入报错的project名/</classesDirectory>
            </configuration>
        </execution>
    </executions>
</plugin>

11.3  If the addition cannot be solved, it is probably due to the lack of necessary parameters in the packaging command . Remove the plug-ins added in the previous step , and then use the packaging tool that comes with IDEA, which is simple, convenient and fast:

11.4 Go to the nexus private warehouse to view the uploaded dependency packages:

Guess you like

Origin blog.csdn.net/weixin_42585386/article/details/113527138