gpt4 book ai didi

java - NoClassDefFoundError com/google/api/services/storage/Storage$Builder

转载 作者:行者123 更新时间:2023-12-01 21:43:08 25 4
gpt4 key购买 nike

执行 GCS 图像上传步骤并从 URL 下载最新文件后

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

下面是代码。

    public class GcsExample {

private static GcsService gcsService = GcsServiceFactory.createGcsService();
// Error during initialization

public void doPost(String gcsFilename, byte[] data) throws IOException {

GcsFilename filename = new GcsFilename("niranttest2.appspot.com", gcsFilename);
com.google.appengine.tools.cloudstorage.GcsFileOptions.Builder fileOptionsBuilder = new GcsFileOptions.Builder();
fileOptionsBuilder.mimeType("image/jpeg");

GcsFileOptions fileOptions = fileOptionsBuilder.build();
GcsOutputChannel outputChannel = gcsService.createOrReplace(filename, fileOptions);

// write file out
BufferedOutputStream outStream = new BufferedOutputStream(Channels.newOutputStream(outputChannel));

List<byte[]> allBytes = new LinkedList<byte[]>();
allBytes.add(data);

for (byte[] b : allBytes) {
outStream.write(b);
}
outStream.close();
outputChannel.close();
}

}

此代码在本地主机中运行良好,但在生产中 gcsService 未初始化。服务器日志如下:

java.lang.NoClassDefFoundError: com/google/api/services/storage/Storage$Builder
at com.google.appengine.tools.cloudstorage.oauth.OauthRawGcsService.<init>(OauthRawGcsService.java:171)
at com.google.appengine.tools.cloudstorage.oauth.OauthRawGcsServiceFactory.createOauthRawGcsService(OauthRawGcsServiceFactory.java:41)
at com.google.appengine.tools.cloudstorage.GcsServiceFactory.createRawGcsService(GcsServiceFactory.java:59)
at com.google.appengine.tools.cloudstorage.GcsServiceFactory.createGcsService(GcsServiceFactory.java:44)
at com.google.appengine.tools.cloudstorage.GcsServiceFactory.createGcsService(GcsServiceFactory.java:40)
at com.google.appengine.tools.cloudstorage.GcsServiceFactory.createGcsService(GcsServiceFactory.java:75)
at com.sparks.nirant.serviceImpl.GcsExample.<clinit>(GcsExample.java:30)

下面是我正在使用的库

/WEB-INF/lib/appengine-api-1.0-sdk-1.9.28.jar
/WEB-INF/lib/appengine-api-labs.jar
/WEB-INF/lib/appengine-endpoints-deps.jar
/WEB-INF/lib/appengine-endpoints.jar
/WEB-INF/lib/appengine-jsr107cache-1.9.28.jar
/WEB-INF/lib/asm-4.0.jar
/WEB-INF/lib/commons-logging-1.1.1.jar
/WEB-INF/lib/datanucleus-api-jdo-3.1.3.jar
/WEB-INF/lib/datanucleus-api-jpa-3.1.3.jar
/WEB-INF/lib/datanucleus-appengine-2.1.2.jar
/WEB-INF/lib/datanucleus-core-3.1.3.jar
/WEB-INF/lib/geronimo-jpa_2.0_spec-1.0.jar
/WEB-INF/lib/google-api-client-1.21.0.jar
/WEB-INF/lib/google-api-client-android-1.21.0.jar
/WEB-INF/lib/google-api-client-appengine-1.21.0.jar
/WEB-INF/lib/google-api-client-gson-1.21.0.jar
/WEB-INF/lib/google-api-client-jackson2-1.21.0.jar
/WEB-INF/lib/google-api-client-java6-1.21.0.jar
/WEB-INF/lib/google-api-client-protobuf-1.21.0.jar
/WEB-INF/lib/google-api-client-servlet-1.21.0.jar
/WEB-INF/lib/google-api-client-xml-1.21.0.jar
/WEB-INF/lib/google-http-client-1.21.0.jar
/WEB-INF/lib/google-http-client-android-1.21.0.jar
/WEB-INF/lib/google-http-client-appengine-1.21.0.jar
/WEB-INF/lib/google-http-client-gson-1.21.0.jar
/WEB-INF/lib/google-http-client-jackson-1.21.0.jar
/WEB-INF/lib/google-http-client-jackson2-1.21.0.jar
/WEB-INF/lib/google-http-client-jdo-1.21.0.jar
/WEB-INF/lib/google-http-client-protobuf-1.21.0.jar
/WEB-INF/lib/google-http-client-xml-1.21.0.jar
/WEB-INF/lib/google-oauth-client-1.21.0.jar
/WEB-INF/lib/google-oauth-client-appengine-1.21.0.jar
/WEB-INF/lib/google-oauth-client-java6-1.21.0.jar
/WEB-INF/lib/google-oauth-client-jetty-1.21.0.jar
/WEB-INF/lib/google-oauth-client-servlet-1.21.0.jar
/WEB-INF/lib/gson-2.1.jar
/WEB-INF/lib/guava-jdk5-17.0.jar
/WEB-INF/lib/httpclient-4.0.1.jar
/WEB-INF/lib/httpcore-4.0.1.jar
/WEB-INF/lib/jackson-core-2.1.3.jar
/WEB-INF/lib/jackson-core-asl-1.9.11.jar
/WEB-INF/lib/jdo-api-3.0.1.jar
/WEB-INF/lib/jdo2-api-2.3-eb.jar
/WEB-INF/lib/jetty-6.1.26.jar
/WEB-INF/lib/jetty-util-6.1.26.jar
/WEB-INF/lib/jsr107cache-1.1.jar
/WEB-INF/lib/jsr305-1.3.9.jar
/WEB-INF/lib/jta-1.1.jar
/WEB-INF/lib/protobuf-java-2.4.1.jar
/WEB-INF/lib/transaction-api-1.1.jar
/WEB-INF/lib/xpp3-1.1.4c.jar
/WEB-INF/lib/javax.servlet-api-3.0.1.jar
/WEB-INF/lib/commons-fileupload-1.3.1.jar
/WEB-INF/lib/commons-io-2.4.jar
/WEB-INF/lib/google-api-client-1.18.0-rc.jar
/WEB-INF/lib/appengine-gcs-client-0.5.jar/

我相信错误是由于 appengine-gcs-client-0.5.jar 文件造成的,但我已经尝试使用 appengine-gcs-client-0.3.jar ,它再次抛出相同的错误。

最佳答案

您似乎正在使用原始存储客户端(正如我从 GcsServiceFactory.createRawGcsService 中看到的那样),我猜是因为您在 App Engine 之外使用它。也许无论如何都是需要的。

此类来自 google-api-services-storage lib,您应该添加以下依赖项:

<dependency>
<groupId>com.google.apis</groupId>
<artifactId>google-api-services-storage</artifactId>
<version>v1-rev66-1.21.0</version>
</dependency>

关于java - NoClassDefFoundError com/google/api/services/storage/Storage$Builder,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36231634/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com