2017-08-20 27 views
0


我有一個基於Maven的Vert-x應用程序,它包含一個Java Verticle。目前,我開始與應用:選擇Verticle名稱以從Maven shell開始

java -jar jarfile.jar 

現在我需要另一個Verticle添加到項目中。如何選擇以Maven開頭的Verticle? 謝謝

回答

1

在Vertx中有一個DeploymentOptions,並且vertx提供了多個Verticles部署選項。

讓我們看看你有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中,你只需要定義上面的例子MainVerticle開始在樹蔭插件主類,所以部署其他Verticles

<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> 

我希望這將幫助你:)

+0

感謝,並表示歉意的acknoledgement晚 – Carla

+0

我很高興我能幫助:) – Flash