【问题标题】:MACOSX - java.lang.NoSuchMethodError: org.apache.http.impl.conn.CPool.setValidateAfterInactivity(I)VMACOSX - java.lang.NoSuchMethodError: org.apache.http.impl.conn.CPool.setValidateAfterInactivity(I)V
【发布时间】:2019-02-03 12:49:17
【问题描述】:

所以这是一个笨蛋,我希望得到一些帮助。

这是我遇到的错误

getS3Client(): Exception: java.lang.NoSuchMethodError: org.apache.http.impl.conn.CPool.setValidateAfterInactivity(I)V

当我尝试运行这段代码时

GrailsApplication grailsApplication

// Amazon AWS S3 properties
private awsProps = [  "loaded"      : false
                      , "S3Bucket"    : ""
                      , "AccessKeyId" : ""
                      , "AccessKeyPsw": ""
]

def getS3Client ( ) {
  try {
    if ( ! awsProps.loaded ) {
       loadAwsProperties()
    }

    def awsCreds = new BasicAWSCredentials( awsProps.AccessKeyId, awsProps.AccessKeyPsw )

    AmazonS3 s3Client
    s3Client = AmazonS3ClientBuilder.standard()
                .withCredentials( new AWSStaticCredentialsProvider( awsCreds ) )
                .withRegion( Regions.US_EAST_1 )
                .build()

        return s3Client
   } catch ( Throwable t ) {
        log.error ( "getS3Client(): Exception: ${t}" )
        return null
    }
}

这是我在文件顶部的依赖项

import com.amazonaws.HttpMethod
import com.amazonaws.auth.AWSStaticCredentialsProvider
import com.amazonaws.auth.BasicAWSCredentials

import com.amazonaws.regions.Regions

import com.amazonaws.services.s3.AmazonS3
import com.amazonaws.services.s3.AmazonS3ClientBuilder
import com.amazonaws.services.s3.model.*
import com.burris.portal.utils.Utils
import grails.core.GrailsApplication

import javax.imageio.ImageIO
import javax.imageio.ImageReader
import javax.imageio.stream.ImageInputStream
import java.awt.Graphics2D
import java.awt.RenderingHints
import java.awt.image.BufferedImage

import grails.gorm.transactions.Transactional
import groovy.util.logging.Log4j

这是我的 build.gradle 文件依赖项

* FOR AMAZON S3 force these org.apache.httpcomponents to the top of the classpath
 */
configurations.all {
    resolutionStrategy.force 'org.apache.httpcomponents:httpcore:4.4.9', 'org.apache.httpcomponents:httpclient:4.5.5'
}

/* Continue with other necessary dependencies */
dependencies {

    /* FOR AMAZON S3 */
    compile 'org.apache.httpcomponents:httpcore:4.4.9'
    compile "org.apache.httpcomponents:httpclient:4.5.5"
    compile "com.amazonaws:aws-java-sdk-s3:1.11.328"

    /* FOR GROOVY HTTP */
    compile "org.codehaus.groovy.modules.http-builder:http-builder:0.6"
    ...
 }

现在这里是关键,它几乎可以在所有其他开发者机器上运行,除了我自己的机器,我无法弄清楚为什么。

这是一个 groovy on grails 项目,我使用的构建引擎是 gradle with java。

这是我的版本,虽然我已经测试了其他几个可以在我同事的机器上运行但由于某种原因不是我的版本

java -version
java version "1.8.0_181"
Java(TM) SE Runtime Environment (build 1.8.0_181-b13)
Java HotSpot(TM) 64-Bit Server VM (build 25.181-b13, mixed mode)

gradle --version

------------------------------------------------------------
Gradle 4.6
------------------------------------------------------------

Build time:   2018-02-28 13:36:36 UTC
Revision:     8fa6ce7945b640e6168488e4417f9bb96e4ab46c

Groovy:       2.4.12
Ant:          Apache Ant(TM) version 1.9.9 compiled on February 2 2017
JVM:          1.8.0_181 (Oracle Corporation 25.181-b13)
OS:           Mac OS X 10.13.6 x86_64

grails --version
| Grails Version: 3.2.11
| Groovy Version: 2.4.11
| JVM Version: 1.8.0_181

gradle dependencies --configuration=testRuntime | grep httpcore
    +--- org.apache.httpcomponents:httpcore:4.4.9
    |    +--- org.apache.httpcomponents:httpcore:4.4.9
    |         |    |    +--- org.apache.httpcomponents:httpcore:4.3 -> 4.4.9
    |         |    |    \--- org.apache.httpcomponents:httpcore-nio:4.3
    |         |    |         \--- org.apache.httpcomponents:httpcore:4.3 -> 4.4.9

这是我尝试过的

  1. 升级和降级我的 java 版本、gradle、grails 和 groovy 版本都没有成功。我的同事在 gradle 3.1 和 4.8 上工作,所以我认为问题不在于这里。
  2. 从 openJDK 切换到 OracleJDK 没有运气。
  3. 通过 rm -rf ~/.gradlerm -rf ./gradlerm build/.dependencies 消除了我对全局主目录和本地 repo 目录的 gradle 依赖项,以强制重新下载所有 repo,但没有成功
  4. 尝试/gradlew clean build 没有成功
  5. 将 repo 克隆到不同的 repo,结果相同
  6. 重启了电脑还是不行
  7. 查看了 GitHub 和 StackOverflow,这让我认为升级我的 httpcore 版本会有所帮助,除了我对 httpcore 的所有 gradle 依赖项与另一台可以正常运行该方法的计算机完全相同(见上文)

这是我的 MAC OSX 版本 - macOS High Sierra Version 10.13.6

所以任何和所有的帮助都将不胜感激,因为我在这里无能为力。该应用程序在几乎所有其他情况下都能正常运行,但只是在该方法处中断。

【问题讨论】:

  • 您能提供此异常的堆栈跟踪吗?例如您可以将catch 块中的日志语句更改为log.error ( "getS3Client(): Exception: ${t}", t )

标签: java gradle grails amazon-s3 groovy


【解决方案1】:

我有同样的问题。就我而言,下面的这个线程帮助我解决了我的问题。 enter link description here

我有 httpclient:4.5.9 和 httpclient:4.3。然后我将 httpcore 更新到高于 4.4 的版本。

    <dependency>
        <groupId>org.apache.httpcomponents</groupId>
        <artifactId>httpasyncclient</artifactId>
        <version>4.5.9</version>
      <exclusions>
        <exclusion>
            <groupId>org.apache.httpcomponents</groupId>
            <artifactId>httpcore</artifactId>
        </exclusion>
      </exclusions>
    </dependency>
    <dependency>
      <groupId>org.apache.httpcomponents</groupId>
      <artifactId>httpcore</artifactId>
      <version>4.4.11</version>
    </dependency>

【讨论】:

    【解决方案2】:

    似乎此错误:etS3Client(): Exception: java.lang.NoSuchMethodError: org.apache.http.impl.conn.CPool.setValidateAfterInactivity(I)V 通常是由您的类路径中的 JAR 冲突引起的。

    您可以查看此链接以获取示例:https://community.hortonworks.com/content/supportkb/150327/error-javalangnosuchmethoderror-orgapachehttpimplc.html

    【讨论】:

    • -1 仅链接导致付费墙的答案。始终引用重要链接中最相关的部分,以防外部资源无法访问或永久离线。
    • 当时(2 年前 ^^)并没有在付费墙后面,但我必须承认,理论上你是对的。最后,上面已经引用了“相关部分”:“通常是由类路径中的 JAR 冲突引起的”。据我所知,这篇知识库文章中没有更多内容......
    猜你喜欢
    • 2011-01-26
    • 2016-02-09
    • 2016-06-14
    • 1970-01-01
    • 1970-01-01
    • 2018-03-11
    • 2018-08-15
    • 2018-04-23
    • 1970-01-01
    相关资源
    最近更新 更多