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>
相关推荐
顺风尿一寸3 小时前
Java Socket 内核之旅:从 SocketChannel.read() 到 tcp_recvmsg 与 epoll 的完整调用链路
linux
XIAOHEZIcode9 小时前
Ubuntu 终端美化全栈指南:Bash 到 Kitty 踩坑实录
linux·ubuntu·命令行
唐青枫11 小时前
别再只会用 cron:Linux systemd Timer 定时任务实战详解
linux
和你看星星1 天前
Git rerere:让重复冲突只解决一次
git
AlfredZhao2 天前
生产环境里,为什么不建议把普通端口直接暴露到公网?
linux·https·443·80
戴为沐3 天前
Linux内存扩容指南
linux
zylyehuo4 天前
Linux 彻底且安全地删除文件
linux
用户805533698034 天前
主线 U-Boot 上 RK3506:和闭源 rkbin 拔河的三个隐性契约
linux·嵌入式
用户034095297914 天前
linux fcitx 5 雾凇拼音 设置在中文输入法下仍然输入英文标点
linux
嘻嘻仙人5 天前
Ubuntu中 git上传自己的项目和二次上传一般流程
git·github