Feng Yu
Feng Yu

Reputation: 1493

vertx run -cp option doesn't work

I have a question when I use vertx run.

My command is vertx run groovy:myModule -conf conf.json. But the dependencies are all in lib. I find the doc about add the classpath to vertx, just pass -cp to vertx run.

So I use vertx run groovy:myModule -conf conf.json -cp "lib/*", but it doesn't works, also throw unable to resolve class exception.

Then I read the vertx script, I find vertx will pass the CLASSPATH environment variable. So I try this way:

CLASSPATH="lib/*" vertx run groovy:myModule -conf conf.json

It works!

Why -cp is not work?

Upvotes: 3

Views: 2131

Answers (1)

Kevin Bayes
Kevin Bayes

Reputation: 846

If you have a look at the vertx script to add to the classpath you set the classpath property as you described above "CLASSPATH="lib/*".

This then gets used in the following line in the script:

CLASSPATH=${CLASSPATH}:${VERTX_HOME}/conf:${VERTX_HOME}/lib/*

Then the last line of the script then uses this variable to set the java -classpath property when starting vertx:

exec "$JAVACMD" \
"${JVM_OPTS[@]}" \
-Djava.util.logging.config.file=${VERTX_JUL_CONFIG:-${VERTX_HOME}/conf/logging.properties} \
-Dvertx.home=$VERTX_HOME\
-Dvertx.clusterManagerFactory=org.vertx.java.spi.cluster.impl.hazelcast.HazelcastClusterManagerFactory\
-classpath "$CLASSPATH" \
org.vertx.java.platform.impl.cli.Starter "$@"

This is the reason setting the variable works and using -cp does not work. You could alter the script to accept a -cp input, but that would require you to customize the script.

Upvotes: 1

Related Questions