Linux安装git和maven——拉取代码 --> mvn打包成jar包 --->运行jar包

本文详细介绍了在CentOS上安装Git和Maven3.8的过程,包括配置环境变量、阿里云仓库设置以及使用Maven打包和运行jar包,还提供了pom.xml文件示例。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

在这里插入图片描述

前言

我们知道最后的代码都是要运行在Linux系统中的,所以就需要在Linux中安装git,从而能够拉取代码,安装maven,从而能够进行项目的打包。

本篇博客以centos为例,介绍如何安装git,安装maven3.8,配置环境变量,并使用命令进行打包,然后运行jar包。

其他相关的maven和git的博客文章如下

引出


1.介绍如何安装git;
2.安装maven3.8,配置环境变量;
3.使用命令进行打包,然后运行jar包

Linux安装git

安装git

yum install -y git

在这里插入图片描述

然后就可以进行代码的克隆

git clone https://gitee.com/pet365/java-gc-demo

安装maven

1.查找版本

https://maven.apache.org/download.cgi

在这里插入图片描述

2.下载和解压

wget https://dlcdn.apache.org/maven/maven-3/3.8.8/binaries/apache-maven-3.8.8-bin.tar.gz

在这里插入图片描述

 tar -zxf apache-maven-3.8.8-bin.tar.gz

在这里插入图片描述

3.配置环境变量

/usr/local/software/maven/apache-maven-3.8.8

在这里插入图片描述

JAVA_HOME=/root/software/jdk/jdk1.8.0_371
CLASSPATH=.:$JAVA_HOME/lib
MAVEN_HOME=/usr/local/software/maven/apache-maven-3.8.8
PATH=$MAVEN_HOME/bin:$JAVA_HOME/bin:$PATH
export JAVA_HOME CLASSPATH MAVEN_HOME PATH

是配置生效

source /etc/profile

输入mvn -version查看安装版本

在这里插入图片描述

4.配置阿里云仓库

    <mirror>
        <id>aliyunmaven</id>
        <mirrorOf>central</mirrorOf>
        <name>阿里云公共仓库</name>
        <url>https://maven.aliyun.com/repository/public</url>
    </mirror>

在这里插入图片描述

5.先清理后打包

mvn clean package

在这里插入图片描述

运行jar包

 java -jar target/spring-gc-demo-1.0-SNAPSHOT.jar

在这里插入图片描述


总结

1.介绍如何安装git;
2.安装maven3.8,配置环境变量;
3.使用命令进行打包,然后运行jar包

附录:pom.xml文件

<?xml version="1.0" encoding="UTF-8"?>
<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.tianju</groupId>
    <artifactId>spring-gc-demo</artifactId>
    <version>1.0-SNAPSHOT</version>
    <packaging>jar</packaging>

    <properties>
        <maven.compiler.source>8</maven.compiler.source>
        <maven.compiler.target>8</maven.compiler.target>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <spring-boot.version>2.3.8.RELEASE</spring-boot.version>
    </properties>

    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        <dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
        </dependency>
    </dependencies>
    <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-dependencies</artifactId>
                <version>${spring-boot.version}</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
        </dependencies>
    </dependencyManagement>
    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <version>2.3.8.RELEASE</version>
                <executions>
                    <execution>
                        <goals>
                            <!--repackage 会从新打包应用,将所有的依赖项全部打包到一个jar包中-->
                            <goal>repackage</goal>
                        </goals>
                    </execution>
                </executions>
                <configuration>
                    <mainClass>com.tianju.GcApp</mainClass>
                </configuration>
            </plugin>
        </plugins>
    </build>


</project>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Arya's Blog

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值