选择 Verticle 名称从 Maven 开始 shell

Choose Verticle name to start from Maven shell


我有一个基于 Maven 的 Vert-x 应用程序,其中包含一个 Java Verticle。目前我正在启动应用程序:

java -jar jarfile.jar

现在我需要在项目中添加另一个 Verticle。我如何选择从 Maven 开始的 Verticle? 谢谢

There is a DeploymentOptions in Vertx and vertx provides multiple Verticles deployment option.

假设您有 MainVerticle 和另一个 Verticle 作为 DemoVerticle:

 public class MainVerticle extends AbstractVerticle {

  @Override
  public void start(Future<Void> startFuture) throws Exception {
     vertx = this.getVertx(); 

     // you can configure deployment option

  final DeploymentOptions deployOptions1 = new DeploymentOptions();

  // using below way you can deploy multiple Verticles 
   vertx.deployVerticle(DemoVerticle.class.getName(), deployOptions1 , deployResult -> {
                if (deployResult.succeeded()) {
                    LOG.info(" [SUCCESS]  --> " + deployResult.result());
                } else {
                    LOG.error(" [ERROR] --> " + deployResult.cause());
                }
            });

  }
}

在pom.xml中你只需要在Shade插件中定义starting main class,所以在上面的例子中MainVerticle正在部署其他Verticle

 <build>
  .
  .
  .
<plugins>
        <!-- Shade plugin to assemble a runnable fat jar -->
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-shade-plugin</artifactId>
            <version>2.3</version>
            <executions>
                <execution>
                    <phase>package</phase>
                    <goals>
                        <goal>shade</goal>
                    </goals>
                    <configuration>
                        <transformers>
                            <transformer
                                implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
                                <manifestEntries>
                                    <Main-Class>${main.class}</Main-Class>
                                    <Main-Verticle>com.path-of-your-package.MainVerticle</Main-Verticle>
                                </manifestEntries>
                            </transformer>
                            <transformer
                                implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">
                                <resource>META-INF/services/io.vertx.core.spi.VerticleFactory</resource>
                            </transformer>
                            <transformer
                                implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">
                                <resource>META-INF/services/org.opensaml.core.config.Initializer</resource>
                            </transformer>
                        </transformers>
                        <artifactSet>
                        </artifactSet>
                        <filters>
                            <filter>
                                <artifact>*:*</artifact>
                                <excludes>
                                    <exclude>META-INF/*.SF</exclude>
                                    <exclude>META-INF/*.DSA</exclude>
                                    <exclude>META-INF/*.RSA</exclude>
                                </excludes>
                            </filter>
                        </filters>
                        <outputFile>${project.build.directory}/${project.artifactId}-${project.version}-fat.jar</outputFile>
                    </configuration>
                </execution>
            </executions>
        </plugin>

  .
  .
  .
  </build>

希望对您有所帮助:)

由于您似乎在使用 fat jar,因此您很可能在使用 Vertx Launcher

http://vertx.io/docs/vertx-core/java/#_the_vert_x_launcher

它允许您将主 Verticle 定义为 运行