代码之家  ›  专栏  ›  技术社区  ›  Carla

选择从Maven shell开始的垂直名称

  •  0
  • Carla  · 技术社区  · 8 年前


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

    java -jar jarfile.jar
    

    现在,我需要为该项目添加另一条垂直线。我如何选择从Maven开始的垂直线? 谢谢

    2 回复  |  直到 8 年前
        1
  •  1
  •   Shasha    8 年前

    Vertx中有一个DeploymentOptions,Vertx提供了多个垂直部署选项。

    让我们假设您有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插件中定义开始的main类,所以在上面的示例中,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>
    

    我希望这能帮助你:)

        2
  •  1
  •   JAV    8 年前

    因为您似乎在使用胖jar,所以最有可能使用的是Vertx启动器

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