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

前言

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

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

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

目录

引出


1.介绍如何安装git;

2.安装maven3.8,配置环境变量;

3.使用命令进行打包,然后运行jar包

Linux安装git

安装git

java 复制代码
yum install -y git

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

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

安装maven

1.查找版本

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

2.下载和解压

java 复制代码
wget https://dlcdn.apache.org/maven/maven-3/3.8.8/binaries/apache-maven-3.8.8-bin.tar.gz
java 复制代码
 tar -zxf apache-maven-3.8.8-bin.tar.gz

3.配置环境变量

java 复制代码
/usr/local/software/maven/apache-maven-3.8.8
java 复制代码
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

是配置生效

java 复制代码
source /etc/profile

输入mvn -version查看安装版本

4.配置阿里云仓库

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

5.先清理后打包

java 复制代码
mvn clean package

运行jar包

java 复制代码
 java -jar target/spring-gc-demo-1.0-SNAPSHOT.jar

总结

1.介绍如何安装git;

2.安装maven3.8,配置环境变量;

3.使用命令进行打包,然后运行jar包

附录:pom.xml文件

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>
相关推荐
StarShip11 分钟前
git commit --amend 之后,想要修改为git commit , 如何处理?
git
洋芋土豆13 分钟前
linux文件及目录管理和vim编辑
linux·vim
柳鲲鹏34 分钟前
RGB转换为NV12,查表式算法
linux·c语言·算法
程序猿(雷霆之王)38 分钟前
Linux——线程安全
linux·运维·服务器
wdfk_prog1 小时前
[Linux]学习笔记系列 -- [kernel][time]timer
linux·笔记·学习
fy zs1 小时前
linux下动静态库
linux
不做无法实现的梦~2 小时前
机载电脑部署安装px4环境详细教程
linux
特轮飞2 小时前
Linux网络协议ARP IGMP ICMP的理解
linux·运维·网络协议
DeeplyMind2 小时前
第10章:中断处理-6:Implementing a Handler
linux·驱动开发
jerryinwuhan2 小时前
Linux常用命令练习题
linux·运维·服务器