3

我在 apache karaf 4.2.6 中有一个带有 java 11 的模块,用于验证 Google Play 中的购买收据。我正在使用androidpublisher。

当它第一次发送请求时,我在 OpenCensusUtils 类中收到错误:

androidPublisher.purchases().products().get(packageName, productId, purchaseToken).execute()

java.lang.ClassNotFoundException: io.opencensus.trace.propagation.TextFormat not found by wrap_file__Users_USER_NAME_.m2_repository_io_opencensus_opencensus-contrib-http-util_0.22.1_opencensus-contrib-http-util-0.22.1.jar

在随后的时间里,我在 com.google.api.client.http.HttpRequest 类中出现错误private final Tracer tracer = OpenCensusUtils.getTracer()

java.lang.NoClassDefFoundError: Could not initialize class com.google.api.client.http.OpenCensusUtils

这是依赖项:

    <dependency>
        <groupId>com.google.apis</groupId>
        <artifactId>google-api-services-androidpublisher</artifactId>
        <version>v3-rev92-1.25.0</version>
        <exclusions>
            <exclusion>
                <groupId>org.apache.httpcomponents</groupId>
                <artifactId>httpclient</artifactId>
            </exclusion>
        </exclusions>
    </dependency>

    <dependency>
        <groupId>com.google.http-client</groupId>
        <artifactId>google-http-client</artifactId>
        <version>1.29.2</version>
    </dependency>

    <dependency>
        <groupId>io.opencensus</groupId>
        <artifactId>opencensus-api</artifactId>
        <version>0.22.1</version>
    </dependency>
    <dependency>
        <groupId>io.opencensus</groupId>
        <artifactId>opencensus-contrib-http-util</artifactId>
        <version>0.22.1</version>
    </dependency>

此外google-api-clientgoogle-http-client-jackson2并且google-oauth-client有版本 1.29.2

在 karaf 我看到库opencensus-api正在导出一个 io.opencensus.trace.propagation包含类 TextFormat 的包。

我究竟做错了什么?

4

1 回答 1

1

我通过将 io.opencensus 和 io.grpc 添加到模块构建区域的 Private-Package 来解决,如下所示。它使它们嵌入本地。

....
 <build>
    <plugins>
      <plugin>
       ....
        <configuration>
          <instructions>
            <Bundle-SymbolicName> ${project.artifactId} </Bundle-SymbolicName>
            <Private-Package>
             META-INF.services;-split-package:=merge-first,
             com.google.*;-split-package:=merge-first,
             io.opencensus.*;-split-package:=merge-first,
             io.grpc.*;-split-package:=merge-first
            </Private-Package>
            ....
于 2020-01-21T20:44:20.943 回答