【问题标题】:Maven spring-boot:run against compiled jarMaven spring-boot:针对已编译的 jar 运行
【发布时间】:2017-08-24 19:19:23
【问题描述】:

是否可以直接针对由于包目标而不是源而创建的 jar 文件运行 maven,特别是 spring-boot:run 目标?

我想这样做的原因是因为我想使用 spring boot Devtools(可悲的是如果您使用 Java -jar 运行应用程序,则不起作用)并且我也不想将应用程序的源代码放入容器中。

【问题讨论】:

    标签: java maven spring-boot


    【解决方案1】:

    classes 参数不是可选的(通常使用标准 Maven 项目结构推断),但您可以为其提供一个空目录,然后使用 folders 参数包含先前打包的 JAR。这是一个例子

    <plugin>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-maven-plugin</artifactId>
        <configuration>
            <mainClass>com.this.that.YourApplication</mainClass>
            <!-- any directory will do as long as (a) it exists and (b) it does not contain classes -->
            <classesDirectory>/tmp/</classesDirectory>
            <folders>
                <folder>
                    <!-- the address, relative to the plugin's workingDirectory, of the 'original' application JAR -->
                    tmp/lib/your-application.jar.original
                </folder>
            </folders>
        </configuration>
    </plugin>
    

    使用此配置,如果您使用-X 运行,您将看到由 Spring Boot 插件生成的 JVM 的类路径中的前两个条目是 (1) 您的应用程序 JAR 和 (2) 空类目录.例如:

    [DEBUG] Classpath for forked process: <full_path_removed>/tmp/lib/your-application.jar.original:/tmp:
    

    注意事项:

    • 您需要提供mainClass,因为您使用的原始 JAR 不包括 META-INF/MANIFEST.MF 中的 Main-Class 指令
    • 您需要引用“原始”JAR 而不是 Spring Boot 打包的 JAR,因为原始 JAR 是在其原始位置包含应用程序主类的那个(Spring Boot 打包的 JAR 重新定位它)。李>

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-01-26
      • 2018-10-03
      • 2019-07-22
      • 2021-06-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多