【问题标题】:Integration xero (invoicing gateway) in apache felix (osgi)在 apache felix (osgi) 中集成 xero(发票网关)
【发布时间】:2019-11-29 08:02:46
【问题描述】:

我在 karaf(版本 3.0.3)中有一个包含多个模块的项目,我需要向 Xero API(发票网关)添加一个依赖项 - https://github.com/XeroAPI/Xero-Java

我通过 felix apache 使用 OSGI 实现。在模块中,我将所有依赖项添加到 Xero,这些都在 pom bellow 中。

Pom.xml

  <dependency>
    <groupId>com.github.xeroapi</groupId>
    <artifactId>xero-java</artifactId>
    <version>${xero-java.version}</version>
  </dependency>
  <dependency>
    <groupId>com.github.xeroapi</groupId>
    <artifactId>xeroapi-schemas</artifactId>
    <version>${xero-schemas.version}</version>
  </dependency>
  <dependency>
    <groupId>javax.xml.bind</groupId>
    <artifactId>jaxb-api</artifactId>
    <version>${jaxb-api.version}</version>
  </dependency>
  <dependency>
    <groupId>com.sun.xml.bind</groupId>
    <artifactId>jaxb-core</artifactId>
    <version>${jaxb-core.version}</version>
  </dependency>
  <dependency>
    <groupId>com.sun.xml.bind</groupId>
    <artifactId>jaxb-impl</artifactId>
    <version>${jaxb-impl.version}</version>
  </dependency>
  <dependency>
    <groupId>javax.activation</groupId>
    <artifactId>activation</artifactId>
    <version>${javax-activation.version}</version>
  </dependency>
  <dependency>
    <groupId>org.threeten</groupId>
    <artifactId>threetenbp</artifactId>
    <version>${threetenbp.version}</version>
  </dependency>

      <plugin>
        <groupId>org.apache.felix</groupId>
        <artifactId>maven-bundle-plugin</artifactId>
        <extensions>true</extensions>
        <configuration>
          <instructions>
            <Bundle-SymbolicName>${project.artifactId}</Bundle-SymbolicName>
            <Import-Package>!com.google.api.client.http,*</Import-Package>
            <Embed-Dependency>com.google.api.client.http</Embed-Dependency>
          </instructions>
        </configuration>
      </plugin>

所有实现都已部署和编译,但在运行 karaf 时出现下一个错误。

原木卡拉夫

2019-07-19 15:44:19,812 |错误 | lixDispatchQueue | FeatureDeploymentListener | 22 - org.apache.karaf.deployer.features - 3.0.3 |无法安装功能 java.lang.Exception:无法在功能be-invoice-mgmt-0.2-SNAPSHOT中启动捆绑mvn:com.xtpo.im/im-bll-impl/0.2-SNAPSHOT:捆绑com.xtpo中未解决的约束。 im.im-bll-impl [368]:无法解析 368.0:缺少要求 [368.0] osgi.wiring.package; (osgi.wiring.package=com.google.api.client.http) 在 org.apache.karaf.features.internal.FeaturesServiceImpl.startBundle(FeaturesServiceImpl.java:504)[21:org.apache.karaf.features.core:3.0.3] 在 org.apache.karaf.features.internal.FeaturesServiceImpl.installFeatures(FeaturesServiceImpl.java:459)[21:org.apache.karaf.features.core:3.0.3] 在 Proxya6f8789a_dbdc_4181_b0eb_837248e8cb78.installFeatures(未知来源)[:] 在 Proxycbafeabb_12c9_47e3_94d6_f999d20117fa.installFeatures(未知来源)[:] 在 org.apache.karaf.deployer.features.FeatureDeploymentListener.bundleChanged(FeatureDeploymentListener.java:213)[22:org.apache.karaf.deployer.features:3.0.3] 在 org.apache.felix.framework.util.EventDispatcher.invokeBundleListenerCallback(EventDispatcher.java:868)[org.apache.felix.framework-4.2.1.jar:] 在 org.apache.felix.framework.util.EventDispatcher.fireEventImmediately(EventDispatcher.java:789)[org.apache.felix.framework-4.2.1.jar:] 在 org.apache.felix.framework.util.EventDispatcher.run(EventDispatcher.java:1088)[org.apache.felix.framework-4.2.1.jar:] 在 org.apache.felix.framework.util.EventDispatcher.access$000(EventDispatcher.java:54)[org.apache.felix.framework-4.2.1.jar:] 在 org.apache.felix.framework.util.EventDispatcher$1.run(EventDispatcher.java:101)[org.apache.felix.framework-4.2.1.jar:] 在 java.lang.Thread.run(Thread.java:748)[:1.8.0_211] 引起:org.osgi.framework.BundleException:捆绑com.xtpo.im.im-bll-impl [368]中未解决的约束:无法解决368.0:缺少要求[368.0] osgi.wiring.package; (osgi.wiring.package=com.google.api.client.http) 在 org.apache.felix.framework.Felix.resolveBundleRevision(Felix.java:3974)[org.apache.felix.framework-4.2.1.jar:] 在 org.apache.felix.framework.Felix.startBundle(Felix.java:2037)[org.apache.felix.framework-4.2.1.jar:] 在 org.apache.felix.framework.BundleImpl.start(BundleImpl.java:955)[org.apache.felix.framework-4.2.1.jar:] 在 org.apache.felix.framework.BundleImpl.start(BundleImpl.java:942)[org.apache.felix.framework-4.2.1.jar:] 在 org.apache.karaf.features.internal.FeaturesServiceImpl.startBundle(FeaturesServiceImpl.java:501)[21:org.apache.karaf.features.core:3.0.3] ... 10 更多

问题在于 com.google.api.client.http。有人可以帮我解决这个问题吗?

在文件功能中,我有下一个依赖项:

features.xml

    <!--Xero dependencies-->
    <bundle>wrap:mvn:com.github.xeroapi/xero-java/${xero-java.version}</bundle>
    <bundle>wrap:mvn:com.github.xeroapi/xeroapi-schemas/${xero-schemas.version}</bundle>
    <bundle>wrap:mvn:javax.xml.bind/jaxb-api/${jaxb-api.version}</bundle>
    <bundle>wrap:mvn:com.sun.xml.bind/jaxb-impl/${jaxb-impl.version}</bundle>
    <bundle>wrap:mvn:javax.activation/activation/${javax-activation.version}</bundle>
    <bundle>wrap:mvn:org.threeten/threetenbp/${threetenbp.version}</bundle>

谢谢大家

【问题讨论】:

    标签: java osgi apache-karaf apache-felix xero-api


    【解决方案1】:

    Felix 无法解析包com.google.api.client.http。您必须部署包含该包的包或将其嵌入到您自己的包中。该软件包可从 maven 工件 com.google.http-client:google-http-client 获得。

    您可以将 maven-bundle-plugin 配置为 embed compile scoped dependencies 并将依赖项添加到上面链接的 google http-client 工件:

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

    可能需要对版本进行一些调整。请注意,该工件被打包为一个 OSGi 包,因此您也可以尝试下载它并将其与您自己的包一起部署到 karaf(而不是嵌入它)。

    【讨论】:

    • 感谢@gjoranv。我添加了包(版本 1.29.0)并得到下一个错误:java.lang.Exception: Could not start bundle mvn:com.xpto.im/im-bll-impl/0.2-SNAPSHOT in feature(s) be- invoice-mgmt-0.2-SNAPSHOT:捆绑 com.xpto.im.im-bll-impl [368] 中未解决的约束:无法解决 368.0:缺少要求 [368.0] osgi.wiring.package; (&(osgi.wiring.package=com.google.api.client.http)(version>=1.29.0)(!(version>=2.0.0)))
    • 在我的 pom 中,我使用插件“maven-bundle-plugin”和下一个配置: org.apache.felixmaven-bundle-plugin true${project.artifactId}!com.google.api.client.http ,*com.google.api.client.http
    • 我认为maven-bundle-plugin只匹配artifactId,所以Embed-Dependency标签的内容应该是google-http-client-apache。请尝试解压缩您的包以验证其类是否真正嵌入。 com.xtpo.im/im-bll-impl 指的是您正在构建的捆绑包,对吗?
    • 是的!我有同样的错误:(&amp;(osgi.wiring.package=com.google.api.client.http)(version&gt;=1.29.0)(!(version&gt;=2.0.0)))
    • 对不起,我对 maven 工件的看法是错误的。我用正确的答案更新了我的答案。
    猜你喜欢
    • 2017-07-11
    • 2018-05-14
    • 2017-10-25
    • 1970-01-01
    • 1970-01-01
    • 2015-04-12
    • 1970-01-01
    • 2014-09-09
    • 1970-01-01
    相关资源
    最近更新 更多