首页 > 解决方案 > Bootique,正在运行的主要示例,服务器选项未显示

问题描述

我正在关注bootique.io的入门指南,我似乎遇到了一些可能与我的 maven 配置相关的内容,或者可能与 bootique.io 中最近未包含在入门指南中的更改有关的内容。

我创建了一个简单的 github 项目来遵循这里的指南(git clone 和 mvn 包,java -jar target/bootique-tryout-1-jar-with-dependencies.jar 运行)。

入门指南指出,在编译并运行 jar 之后,您应该会看到如下所示的选项列表:

NAME
      com.foo.Application

OPTIONS
      -c yaml_location, --config=yaml_location
           Specifies YAML config location, which can be a file path or a URL.

      -h, --help
           Prints this message.

      -H, --help-config
           Prints information about application modules and their configuration
           options.

      -s, --server
           Starts Jetty server.

但是,当我运行上述后续版本时,我会看到:

NAME
      bootique-tryout-1-jar-with-dependencies.jar

OPTIONS
      -c yaml_location, --config=yaml_location
           Specifies YAML config location, which can be a file path or a URL.

      -h, --help
           Prints this message.

      -H, --help-config
           Prints information about application modules and their configuration
           options.

注意缺少的-s, --server选项。我错过了什么(明显的?)东西?

标签: java

解决方案


啊,在论坛里翻了一下,我发现这是由于在处理由 maven-assembly-plugin 和 maven-shade-plugin 生成的组合 jar 时的一些 bootique 特定设置。

我删除了基于 maven-assembly-plugin 的 jar-with-dependencies 并将其替换为 maven-shade-plugin,配置如下:

        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-shade-plugin</artifactId>
            <version>3.1.1</version>
            <configuration>
                <createDependencyReducedPom>true</createDependencyReducedPom>
                <filters>
                    <filter>
                        <artifact>*:*</artifact>
                        <excludes>
                            <exclude>META-INF/*.SF</exclude>
                            <exclude>META-INF/*.DSA</exclude>
                            <exclude>META-INF/*.RSA</exclude>
                        </excludes>
                    </filter>
                </filters>
            </configuration>
            <executions>
                <execution>
                    <phase>package</phase>
                    <goals>
                        <goal>shade</goal>
                    </goals>
                    <configuration>
                        <transformers>
                            <transformer implementation="org.apache.maven.plugins.shade.resource.ServicesResourceTransformer" />
                            <transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
                                <mainClass>${main.class}</mainClass>
                            </transformer>
                        </transformers>
                    </configuration>
                </execution>
            </executions>
        </plugin>

当我现在mvn clean package尝试运行应用程序时,我看到了-s, --server预期的选项:

NAME
      bootique-tryout-1.jar

OPTIONS
      -c yaml_location, --config=yaml_location
           Specifies YAML config location, which can be a file path or a URL.

      -h, --help
           Prints this message.

      -H, --help-config
           Prints information about application modules and their configuration
           options.

      -s, --server
           Starts Jetty server.

我已经使用上述修复更新了我的示例项目。


推荐阅读