How to launch a Java vertx service from fatjar?

891 views
Skip to first unread message

Ian Lewis

unread,
Jun 17, 2016, 6:28:13 AM6/17/16
to vert.x

I'm trying to understand the simplest way of using a single fatjar for my production system, but still allowing verticles from that jar to be launched separately from the command line in addition to whatever was specified in the 'Main-Verticle' Maven config.

I.e. I'm ok with running the basic system with the following command which launches the verticle specified "Main-Verticle" which in my case then spawns a few other verticles:

java -jar target/my-fat-jar.jar -cluster -cluster-port 10000 -conf com.xx.my-conf.json

But, when the core system is running, I'd like to be able to launch/kill other verticles from within the same jar from the command line which might not have been launched at the initial startup, e.g. something like

java -jar target/my-fat-jar.jar com.xx.my-verticle -cluster -cluster-port 10000 -conf com.xx.my-service-conf.json

My challenge is the vertx/jar approach seems designed to be hardcoded with the name of a single 'main' verticle, and I do know I could implement my own dispatcher that accepts a config and launches any verticle in the jar, but I would seem to be rewriting vertx.io.Launcher at that point.

An example of another verticle I might want to run in addition to the main system is my application-specific 'Console' verticle, which itself takes a vertx json config file to tell it what to monitor.  I can launch  a 'service' configuration of this verticle fine using

vertx run "service:com.me.xx.console.cambridge" -cluster -cluster-port 10001

but on the PRODUCTION system I'd like to allow the same but from the fatjar if possible.

Hopefully this is fairly simple, any advice appreciated. I've been looking at things such as running "io.vertx.Launcher" from the fatjar and giving it the 'service' config of my verticle, but the "Main-Verticle" is still launched, not the one specified in the 'service format' json config file.


Ian Lewis

unread,
Jun 17, 2016, 7:32:18 AM6/17/16
to vert.x
As an update, and I'm in scarily trial-and-error mode here, the following seems to do the job:

java -cp target/my-SNAPSHOT-fat.jar io.vertx.core.Launcher run "service:com.me.xx.my-service"

Seem ok to anyone that knows better than me?

Clement Escoffier

unread,
Jun 17, 2016, 9:09:00 AM6/17/16
to ve...@googlegroups.com
Hi,

It’s how it’s intended to work :-)

“service:your-service” triggers the Service verticle factory, that loads the service identified by “your-service” and deploy the main verticle.

You can also build a fat jar with Main-Verticle set to service:your-service, and then launch it using:

java -jar your-fat-jar.jar

I’ve opened https://github.com/vert-x3/vertx-service-factory/issues/8 to extend the manual.


Clement

--
You received this message because you are subscribed to the Google Groups "vert.x" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vertx+un...@googlegroups.com.
Visit this group at https://groups.google.com/group/vertx.
To view this discussion on the web, visit https://groups.google.com/d/msgid/vertx/2c12d6e7-bfb9-40b1-940b-838042127d9b%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Jez P

unread,
Jun 17, 2016, 9:21:57 AM6/17/16
to vert.x
Doesn't vertx-shell offer the ability to do effective command-line deployment via ssh connection as well?

Ian Lewis

unread,
Jun 17, 2016, 11:00:40 AM6/17/16
to vert.x
Awesome, thanks.

That's really useful for scripted startup of a variety of configurations on the production server.

Clement Escoffier

unread,
Jun 17, 2016, 2:35:29 PM6/17/16
to ve...@googlegroups.com
On 17 juin 2016, at 15:21, Jez P <mr.n...@gmail.com> wrote:

Doesn't vertx-shell offer the ability to do effective command-line deployment via ssh connection as well?

Yes it does. You can deploy verticles using vertx shell.

Clement

Reply all
Reply to author
Forward
0 new messages