maven构建jar运行时抛的异常,通过使用shade插件打包解决。
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<transformers>
<!--
解决Caused by: java.lang.IllegalStateException: Could not find policy 'pick_first'. Make sure its implementation is either registered to LoadBalancerRegistry or included in META-INF/services/io.grpc.LoadBalancerProvider from your jar files.
这个case通常是使用shade包的工程,在打包时候改变了gRPC的SPI实现的路径名,导致找不到实际实现所以出现上述异常
-->
<transformer implementation="org.apache.maven.plugins.shade.resource.ServicesResourceTransformer">
</transformer>
<!--指定主main 可以直接java -jar 运行-->
<transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
<mainClass>mainClassPath</mainClass>
</transformer>
</transformers>
</configuration>
</execution>
</executions>
</plugin>