我有一個基於Maven的Vert-x應用程序,它包含一個Java Verticle。目前,我開始與應用:選擇Verticle名稱以從Maven shell開始
java -jar jarfile.jar
現在我需要另一個Verticle添加到項目中。如何選擇以Maven開頭的Verticle? 謝謝
我有一個基於Maven的Vert-x應用程序,它包含一個Java Verticle。目前,我開始與應用:選擇Verticle名稱以從Maven shell開始
java -jar jarfile.jar
現在我需要另一個Verticle添加到項目中。如何選擇以Maven開頭的Verticle? 謝謝
在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>
我希望這將幫助你:)
既然你似乎是使用發牛逼罐子,你是最有可能使用Vertx啓動
http://vertx.io/docs/vertx-core/java/#_the_vert_x_launcher
,它允許您定義主verticle運行
感謝,並表示歉意的acknoledgement晚 – Carla
我很高興我能幫助:) – Flash