OSGI 中的 Google 客户端 API [英] Google Client API in OSGI

查看:40
本文介绍了OSGI 中的 Google 客户端 API的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我无法在 OSGI 应用程序框架 (AEM) 中提供 Java 的 OAuth 客户端库所需的依赖项.

I'm having trouble providing the dependencies needed for OAuth Client Library for Java within an OSGI application framework (AEM).

https://developers.google.com/api-client-library/java/google-oauth-java-client/setup

我不想手动将每个依赖项转换为 OSGI 包 BND.所以我使用 maven-bundle-plugin 将这些嵌入到我的包中.到目前为止,我的过程一直是在 error.log 中查看有关捆绑中未解决的约束"的消息.然后跟踪丢失的包,添加 maven 依赖项,并将其添加到 Embed-Dependency 部分.这似乎适用于 google-http-client 和 google-oauth-client.GSON(或 Jackson2 )无法通过这种方式解决,我收到消息...

I don't want to manually convert each dependency to an OSGI bundle, BND. So I'm using maven-bundle-plugin to embed these into my bundle. My process so far has been to watch the error.log for messages about 'Unresolved constraint in bundle.' Then track down the missing package, add the maven dependency, and add it to the Embed-Dependency section. That seemed to work for google-http-client and google-oauth-client. GSON (or Jackson2 ) cannot be resolved this way, and I get the message...

更新:

正如尼尔指出的那样,我需要为 GSON (google-http-client-gson) 嵌入不同的依赖项.谢谢!

As Neil pointed out I needed to embed a different dependency for GSON (google-http-client-gson). Thank you!

但是它仍然无法部署,并且目前正在报告此消息...

However it's still not able to deploy, and currently reporting this message...

org.osgi.framework.BundleException:捆绑 com.mypackage.services 中未解决的约束 [394]:无法解决 394.130:缺少需求 [394.130] osgi.wiring.package;(osgi.wiring.package=sun.misc)

org.osgi.framework.BundleException: Unresolved constraint in bundle com.mypackage.services [394]: Unable to resolve 394.130: missing requirement [394.130] osgi.wiring.package; (osgi.wiring.package=sun.misc)

似乎其他人对此有问题,可能与 OSGi 中的 Guava 我曾尝试将 sun.misc 设为可选.

It seems others have had trouble with this, and possible related to Guava in OSGi I have tried making sun.misc optional.

<Import-Package>sun.misc.*;resolution:=optional,*</Import-Package>

但捆绑包无法启动,并提供错误消息捆绑包中的未解决约束".在这一点上,我的问题是...

But the bundle fails to start, and provides the error message 'Unresolved constraint in bundle.' At this point my questions are...

有没有人成功地在 OSGI 中为 Java 部署 Google CLient API?如果是这样,如何?

或者.我很感激关于这个 sun.misc 包的建议,这可能与在 OSGI 中使用 Guava 有关系

Alternatively. I would appreciate suggestions about this sun.misc package, and it's possible relation to using Guava in OSGI

我的 pom.xml

<dependencies>
<dependency>
 <groupId>com.google.api-client</groupId>
 <artifactId>google-api-client</artifactId>
 <version>1.20.0</version>
</dependency>

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

<dependency>
  <groupId>com.google.api-client</groupId>
  <artifactId>google-api-client-java6</artifactId>
  <version>1.20.0</version>
</dependency>

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

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

<dependency>
  <groupId>com.google.oauth-client</groupId>
  <artifactId>google-oauth-client</artifactId>
  <version>1.20.0</version>
</dependency>

<dependency>
  <groupId>com.google.oauth-client</groupId>
  <artifactId>google-oauth-client-java6</artifactId>
  <version>1.20.0</version>
</dependency>

<dependency>
    <groupId>com.google.guava</groupId>
    <artifactId>guava</artifactId>
    <version>18.0</version>
</dependency>

<dependency>
    <groupId>org.glassfish</groupId>
    <artifactId>javax.jms</artifactId>
    <version>3.2-b06</version>
</dependency>

<dependency>
    <groupId>commons-logging</groupId>
    <artifactId>commons-logging</artifactId>
    <version>1.1.3</version>
</dependency>


<dependency>
    <groupId>org.apache.httpcomponents</groupId>
    <artifactId>httpclient</artifactId>
    <version>4.5</version>
</dependency>

<dependency>
    <groupId>org.apache.httpcomponents</groupId>
    <artifactId>httpcore</artifactId>
    <version>4.4.1</version>
</dependency>
<dependency>
    <groupId>org.apache.servicemix.bundles</groupId>
    <artifactId>org.apache.servicemix.bundles.ehcache</artifactId>
    <version>2.6.11_1</version>
</dependency>

<dependency>
    <groupId>org.apache.servicemix.bundles</groupId>
    <artifactId>org.apache.servicemix.bundles.avalon-framework</artifactId>
    <version>4.3.1_1</version>
</dependency>
</dependencies>
<build>
    <plugins>
        <plugin>
            <groupId>org.apache.felix</groupId>
            <artifactId>maven-bundle-plugin</artifactId>
            <extensions>true</extensions>
            <configuration>
                <instructions>
                    <Bundle-Activator>com.mypackage.services.osgi.Activator</Bundle-Activator>
                    <Embed-Dependency>    
                        google-api-client;scope=compile,
                        google-oauth-client;scope=compile,
                        google-http-client;scope=compile,
                        google-api-client-gson;scope=compile,                 
                        gson;scope=compile,
                        httpclient;scope=compile, 
                    </Embed-Dependency>
                    <Sling-Test-Regexp>.*Test</Sling-Test-Regexp>
                </instructions>
            </configuration>
        </plugin>

MANIFEST.MF 中的部分

Portions from the MANIFEST.MF

Embed-Dependency: google-api-client;scope=compile,google-api-client-java
 6;scope=compile,google-oauth-client;scope=compile,google-oauth-client-j
 ava6;scope=compile,google-http-client;scope=compile,google-http-client-
 gson;scope=compile,google-http-client-jackson2;scope=compile,gson;scope
 =compile,guava;scope=compile,httpclient;scope=compile,httpcore;scope=co
 mpile,
Embedded-Artifacts: google-api-client-1.20.0.jar;g="com.google.api-clien
 t";a="google-api-client";v="1.20.0",google-api-client-java6-1.20.0.jar;
 g="com.google.api-client";a="google-api-client-java6";v="1.20.0",google
 -oauth-client-1.20.0.jar;g="com.google.oauth-client";a="google-oauth-cl
 ient";v="1.20.0",google-oauth-client-java6-1.20.0.jar;g="com.google.oau
 th-client";a="google-oauth-client-java6";v="1.20.0",google-http-client-
 1.20.0.jar;g="com.google.http-client";a="google-http-client";v="1.20.0"
 ,google-http-client-gson-1.20.0.jar;g="com.google.http-client";a="googl
 e-http-client-gson";v="1.20.0",google-http-client-jackson2-1.20.0.jar;g
 ="com.google.http-client";a="google-http-client-jackson2";v="1.20.0",gs
 on-2.3.jar;g="com.google.code.gson";a="gson";v="2.3",guava-18.0.jar;g="
 com.google.guava";a="guava";v="18.0",httpclient-4.5.jar;g="org.apache.h
 ttpcomponents";a="httpclient";v="4.5",httpcore-4.4.1.jar;g="org.apache.
 httpcomponents";a="httpcore";v="4.4.1"
Import-Package: com.adobe.cq.sightly;version="[2.2,3)",com.day.cq.common
 s;version="[5.7,6)",com.day.cq.commons.date;version="[5.7,6)",com.day.c
 q.dam.api;version="[1.2,2)",com.day.cq.search;version="[1.1,2)",com.day
 .cq.search.result;version="[1.1,2)",com.day.cq.tagging;version="[5.7,6)
 ",com.day.cq.wcm.api;version="[1.2,2)",com.day.cq.wcm.api.components;ve
 rsion="[5.7,6)",com.day.cq.wcm.commons;version="[5.7,6)",com.day.cq.wcm
 .foundation;version="[5.7,6)",com.fasterxml.jackson.core;version="[2.1,
 3)",javax.annotation,javax.crypto,javax.crypto.spec,javax.jcr;version="
 [2.0,3)",javax.naming,javax.naming.directory,javax.naming.ldap,javax.ne
 t,javax.net.ssl,javax.security.auth.x500,javax.servlet,javax.servlet.ht
 tp,javax.xml.parsers,org.apache.commons.codec.binary,org.apache.commons
 .httpclient;version="[3.1,4)",org.apache.commons.httpclient.methods;ver
 sion="[3.1,4)",org.apache.commons.httpclient.params;version="[3.1,4)",o
 rg.apache.commons.io;version="[1.4,2)",org.apache.commons.logging;versi
 on="[1.1,2)",org.apache.sling.api;version="[2.3,3)",org.apache.sling.ap
 i.request;version="[2.4,3)",org.apache.sling.api.resource;version="[2.5
 ,3)",org.apache.sling.api.servlets;version="[2.1,3)",org.apache.sling.a
 pi.wrappers;version="[2.5,3)",org.apache.sling.jcr.api;version="[2.2,3)
 ",org.apache.sling.junit.annotations;version="[1.0,2)",org.ietf.jgss,or
 g.junit;version="[4.8,5)",org.junit.runner;version="[4.8,5)",org.osgi.f
 ramework;version="[1.5,2)",org.osgi.service.component;version="[1.1,2)"
 ,org.slf4j;version="[1.6,2)",org.w3c.dom,org.xml.sax,sun.misc

推荐答案

所以我终于让它工作了.我已经发布了代码以防对其他人有帮助,或者可能找到更好的方法.

So I finally have it working. I've posted the code in case it helps others, or perhaps to find better ways to do it.

依赖项...

<!-- Embedded Google Client API JAR's -->
<dependency>
 <groupId>com.google.api-client</groupId>
 <artifactId>google-api-client</artifactId>
 <version>1.20.0</version>
</dependency>
<dependency>
  <groupId>com.google.http-client</groupId>
  <artifactId>google-http-client</artifactId>
  <version>1.20.0</version>
</dependency>
<dependency>
  <groupId>com.google.api-client</groupId>
  <artifactId>google-api-client-java6</artifactId>
  <version>1.20.0</version>
</dependency>
<dependency>
    <groupId>com.google.http-client</groupId>
    <artifactId>google-http-client-jackson2</artifactId>
    <version>1.20.0</version>
</dependency>
<dependency>
    <groupId>com.google.http-client</groupId>
    <artifactId>google-http-client-gson</artifactId>
    <version>1.20.0</version>
</dependency>
<dependency>
  <groupId>com.google.oauth-client</groupId>
  <artifactId>google-oauth-client</artifactId>
  <version>1.20.0</version>
</dependency>
<dependency>
  <groupId>com.google.oauth-client</groupId>
  <artifactId>google-oauth-client-java6</artifactId>
  <version>1.20.0</version>
</dependency>
<dependency>
    <groupId>org.apache.servicemix.bundles</groupId>
    <artifactId>org.apache.servicemix.bundles.avalon-framework</artifactId>
    <version>4.3.1_1</version>
</dependency>
<dependency>
    <groupId>commons-logging</groupId>
    <artifactId>commons-logging</artifactId>
    <version>1.1</version>
</dependency>
<dependency>
    <groupId>org.glassfish</groupId>
    <artifactId>javax.jms</artifactId>
    <version>3.2-b06</version>
</dependency>

maven-bundle-plugin 设置

the maven-bundle-plugin settings

    <plugin>
      <groupId>org.apache.felix</groupId>
      <artifactId>maven-bundle-plugin</artifactId>
      <extensions>true</extensions>
      <configuration>
          <instructions>
              <Bundle-Activator>com.r2i.michigan.lsa.services.osgi.Activator</Bundle-Activator>
              <Embed-Dependency>                             
                  *;scope=compile|runtime,
              </Embed-Dependency>
                <Embed-Transitive>true</Embed-Transitive> 
                <Import-Package>
                  sun.misc;resolution:=optional,
                  com.sun.jdmk.comm;resolution:=optional,*
                </Import-Package>                       
              <Sling-Test-Regexp>.*Test</Sling-Test-Regexp>
          </instructions>
      </configuration>
    </plugin>   

这篇关于OSGI 中的 Google 客户端 API的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆