在springboot工程中打包制定main主类执行

Posted 健康平安的活着

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了在springboot工程中打包制定main主类执行相关的知识,希望对你有一定的参考价值。

一 在spt工程指定主类执行

1.pom文件的配置

<?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>

  <parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>2.4.2</version>
  </parent>

  <groupId>com.bonc.es</groupId>
  <artifactId>fan-create-es-db</artifactId>
  <version>1.0-SNAPSHOT</version>

  <name>fan-create-es-db</name>
  <!-- FIXME change it to the project's website -->
  <url>http://www.example.com</url>

  <properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <maven.compiler.source>1.8</maven.compiler.source>
    <maven.compiler.target>1.8</maven.compiler.target>
  </properties>

  <dependencies>
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>4.13</version>
      <scope>test</scope>
    </dependency>

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

    <!-- https://mvnrepository.com/artifact/org.elasticsearch/elasticsearch -->
    <dependency>
      <groupId>org.elasticsearch.client</groupId>
      <artifactId>transport</artifactId>
      <version>5.5.0</version>
    </dependency>
    <dependency>
      <groupId>org.elasticsearch</groupId>
      <artifactId>elasticsearch</artifactId>
      <version>2.3.5</version>
    </dependency>
    <dependency>
      <groupId>com.google.code.gson</groupId>
      <artifactId>gson</artifactId>
      <version>2.8.5</version>
    </dependency>
    <dependency>
      <groupId>net.sf.json-lib</groupId>
      <artifactId>json-lib</artifactId>
      <version>2.4</version>
      <classifier>jdk15</classifier>
    </dependency>
  </dependencies>

  <build>
    <plugins>
      <plugin>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-maven-plugin</artifactId>
        <version>1.3.5.RELEASE</version>
        <configuration>
          <mainClass>com.bonc.es.util.Test</mainClass>
        </configuration>
        <executions>
          <execution>
            <goals>
              <goal>repackage</goal>
            </goals>
          </execution>
        </executions>
      </plugin>
    </plugins>

  </build>
</project>

2.打包结果截图

 

以上是关于在springboot工程中打包制定main主类执行的主要内容,如果未能解决你的问题,请参考以下文章

Spring Boot 在命令行指定主类启动程序

maven 打包java项目(含web工程)指定Main类

将 Spring boot 项目打成可执行Jar包,及相关注意事项(main-class缺少 xsd重复打包依赖)

将 Spring boot 项目打成可执行Jar包,及相关注意事项(main-class缺少 xsd重复打包依赖)

将 Spring boot 项目打成可执行Jar包,及相关注意事项(main-class缺少 xsd重复打包依赖)

将 Spring boot 项目打成可执行Jar包,及相关注意事项(main-class缺少 xsd重复打包依赖)