vert-x3 / vertx-config

Vert.x Configuration Service
Apache License 2.0
54 stars 64 forks source link

Be able to load configuration after packaging as jar. #98

Closed CameronHudson8 closed 5 years ago

CameronHudson8 commented 5 years ago

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

Camerons-Air:webservice cameronhudson$ java -jar target/webservice-1.0.0-SNAPSHOT.jar 
Oct 13, 2019 3:26:20 PM io.vertx.config.impl.ConfigRetrieverImpl
INFO: Config file path: conf/config.json, format:json
Oct 13, 2019 3:26:21 PM edu.cmu.dramaticstorm.App lambda$null$1
INFO: Listening on port 8080. // This is my own logger call.
Oct 13, 2019 3:26:21 PM io.vertx.core.impl.launcher.commands.VertxIsolatedDeployer
INFO: Succeeded in deploying verticle
Oct 13, 2019 3:26:26 PM io.vertx.config.impl.ConfigRetrieverImpl
INFO: Config file path: conf/config.json, format:json
Oct 13, 2019 3:26:26 PM ConfigurationProvider#io.vertx.config.impl.spi.FileConfigStore@2e210e63
WARNING: Unable to process the retrieve the configuration null

And the application hangs.

vietj commented 5 years ago

do you mean that the config retriever should look at the classpath for the config file ?

vietj commented 5 years ago

what do you think @cescoffier ?

CameronHudson8 commented 5 years ago

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

vietj commented 5 years ago

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.

CameronHudson8 commented 5 years ago

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:

Now I'm wondering if this is perhaps a bug, or if there's something else wrong with my setup.

vietj commented 5 years ago

contributed https://github.com/vert-x3/vertx-config/issues/99

vietj commented 5 years ago

can you have a try with the contribution ?

CameronHudson8 commented 5 years ago

I have to go to class now, but I will try that later today. Thanks for the quick update!

CameronHudson8 commented 5 years ago

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
Stwissel commented 5 years ago

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 !