选择Verticle name从Maven shell开始

时间:2017-08-20 20:32:04

标签: vert.x


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

java -jar jarfile.jar

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

2 个答案:

答案 0 :(得分:1)

  

Vertx中有一个DeploymentOptions,而vertx提供了多个Verticle部署选项。

让我们考虑你有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插件中定义起始主类,所以在上面的例子中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>

我希望这会对你有所帮助:)

答案 1 :(得分:1)

由于您似乎使用的是胖罐,因此您最有可能使用Vertx Launcher

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

允许您定义要运行的主要Verticle