我试图使VertX Mertrics在通过exec:java Maven插件运行时工作。
当我将应用程序打包到fatjar中并使用java -jar fat.jar -conf config.json -Dvertx.metrics.options.enabled=true运行时,所有这些都可以正常工作。
当我使用mvn clean package exec:java -DskipTests运行它时,我看到:2016-03-22 18:39:58.833 WARN i.v.c.i.VertxImpl:348 - Metrics has been set to enabled but no VertxMetricsFactory found on classpath
我尝试了几种方法:
io.vertx:vertx-dropwizard-metrics:3.2.1添加为编译依赖项src/main/resources/META-INF/services/io.vertx.core.spi.VertxMetricsFactory文件注册它(反复检查它是否实际被复制到target/classes/META-INF/services/io.vertx.core.spi.VertxMetricsFactory)${basedir}/src/main/resources作为额外的类路径元素(除了前面的一点)我在调试器中再次签入,ServiceLoader实际上返回了一个空迭代器。
这是我的exec-plugin配置:<plugin> <groupId>org.codehaus.mojo</groupId> <artifactId>exec-maven-plugin</artifactId> <configuration> <additionalClasspathElements> <element>${basedir}/src/main/resources</element> </additionalClasspathElements> <mainClass>io.vertx.core.Launcher</mainClass> <commandlineArgs>run ${vertx.mainVerticle} -conf ${vertx.config}</commandlineArgs> <systemProperties> <systemProperty> <key>vertx.logger-delegate-factory-class-name</key> <value>io.vertx.core.logging.SLF4JLogDelegateFactory</value> </systemProperty> <systemProperty> <key>vertx.metrics.options.enabled</key> <value>true</value> </systemProperty> </systemProperties> </configuration> </plugin>
下面是exec:exec配置,确实可以使用,但我想了解是否和为什么可以使用exec:java来实现这一配置。
`<profile> <id>exec</id> <build> <plugins> <plugin> <groupId>org.codehaus.mojo</groupId> <artifactId>exec-maven-plugin</artifactId> <executions> <execution> <goals> <goal>exec</goal> </goals> <phase>process-classes</phase> <configuration> <executable>java</executable> <arguments> <argument>-Dvertx.metrics.options.enabled=true</argument> <argument>-Dvertx.logger-delegate-factory-class-name=${vertx.logger-delegate-factory-class-name}</argument> <argument>-classpath</argument> <classpath /> <argument>io.vertx.core.Launcher</argument> <argument>run</argument> <argument>${vertx.mainVerticle}</argument> <argument>-conf</argument> <argument>${vertx.config}</argument> </arguments> </configuration> </execution> </executions> </plugin> </plugins> </build> </profile>`发布于 2016-03-22 19:47:45
你试过exec:exec而不是exec:java吗?
exec:exec在一个单独的进程中运行,这可能解决您的问题。
ServiceLoader使用应用程序类加载器加载META-INF/services中列出的任何类。这就是为什么ServiceLoader在带有自定义类加载器(例如OSGi)的环境中经常不工作的原因。
由于Maven为每个Maven插件构建了自己的类加载器,即使您声明包含SPI的编译时依赖项,这些类也只能在Maven类加载器中可见,而对应用程序类加载器则不可见。
https://stackoverflow.com/questions/36161795
复制相似问题