Closed CameronHudson8 closed 5 years ago
do you mean that the config retriever should look at the classpath for the config file ?
what do you think @cescoffier ?
do you mean that the config retriever should look at the classpath for the config file ?
Perhaps. To be honest, I don't understand how Java maps resources and classpaths into the jar when packaging. However, reading a resource file packaged in a jar can be done with Thread.currentThread().getContextClassLoader().getResourceAsStream(String filepath)
.
actually it is possible if you don't use the default path and configure it from System property vertx-config-path. So setting the system property vertx-config-path to conf/config.json should work. I'll contribute so it works in the general case.
Actually, I've since found that I get the aforementioned WARNING
and hanging of the application whenever ConfigRetriever.getConfig
is called inside a jar, regardless of whether the conf/config.json
file is present at src/main/resources
, ./
, located elsewhere, or absent.
Things I've tried:
java -jar target/my-app.jar -conf src/main/resources/conf/config.json
, but got the same WARNING
and application hang. conf/config.json
to the root directory, so that the conf
directory is a sibling to src
. While this also loads successfully when unpackaged, it also results in a WARNING
and hang when run by java -jar target/my-app.jar -conf conf/config.json
.conf/config.json
and conf
completely, and running the jar as java -jar target/my-app.jar
(without the -conf
) flag, and it also results in the same WARNING
and hang.Now I'm wondering if this is perhaps a bug, or if there's something else wrong with my setup.
can you have a try with the contribution ?
I have to go to class now, but I will try that later today. Thanks for the quick update!
Here are the resulting logs. There are warnings about the thread being blocked. Although the reported config path is different from before, ConfigurationProvider.get
still emits WARNING: Unable to process the retrieve the configuration null
and the application hangs.
CCamerons-Air:webservice cameronhudson$ java -jar target/webservice-1.0.0-SNAPSHOT.jar
Oct 14, 2019 9:17:18 AM io.vertx.config.impl.ConfigRetrieverImpl
INFO: Config file path: /var/folders/dr/j_n16l813t396y_jm6pcfqsm0000gn/T/vertx-cache/file-cache-1adc87a8-db9c-4651-8af4-4e2e9be1c995/conf/config.json, format:json
Oct 14, 2019 9:17:21 AM io.vertx.core.impl.BlockedThreadChecker
WARNING: Thread Thread[vert.x-eventloop-thread-0,5,main]=Thread[vert.x-eventloop-thread-0,5,main] has been blocked for 2737 ms, time limit is 2000 ms
Oct 14, 2019 9:17:22 AM io.vertx.core.impl.BlockedThreadChecker
WARNING: Thread Thread[vert.x-eventloop-thread-0,5,main]=Thread[vert.x-eventloop-thread-0,5,main] has been blocked for 3737 ms, time limit is 2000 ms
Oct 14, 2019 9:17:23 AM io.vertx.core.impl.BlockedThreadChecker
WARNING: Thread Thread[vert.x-eventloop-thread-0,5,main]=Thread[vert.x-eventloop-thread-0,5,main] has been blocked for 4742 ms, time limit is 2000 ms
Oct 14, 2019 9:17:24 AM edu.cmu.dramaticstorm.App lambda$null$1
INFO: Listening on port 8080.
Oct 14, 2019 9:17:24 AM io.vertx.core.impl.launcher.commands.VertxIsolatedDeployer
INFO: Succeeded in deploying verticle
# HTTP requests that do not involve ConfigRetriever.getConfig work fine here.
# Sending an HTTP request that involves ConfigRetriever results in:
Oct 14, 2019 9:19:02 AM io.vertx.config.impl.ConfigRetrieverImpl
INFO: Config file path: /var/folders/dr/j_n16l813t396y_jm6pcfqsm0000gn/T/vertx-cache/file-cache-1adc87a8-db9c-4651-8af4-4e2e9be1c995/conf/config.json, format:json
Oct 14, 2019 9:19:02 AM ConfigurationProvider#io.vertx.config.impl.spi.FileConfigStore@bc8b4f7
WARNING: Unable to process the retrieve the configuration null
The issue happens because the result of getFile()
once inside the jar looks like
/some/external/path/yourjar.jar!/conf/config.json
and Java doesn't deal with the !
This is a feature request.
Although locating the configuration at
src/main/resources/conf/config.json
, allows the configuration to be read before packaging, the configuration cannot be read after packaging.When reading of the configuration is attempted after packaging, it results in
And the application hangs.