java.lang.NoSuchMethodError:com.google.common.base.CharMatcher.ascii()

时间:2019-01-06 04:44:49

标签: java glassfish google-cloud-storage guava

我在glassfish服务器上收到此错误

java.lang.NoSuchMethodError: com.google.common.base.CharMatcher.ascii()Lcom/google/common/base/CharMatcher;
at com.google.common.io.BaseEncoding$Alphabet.<init>(BaseEncoding.java:453)
at com.google.common.io.BaseEncoding$Base64Encoding.<init>(BaseEncoding.java:892)
at com.google.common.io.BaseEncoding.<clinit>(BaseEncoding.java:317)
at com.google.cloud.storage.StorageImpl.create(StorageImpl.java:133)
at utils.GoogleCouldBucket_Utils.initGoogleBucket(GoogleCouldBucket_Utils.java:52)
at controllers.proTektantController.loggedInTryingToRegister(proTektantController.java:783)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at javax.el.ELUtil.invokeMethod(ELUtil.java:332)
at javax.el.BeanELResolver.invoke(BeanELResolver.java:537)
at javax.el.CompositeELResolver.invoke(CompositeELResolver.java:256)
at com.sun.el.parser.AstValue.invoke(AstValue.java:283)
at com.sun.el.MethodExpressionImpl.invoke(MethodExpressionImpl.java:304)
at org.jboss.weld.util.el.ForwardingMethodExpression.invoke(ForwardingMethodExpression.java:40)
at org.jboss.weld.el.WeldMethodExpression.invoke(WeldMethodExpression.java:50)
at com.sun.faces.facelets.el.TagMethodExpression.invoke(TagMethodExpression.java:105)
at com.sun.faces.facelets.tag.jsf.core.DeclarativeSystemEventListener.processEvent(EventHandler.java:128)
at javax.faces.component.UIComponent$ComponentSystemEventListenerAdapter.processEvent(UIComponent.java:2584)
at javax.faces.event.SystemEvent.processListener(SystemEvent.java:108)
at javax.faces.event.ComponentSystemEvent.processListener(ComponentSystemEvent.java:118)
at com.sun.faces.application.ApplicationImpl.processListeners(ApplicationImpl.java:2169)
at com.sun.faces.application.ApplicationImpl.invokeComponentListenersFor(ApplicationImpl.java:2114)
at com.sun.faces.application.ApplicationImpl.publishEvent(ApplicationImpl.java:287)
at com.sun.faces.application.ApplicationImpl.publishEvent(ApplicationImpl.java:245)
at javax.faces.application.ApplicationWrapper.publishEvent(ApplicationWrapper.java:726)
at com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java:107)
at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)
at com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:219)
at javax.faces.webapp.FacesServlet.service(FacesServlet.java:659)
at org.apache.catalina.core.StandardWrapper.service(StandardWrapper.java:1682)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:318)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:160)
at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:734)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:673)
at com.sun.enterprise.web.WebPipeline.invoke(WebPipeline.java:99)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:174)
at org.apache.catalina.connector.CoyoteAdapter.doService(CoyoteAdapter.java:416)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:283)
at com.sun.enterprise.v3.services.impl.ContainerMapper$HttpHandlerCallable.call(ContainerMapper.java:459)
at com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:167)
at org.glassfish.grizzly.http.server.HttpHandler.runService(HttpHandler.java:206)
at org.glassfish.grizzly.http.server.HttpHandler.doHandle(HttpHandler.java:180)
at org.glassfish.grizzly.http.server.HttpServerFilter.handleRead(HttpServerFilter.java:235)
at org.glassfish.grizzly.filterchain.ExecutorResolver$9.execute(ExecutorResolver.java:119)
at org.glassfish.grizzly.filterchain.DefaultFilterChain.executeFilter(DefaultFilterChain.java:283)
at org.glassfish.grizzly.filterchain.DefaultFilterChain.executeChainPart(DefaultFilterChain.java:200)
at org.glassfish.grizzly.filterchain.DefaultFilterChain.execute(DefaultFilterChain.java:132)
at org.glassfish.grizzly.filterchain.DefaultFilterChain.process(DefaultFilterChain.java:111)
at org.glassfish.grizzly.ProcessorExecutor.execute(ProcessorExecutor.java:77)
at org.glassfish.grizzly.nio.transport.TCPNIOTransport.fireIOEvent(TCPNIOTransport.java:536)
at org.glassfish.grizzly.strategies.AbstractIOStrategy.fireIOEvent(AbstractIOStrategy.java:112)
at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy.run0(WorkerThreadIOStrategy.java:117)
at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy.access$100(WorkerThreadIOStrategy.java:56)
at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy$WorkerThreadRunnable.run(WorkerThreadIOStrategy.java:137)
at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:591)
at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.run(AbstractThreadPool.java:571)
at java.lang.Thread.run(Thread.java:748)

我正在用Glassfish网站。我已经添加了亚马逊存储桶支持。它可以工作,但是我对他们有疑问,所以我转到了谷歌云平台。我尝试添加Google存储桶。

public static boolean initGoogleBucket()
{
    try {
        ExternalContext externalContext = FacesContext.getCurrentInstance().getExternalContext();
        InputStream iStream = externalContext.getResourceAsStream("/WEB-INF/googleBucket.json");
        if(iStream == null) {
            return false;
        }
        Credentials credentials = GoogleCredentials.fromStream(iStream);
        storage = StorageOptions.newBuilder().setCredentials(credentials).setProjectId(GCP_PROJECT).build().getService();

        BlobId blobId = BlobId.of(GCP_BUCKET,"blob_name3");
        BlobInfo blobInfo = BlobInfo.newBuilder(blobId).setContentType("text/plain").build();
        String str = "Hello, Cloud Storage!";

        Blob blob = storage.create(blobInfo, str.getBytes());
        System.out.println("time:="+blob.getCreateTime() + ", link:"+blob.getMediaLink());
        return true;
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
        return false;
    }
}

在调试器中,我发现它在“ storage.create”失败

我在线阅读,发现的唯一原因是“ google-collet.jar”。我在图书馆中找不到这个罐子。可能是有其他依赖性。

这是我的罐子清单:

glassfish4.1.1/glassfish/domains/domain1/eclipseApps/<project>/WEB-INF/lib$ ls
BootsFaces-OSP-dist-0.7.0.jar
api-common-1.7.0.jar
aspectjrt-1.8.2.jar
aspectjweaver.jar
aws-java-sdk-1.11.285-javadoc.jar
aws-java-sdk-1.11.285-sources.jar
aws-java-sdk-1.11.285.jar
aws-java-sdk.jar
aws-swf-build-tools-1.1.jar
bootstrap-1.0.10.jar
commons-beanutils-1.8.3.jar
commons-codec-1.9.jar
commons-collections-3.2.jar
commons-digester-1.8.jar
commons-logging-1.1.3.jar
freemarker-2.3.9.jar
gax-1.30.0.jar
gax-httpjson-0.47.0.jar
gmaps4jsf-core-3.0.0.jar
google-api-client-1.24.1.jar
google-api-services-storage-v1-rev135-1.24.1.jar
google-auth-library-credentials-0.10.0.jar
google-auth-library-oauth2-http-0.10.0.jar
google-cloud-core-1.40.0.jar
google-cloud-core-http-1.40.0.jar
google-cloud-storage-1.40.0.jar
google-http-client-1.24.1.jar
google-http-client-appengine-1.24.1.jar
google-http-client-jackson-1.24.1.jar
google-http-client-jackson2-1.24.1.jar
google-oauth-client-1.24.1.jar
grpc-context-1.12.0.jar
gson-2.7.jar
guava-23.0.jar
httpclient-4.5.2.jar
httpcore-4.4.4.jar
ion-java-1.0.2.jar
jackson-annotations-2.6.0.jar
jackson-core-2.6.7.jar
jackson-core-asl-1.9.11.jar
jackson-databind-2.6.7.1.jar
jackson-dataformat-cbor-2.6.7.jar
javax.el.jar
javax.mail-api-1.4.6.jar
jmespath-java-1.11.285.jar
joda-time-2.8.1.jar
joda-time-2.9.2.jar
jsf-facelets.jar
jsr305-3.0.2.jar
jstl-1.2.jar
jstl-api-1.2.jar
jstl-impl.jar
jstl.jar
myfaces-api-2.1.5.jar
myfaces-bundle-2.1.5.jar
myfaces-impl-2.1.5.jar
mysql-connector-java-5.1.9.jar
netty-buffer-4.1.17.Final.jar
netty-codec-4.1.17.Final.jar
netty-codec-http-4.1.17.Final.jar
netty-common-4.1.17.Final.jar
netty-handler-4.1.17.Final.jar
netty-resolver-4.1.17.Final.jar
netty-transport-4.1.17.Final.jar
opencensus-api-0.15.0.jar
opencensus-contrib-http-util-0.15.0.jar
primefaces-6.2.jar
proto-google-common-protos-1.12.0.jar
proto-google-iam-v1-0.12.0.jar
protobuf-java-3.6.0.jar
protobuf-java-util-3.6.0.jar
spring-beans-3.0.7.RELEASE.jar
spring-context-3.0.7.RELEASE.jar
spring-core-3.0.7.RELEASE.jar
spring-test-3.0.7.RELEASE.jar
threetenbp-1.3.3.jar

我也有“ Glassfish系统库”和“ JRE系统库[Java Se 8 [1.8.0_161]]””

我正在使用日食。我对Marven很熟悉。

2 个答案:

答案 0 :(得分:1)

这是由您的Guava依赖项中的冲突引起的。您的类路径中的其他依赖项使用的是其他版本的Guava。

我建议运行mvn dependency:tree -Dverbose -Dincludes=guavamvn dependency:tree -Dverbose -Dincludes=guava-jdk5。这将使您能够在类路径中找到依赖项冲突。 guava-jdk5依赖性是导致此特定错误的常见原因。

Maven网站上也提供了有关解决冲突的更多信息; https://maven.apache.org/plugins/maven-dependency-plugin/examples/resolving-conflicts-using-the-dependency-tree.html

一旦确定了引起冲突的依赖项,就可以在pom.xml的依赖项中引入排除规则,以排除导致问题的依赖项,例如;

<exclusions>
    <exclusion>
        <groupId>com.google.guava</groupId>
        <artifactId>guava</artifactId>
    </exclusion>
    <exclusion>
        <groupId>com.google.guava</groupId>
        <artifactId>guava-jdk5</artifactId>
    </exclusion>
</exclusions>

答案 1 :(得分:0)

我解决了问题,但降级了Google云库,并使用inputstream而不是bytes数组。 google不推荐使用此方法,但是将库降级并使用@SuppressWarnings(“ deprecation”)即可。