NetBeans + Glassfish --> NoSuchMethodError

使用 api google-cloud-translate 时会发生以下异常。我正在使用应用服务器 Glassfish 4、JSF 和 bootfaces 在 NetBeans 中开发一个 Web 应用程序。


示例代码:


public void traducir (String text){

Translate translate= TranslateOptions.getDefaultInstance().getService();   

//Traduccion Inglés

Translation translation = translate.translate(text,TranslateOption.sourceLanguage("es"), TranslateOption.targetLanguage("en"));

 String traduccionIngles =  translation.getTranslatedText();

 System.out.println("Ingles traducido= " + traduccionIngles);

}

此方法引发以下运行时异常


    Advertencia:   #{subirFicheroManagedBean.traducirTextosNuevos()}: java.lang.NoSuchMethodError: com.google.common.util.concurrent.MoreExecutors.directExecutor()Ljava/util/concurrent/Executor;

javax.faces.FacesException: #{subirFicheroManagedBean.traducirTextosNuevos()}: java.lang.NoSuchMethodError: com.google.common.util.concurrent.MoreExecutors.directExecutor()Ljava/util/concurrent/Executor;

    at com.sun.faces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:118)

    at javax.faces.component.UICommand.broadcast(UICommand.java:315)

    at javax.faces.component.UIViewRoot.broadcastEvents(UIViewRoot.java:790)

    at javax.faces.component.UIViewRoot.processApplication(UIViewRoot.java:1282)

    at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)

    at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:198)

    at javax.faces.webapp.FacesServlet.service(FacesServlet.java:658)

    at org.apache.catalina.core.StandardWrapper.service(StandardWrapper.java:1682)

    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)


慕丝7291255
浏览 127回答 2
2回答

侃侃无极

I have executed the command "mvn dependency:tree -Dverbose -Dincludes=com.google.guava"&nbsp; &nbsp; [INFO] Scanning for projects...&nbsp; &nbsp; [INFO]&nbsp;&nbsp; &nbsp; [INFO] --------------------< com.sample:traducionMvn >---------------------&nbsp; &nbsp; [INFO] Building traducionMvnPOM 1.0-SNAPSHOT&nbsp; &nbsp; [INFO] --------------------------------[ war ]---------------------------------&nbsp; &nbsp; [INFO]&nbsp;&nbsp; &nbsp; [INFO] --- maven-dependency-plugin:2.8:tree (default-cli) @ traducionMvn ---&nbsp; &nbsp; [INFO] com.cticontrol:traducionMvn:war:1.0-SNAPSHOT&nbsp; &nbsp; [INFO] \- com.google.guava:guava:jar:27.0.1-jre:compile&nbsp; &nbsp; [INFO]&nbsp; &nbsp; +- com.google.guava:failureaccess:jar:1.0.1:compile&nbsp; &nbsp; [INFO]&nbsp; &nbsp; \- com.google.guava:listenablefuture:jar:9999.0-empty-to-avoid-conflict-with-guava:compile&nbsp; &nbsp; [INFO] ------------------------------------------------------------------------&nbsp; &nbsp; [INFO] BUILD SUCCESS&nbsp; &nbsp; [INFO] ------------------------------------------------------------------------&nbsp; &nbsp; [INFO] Total time:&nbsp; 1.607 s&nbsp; &nbsp; [INFO] Finished at: 2019-02-18T11:27:14+01:00&nbsp; &nbsp; [INFO] ------------------------------------------------------------------------my pom is:&nbsp; <!-- Dependecias API TRADUCTOR GOOGLE -->&nbsp; &nbsp; &nbsp; &nbsp; <dependency>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <groupId>com.google.cloud</groupId>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <artifactId>google-cloud-translate</artifactId>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <!-- <version>1.61.0</version> -->&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <version>1.62.0</version>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <exclusions>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <exclusion>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <groupId>com.google.guava</groupId>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <artifactId>guava</artifactId>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </exclusion>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <exclusion>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <artifactId>com.google</artifactId>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <groupId>guava</groupId>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </exclusion>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </exclusions>&nbsp; &nbsp; &nbsp; &nbsp; </dependency>&nbsp; &nbsp; &nbsp; &nbsp; <dependency>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <groupId>com.google.api-client</groupId>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <artifactId>google-api-client</artifactId>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <version>1.28.0</version>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <exclusions>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <exclusion>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <groupId>com.google.guava</groupId>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <artifactId>guava</artifactId>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </exclusion>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <exclusion>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <artifactId>com.google</artifactId>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <groupId>guava</groupId>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </exclusion>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </exclusions>&nbsp; &nbsp; &nbsp; &nbsp; </dependency>&nbsp; &nbsp; &nbsp; &nbsp; <dependency>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <groupId>com.google.guava</groupId>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <artifactId>guava</artifactId>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <version>27.0.1-jre</version>&nbsp; &nbsp; &nbsp; &nbsp; </dependency>&nbsp; &nbsp; &nbsp; &nbsp; <!-- Fin dependencias API -->------------------------------------I keep giving the same error.&nbsp;

翻阅古今

发生这种情况是因为google-api-client版本依赖于 Guava 的版本。不要在 pom.xml 中使用 guava依赖项,而是尝试更改为直接的android 变体:1.28.026.0-android27.0.1-jre-jre26.0-jre&nbsp; &nbsp; <dependency>&nbsp; &nbsp; &nbsp; &nbsp; <groupId>com.google.guava</groupId>&nbsp; &nbsp; &nbsp; &nbsp; <artifactId>guava</artifactId>&nbsp; &nbsp; &nbsp; &nbsp; <version>26.0-jre</version>&nbsp; &nbsp; </dependency>有关此讨论的更多信息,有一个小线程。
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Java