Skip to content
TheChatArchiveThe Chat Archive
gpt-3.5-turbo-0301· OpenAIAi2 WildChat-4.8M (AI2)

Flink 1.17 Springboot 打包

  1. User

    Flink 1.17 Springboot 打包

  2. Assistant

    要将Flink 1.17与Spring Boot应用程序一起打包,您需要使用插件和配置文件来将它们放在一起。

    首先,在您的Spring Boot应用程序中添加以下插件:

    <build>
       <plugins>
          <plugin>
             <groupId>org.springframework.boot</groupId>
             <artifactId>spring-boot-maven-plugin</artifactId>
             <version>2.5.3</version>
             <executions>
                <execution>
                   <goals>
                      <goal>repackage</goal>
                   </goals>
                </execution>
             </executions>
          </plugin>
       </plugins>
    </build>
    

    这将自动将Spring Boot应用程序打包成可运行的jar文件。

    接下来,在您的Flink项目中,将以下内容添加到pom.xml文件的部分:

    <build>
       <plugins>
          <plugin>
             <groupId>org.apache.maven.plugins</groupId>
             <artifactId>maven-assembly-plugin</artifactId>
             <version>3.3.0</version>
             <executions>
                <execution>
                   <id>assemble</id>
                   <phase>package</phase>
                   <goals>
                      <goal>single</goal>
                   </goals>
                   <configuration>
                      <archive>
                         <manifest>
                            <mainClass>您的SpringBoot主类</mainClass>
                         </manifest>
                      </archive>
                   </configuration>
                </execution>
             </executions>
          </plugin>
       </plugins>
    </build>
    

    最后,运行mvn clean package命令来构建Flink项目和Spring Boot应用程序的jar文件。将在目标文件夹中找到两个文件:您的Spring Boot应用程序的可运行jar文件和Flink项目的jar文件。

    您可以按以下顺序运行jar文件:

    1. 运行Spring Boot应用程序的可运行jar文件
    2. 在应用程序中运行Flink项目的jar文件:通过这种方式,您可以将Flink作为一个库运行,并从Spring Boot应用程序中访问它。

    例如,您可以将以下命令添加到运行时脚本中:

    java -jar 您的SpringBoot可运行jar文件 java -cp 您的Flink项目的jar文件 com.example.YourFlinkProgram

  3. User

    Failed to execute goal org.apache.maven.plugins:maven-assembly-plugin:3.3.0:single (assemble) on project ihs-flink-cdc: Error reading assemblies: No assembly descriptors found.

  4. Assistant

    这个错误通常表示maven-assembly-plugin没有找到配置文件。您需要在项目中添加一个assembly.xml文件,该文件描述如何构建jar包。

    在您的Flink项目的根目录中创建一个名为“assembly.xml”的文件,然后将以下示例内容添加到文件中:

    <assembly xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2
                            http://maven.apache.org/plugins/maven-assembly-plugin/schema/1.1.2/maven-assembly-plugin-1.1.2.xsd">
        <id>distribution</id>
        <formats>
            <format>jar</format>
        </formats>
        <includeBaseDirectory>false</includeBaseDirectory>
        <fileSets>
            <fileSet>
                <directory>${project.build.outputDirectory}</directory>
                <outputDirectory>/</outputDirectory>
                <includes>
                    <include>*.class</include>
                </includes>
            </fileSet>
            <fileSet>
                <directory>${project.basedir}</directory>
                <outputDirectory>/</outputDirectory>
                <includes>
                    <include>README.*</include>
                </includes>
            </fileSet>
        </fileSets>
        <dependencySets>
            <dependencySet>
                <useProjectArtifact>true</useProjectArtifact>
                <outputDirectory>/lib</outputDirectory>
                <excludes>
                    <exclude>junit:junit</exclude>
                </excludes>
            </dependencySet>
        </dependencySets>
        <repositories>
            <repository>
                <id>mvn-repo</id>
                <url>http://repo.maven.apache.org/maven2</url>
            </repository>
        </repositories>
    </assembly>
    

    然后,在您的Flink项目中的pom.xml中添加以下配置:

    <build>
        <plugins> 
            <plugin>
                <artifactId>maven-assembly-plugin</artifactId>
                <version>3.3.0</version>
                <executions>
                    <execution>
                        <id>assemble</id>
                        <phase>package</phase>
                        <goals>
                            <goal>single</goal>
                        </goals>
                    </execution>
                </executions>
                <configuration>
                    <descriptors>
                        <descriptor>assembly.xml</descriptor>
                    </descriptors>
                    <archive>
                        <manifest>
                            <mainClass>com.example.YourSpringBootApplication</mainClass>
                        </manifest>
                    </archive>
                </configuration>
            </plugin>
        </plugins>
    </build>
    

    这将告诉maven-assembly-plugin查找名为“assembly.xml”的配置文件并使用它来构建jar包。请确保将“com.example.YourSpringBootApplication”替换为您的Spring Boot应用程序的主类路径。

    现在,您可以运行mvn clean package来构建带有Flink和Spring Boot的可运行jar包。

  5. User

    Flink 1.17 Springboot 打包

  6. Assistant

    要将Flink 1.17与Spring Boot应用程序一起打包,您可以使用Maven插件和配置文件将它们放在一起。

    首先,在您的Spring Boot应用程序中添加以下插件:

    <build>
       <plugins>
          <plugin>
             <groupId>org.springframework.boot</groupId>
             <artifactId>spring-boot-maven-plugin</artifactId>
             <version>2.5.3</version>
             <executions>
                <execution>
                   <goals>
                      <goal>repackage</goal>
                   </goals>
                </execution>
             </executions>
          </plugin>
       </plugins>
    </build>
    

    这将自动将Spring Boot应用程序打包成可运行的jar文件。

    接下来,在您的Flink项目中,将以下内容添加到pom.xml文件的部分:

    <build>
       <plugins>
          <plugin>
             <groupId>org.apache.maven.plugins</groupId>
             <artifactId>maven-assembly-plugin</artifactId>
             <version>3.3.0</version>
             <executions>
                <execution>
                   <id>assemble</id>
                   <phase>package</phase>
                   <goals>
                      <goal>single</goal>
                   </goals>
                   <configuration>
                      <archive>
                         <manifest>
                            <mainClass>您的SpringBoot主类</mainClass>
                         </manifest>
                      </archive>
                      <descriptorRefs>
                         <descriptorRef>jar-with-dependencies</descriptorRef>
                      </descriptorRefs>
                   </configuration>
                </execution>
             </executions>
          </plugin>
       </plugins>
    </build>
    

    现在,运行mvn clean package命令来构建Flink项目和Spring Boot应用程序的可运行jar文件。将在目标文件夹中找到一个包含Flink和所有依赖项的jar文件和一个仅包含Spring Boot应用程序的可运行jar文件。

    您可以按以下顺序运行这两个文件:

    1. 运行Flink项目的jar文件:通过这种方式,您可以将Flink作为一个库运行,并从Spring Boot应用程序中访问它。

      java -cp 您的Flink项目的jar文件 com.example.YourFlinkProgram
      
    2. 运行Spring Boot应用程序的可运行jar文件

      java -jar 您的SpringBoot可运行jar文件
      

    请确保将“com.example.YourFlinkProgram”和“您的SpringBoot主类”替换为您的实际类路径。

Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.