SpringBoot 打成 jar 包发布到服务器上

SpringBoot打成的jar包发布到服务器上

步骤

1. pom.xml文件中必须包含:

<packaging>jar</packaging>
<build>
    <plugins>
        <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
             <configuration>
                 <includeSystemScope>true</includeSystemScope>
                 <fork>true</fork>
             </configuration>
        </plugin>
    </plugins>
</build>

2.进入到项目目录下执行:mvn clean package,会在项目目录下目标文件夹中生成jar:

> E:\ProjectTest\modp-new:mvn clean package

3.然后,运行的jar包即可:

> E:\ProjectTest\modp-new:target/java -jar modp-0.0.1-SNAPSHOT.jar
或者
> E:\ProjectTest\modp-new\target:java -jar modp-0.0.1-SNAPSHOT.jar

遇到的问题

问题:执行mvn clean package时,本地引入的3个jar包无法打进去。

解决办法:需要在pom.xml文件中添加以下依赖:

<dependency>
    <groupId>com.mathworks.toolbox</groupId>
    <artifactId>javabuilder</artifactId>
    <version>1.0.0</version>
    <scope>system</scope>
    <systemPath>${project.basedir}/lib/javabuilder.jar</systemPath>
</dependency>

<dependency>
    <groupId>com.track</groupId>
    <artifactId>trackOfMultityObject</artifactId>
    <version>1.0.0</version>
    <scope>system</scope>
    <systemPath>${project.basedir}/lib/trackOfMultityObject.jar</systemPath>
</dependency>

<dependency>
    <groupId>com.track</groupId>
    <artifactId>cutVideoOfCertain</artifactId>
    <version>1.0.0</version>
    <scope>system</scope>
    <systemPath>${project.basedir}/lib/cutVideoOfCertain.jar</systemPath>
</dependency>

注意:版本必须配置,的groupId可以随便写。

再执行mvn clean package就成功打成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>
    
    <!--modp-0.0.1-SNAPSHOT.jar : jar 包名称-->
	<groupId>com.senglang</groupId>
	<artifactId>modp</artifactId>
	<version>0.0.1-SNAPSHOT</version>
	<packaging>jar</packaging>

	<name>modp</name>
	<description>Demo project for Spring Boot</description>

	<parent>
		<groupId>org.springframework.boot</groupId>
		<artifactId>spring-boot-starter-parent</artifactId>
		<version>2.0.5.RELEASE</version>
		<relativePath/> <!-- lookup parent from repository -->
	</parent>

	<properties>
		<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
		<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
		<java.version>1.8</java.version>
	</properties>

    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-devtools</artifactId>
            <optional>true</optional>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-jpa</artifactId>
        </dependency>

        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <scope>runtime</scope>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-aop</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
            <version>2.0.1.RELEASE</version>
        </dependency>

        <!--引入本地的 jar 包-->
        <dependency>
            <groupId>com.mathworks.toolbox</groupId>
            <artifactId>javabuilder</artifactId>
            <version>1.0.0</version>
            <scope>system</scope>
            <systemPath>${project.basedir}/lib/javabuilder.jar</systemPath>
        </dependency>

        <dependency>
            <groupId>com.track</groupId>
            <artifactId>trackOfMultityObject</artifactId>
            <version>1.0.0</version>
            <scope>system</scope>
            <systemPath>${project.basedir}/lib/trackOfMultityObject.jar</systemPath>
        </dependency>

        <dependency>
            <groupId>com.track</groupId>
            <artifactId>cutVideoOfCertain</artifactId>
            <version>1.0.0</version>
            <scope>system</scope>
            <systemPath>${project.basedir}/lib/cutVideoOfCertain.jar</systemPath>
        </dependency>
    </dependencies>

    <build>
		<plugins>
			<plugin>
				<groupId>org.springframework.boot</groupId>
				<artifactId>spring-boot-maven-plugin</artifactId>
                <configuration>
                    <includeSystemScope>true</includeSystemScope>
                    <fork>true</fork>
                </configuration>
			</plugin>
		</plugins>
	</build>
</project>
扫描二维码关注公众号,回复: 3635233 查看本文章

猜你喜欢

转载自blog.csdn.net/m0_37857690/article/details/83149905