org.apache.http.entity.ContentType 不在 Apache 中了? [英] org.apache.http.entity.ContentType is not in Apache anymore?

查看:111
本文介绍了org.apache.http.entity.ContentType 不在 Apache 中了?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

由于某种原因,我无法导入 org.apache.http.entity.ContentType.我添加了 Apache HTTP 4.3.3:

I can't import org.apache.http.entity.ContentType for some reason. I have added Apache HTTP 4.3.3:

  • 客户
  • 核心
  • 公共编解码器
  • httpclient-cache
  • 公共日志
  • httpmime
  • fluent-hc

最初我没有导入所有这些,但由于问题仍然存在,我现在已经全部完成了,并且我已经清理了我的项目并重建了它

originally I didn't import all of these, but since the problem persists I've done it all now, and I have cleaned my project and rebuilt it

import org.apache.http.entity.mime.MultipartEntityBuilder;有效

import org.apache.http.HttpEntity; 也可以

但是

import org.apache.http.entity.ContentType; 根本找不到

我正在使用 Android Studio (IntelliJ),所以我不确定构建路径答案在这里是否有帮助

I am using Android Studio (IntelliJ) so I'm not sure build path answers are helpful here

我也尝试通过 gradle 链接导入,但我遇到了不同的错误,需要自己更多地控制 jar 文件

I also tried importing via gradle link, but I encountered a different error and need more control over the jar files myself

推荐答案

org.apache.http.entity.ContentTypeorg.apache.httpcomponents:httpcore:4.3.x 模块.但org.apache.http.HttpEntity 也是如此.您找到一个而不是另一个的事实很可能意味着它们不是从 v4.3.x JAR 中提取的.Apache HttpCommponents 项目最近移动了很多类.因此,它可能会在以某种方式被拉入的较旧/不同版本的 httpcore 中找到 HttpEntity;没有 ContentType 类的版本.您需要验证它在哪里找到 HttpEntity.有几种方法可以查看从何处引入依赖项.

org.apache.http.entity.ContentType is in the org.apache.httpcomponents:httpcore:4.3.x module. But so is org.apache.http.HttpEntity. The fact you are finding one and not the other most likely means they are not being pulled in from the v4.3.x JAR. The Apache HttpCommponents project moved a lot of classes around recently. So it may be finding HttpEntity in an older/different version of httpcore that is getting pulled in somehow; a version that does not have the ContentType class. You'll want to verify where it is finding HttpEntity. There are a few ways to see from where a dependency is getting pulled in from.

选项 1最简单的方法之一是将光标放在类上(在导入语句或变量声明中)并打开快速文档(Ctrl+QJ).在文档对话框的顶部,它将显示找到该类的依赖项:

Option 1 One of the easiest ways is to put your cursor on the class (either in the import statement or a variable declaration) and open the quick documentation (Ctrl+Q or J). At the top of the documentation dialog, it will show the dependency where the class is found:

选项 2此选项将显示您的类路径上是否有一个类的多个实例.打开 Goto Class 对话框(Ctrl+NO)并输入类名(您可以完全限定或不完全限定.您甚至可以部分输入名称并使用驼峰式大小写搜索).在找到的类列表中,右侧将是找到类的位置.右边是类来自的依赖项.如果显示不止一次,则表示它在不同的罐子中被多次拉入.如果另一个依赖项将不同版本的 httpcore 作为传递依赖项引入,则可能会发生这种情况(使用构建工具时).所以你需要解决这个问题.请注意,在我的屏幕截图中,我有两个不同版本的 org.springframework.http.HttpEntity 类.一种来自 Spring 3.2.10,一种来自 4.0.6.在这种特殊情况下,这是因为我的项目中有一个基于 Spring 3.2.x 的模块和一个单独的 Spring 4.0.x 模块.所以我对此没有意见,因为它们不会发生冲突,因为它们是独立的模块.但在大多数情况下,这会引起关注.

Option 2 This option will show you if you have multiple instances of a class on your class path. Open the Goto Class dialog (Ctrl+N or O) and enter the class name (you can fully qualify or not. You can even paritally enter the name and use camel case search). In the list of classes that are found, to the right will be where the class is found. TO the right is the dependency from which the class is coming from. If it shows more than once, it means that it is being pulled in multiple times in different jars. This can happen (when using a build tool) if another dependency is pulling in a different version of httpcore as a transitive dependency. So you will need to resolve that. Notice in my screen shot I have two different versions of the org.springframework.http.HttpEntity class. One from Spring 3.2.10 and one from 4.0.6. In this particular case it is because I have a Spring 3.2.x based module and a separate Spring 4.0.x module in my project. So I'm OK with that as they do not clash since those are independent modules. But in most cases, that would be cause for concern.

选项 3您还可以展开并查看 Project 工具窗口中的 External Libraries 节点,以查看依赖项是否被拉入两次.

Option 3 You can also expand and look at the External Libraries node in the Project Tool window to see if a dependency is being pulled in twice.

目前尚不清楚您的项目是如何配置的.您提到了 gradle,但这似乎更像是事后的想法.如果您使用的是 maven 或 gradle,并且在您的 pom 或构建文件中声明了正确的 httpcore 依赖项,请确保您执行重新导入 在适当的构建工具窗口中,以便它正确同步并将该模块添加到项目的依赖项中.然后根据上面的信息查看是否有多个版本的httpcore模块被拉进来

It's unclear how your project is configured. You mentioned gradle, but it seemed more like an after thought. If you are using maven or gradle, and the proper httpcore dependency is declared in your pom or build file, make sure you perform a reimport on the appropriate build tool window so that it synchronizes properly and that module is added to the project's dependency. Then use the above information to see if you have multiple versions of the httpcore module being pulled in.

这篇关于org.apache.http.entity.ContentType 不在 Apache 中了?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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