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>
相关推荐
牧羊人_myr3 分钟前
Maven核心功能与项目构建详解
java·maven
Maple_land15 分钟前
Linux进程第八讲——进程状态全景解析(二):从阻塞到消亡的完整生命周期
linux·运维·服务器·c++·centos
嵌入式分享16 分钟前
嵌入式分享#41:RK3576改UART波特率【精简版】
linux·嵌入式硬件·ubuntu·嵌入式
爱吃生蚝的于勒19 分钟前
【Linux】零基础学会Linux之权限
linux·运维·服务器·数据结构·git·算法·github
惜.己26 分钟前
linux中jenkins正常启动外部无法访问
linux·servlet·jenkins
Cyan_RA938 分钟前
Linux 远程Ubuntu服务器本地部署大模型 EmoLLM 中常见的问题及解决方案 万字详解
linux·运维·服务器·ubuntu·大模型·远程部署·emollm
minji...1 小时前
Linux相关工具vim/gcc/g++/gdb/cgdb的使用详解
linux·运维·服务器·c++·git·自动化·vim
web安全工具库1 小时前
Linux 高手进阶:Vim 核心模式与分屏操作详解
linux·运维·服务器·前端·数据库
egoist20231 小时前
[linux仓库]信号产生[进程信号·贰]
linux·键盘·系统调用·信号产生·软件条件
yunmi_1 小时前
安全框架 SpringSecurity 入门(超详细,IDEA2024)
java·spring boot·spring·junit·maven·mybatis·spring security