java 我需要为 JDK 1.6 下载哪个 Jersey 版本?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/36643869/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
What Jersey Version i need to download for JDK 1.6?
提问by Paul Samsotha
What Jersey (Has RESTful web service support) Version i need to download for JDK 1.6? Please provide the URL of the download and would be helpful. I also need file upload support. What are the jar dependencies for both client and server side?
我需要为 JDK 1.6 下载什么 Jersey(具有 RESTful Web 服务支持)版本?请提供下载的 URL,这会有所帮助。我还需要文件上传支持。客户端和服务器端的 jar 依赖是什么?
The REST server code for file upload looks like as follows:
文件上传的 REST 服务器代码如下所示:
@Path("/file")
public class FileService {
@POST
@Path("/upload")
@Consumes(MediaType.MULTIPART_FORM_DATA)
public void uploadFile(@FormDataParam("file") InputStream uploadedInputStream,@FormDataParam("file") FormDataContentDisposition aFileDetail) {
OutputStream os = null;
try {
File fileToUpload = new File("D:/uploadedFile");
os = new FileOutputStream(fileToUpload);
byte[] b = new byte[2048];
int length;
while ((length = uploadedInputStream.read(b)) != -1) {
os.write(b, 0, length);
}
} catch (IOException ex) {
ex.printStackTrace();
} finally {
try {
os.close();
} catch (IOException ex) {
ex.printStackTrace();
}
}
}
}
Client code looks like as follows:
客户端代码如下所示:
Client client = ClientBuilder.newBuilder()
.register(MultiPartFeature.class).build();
WebTarget webTarget = client.target(REST_SERVICE_URL);
MultiPart multiPart = new MultiPart();
FileDataBodyPart fileDataBodyPart = new FileDataBodyPart("file",
new File("d:/classes12-1.jar"),
MediaType.APPLICATION_OCTET_STREAM_TYPE);
multiPart.bodyPart(fileDataBodyPart);
Response response = webTarget.request(
MediaType.MULTIPART_FORM_DATA).post(
Entity.entity(multiPart, multiPart.getMediaType()));
回答by Paul Samsotha
You need Jersey version 2.6. Anything after 2.6 is compiled with Java 7. You can download the "bundle" from Maven central. The bundle comes with all the core jars bundled into one jar
您需要 Jersey 2.6 版。2.6 之后的任何东西都是用 Java 7 编译的。您可以从 Maven 中心下载“包”。该捆绑包将所有核心 jar 捆绑到一个 jar 中
- Grab the
jaxrs-ri-2.6.jar
(this includes server and client)
- 抓住
jaxrs-ri-2.6.jar
(这包括服务器和客户端)
The core bundle doesn't come with Multipart support. You need to add the jersey-media-multipart
jar. You can down load it from here. Along with this jar, you need one more. If you scroll down in the link, you will see a link for mimepull
1.9.3. You need to download that also.
核心包不附带多部分支持。您需要添加jersey-media-multipart
罐子。你可以从这里下载它。除了这个罐子,你还需要一个。如果您在链接中向下滚动,您将看到mimepull
1.9.3的链接。你也需要下载那个。
If you're using Maven, you really only need these two dependencies
如果你使用 Maven,你真的只需要这两个依赖
<dependency>
<groupId>org.glassfish.jersey.containers</groupId>
<artifactId>jersey-container-servlet</artifactId>
<version>2.6</version>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.media</groupId>
<artifactId>jersey-media-multipart</artifactId>
<version>2.6</version>
</dependency>
If the client project is a different project, then in the client project you should just add the below dependency and the above multipart dependency
如果客户端项目是一个不同的项目,那么在客户端项目中你应该只添加下面的依赖项和上面的多部分依赖项
<dependency>
<groupId>org.glassfish.jersey.core</groupId>
<artifactId>jersey-client</artifactId>
<version>2.6</version>
</dependency>
If the client project is not using Maven or some other dependency managemnet system, you are going to have a hard time getting all the jars in order, as there is no single jar that contains all the built in jars just for the client. You couldjust use the above jaxrs-ri
jar, but it is a large jar, as it has all the server classes also. So if you need it for say an android client, it might not be a good idea to use. Better just use a dependency manager like Maven or Gradle in this case.
如果客户端项目没有使用 Maven 或其他一些依赖管理网络系统,你将很难按顺序获取所有 jar,因为没有一个 jar 包含仅用于客户端的所有内置 jar。您可以只使用上面的jaxrs-ri
jar,但它是一个大 jar,因为它也包含所有服务器类。因此,如果您需要它作为 android 客户端,那么使用它可能不是一个好主意。在这种情况下,最好只使用像 Maven 或 Gradle 这样的依赖项管理器。
See Also:
也可以看看:
UPDATE
更新
If it doesn't work with just the jaxrs-ri-2.6.jar
jar, try and download the jaxrs-ri-2.6.tar.gz
from the same link above. Unzip it and add all the jars from every directory
如果它不能仅与jaxrs-ri-2.6.jar
jar 一起使用,请尝试jaxrs-ri-2.6.tar.gz
从上面的同一链接下载。解压缩并添加每个目录中的所有 jars
回答by user3896478
2.x branch:
2.x 分支:
Until version 2.6, Jersey was compiled with Java SE 6. This has changed in Jersey 2.7.
在 2.6 版本之前,Jersey 是使用 Java SE 6 编译的。这在 Jersey 2.7 中发生了变化。
Up to version 2.25.x almost all Jersey components are compiled with Java SE 7 target. It means, that you will need at least Java SE 7 to be able to compile and run your application that is using latest Jersey. Only core-common and core-client modules are still compiled with Java class version runnable with Java SE 6.
在 2.25.x 版本之前,几乎所有 Jersey 组件都是使用 Java SE 7 目标编译的。这意味着,您至少需要 Java SE 7 才能编译和运行使用最新 Jersey 的应用程序。只有 core-common 和 core-client 模块仍然使用可在 Java SE 6 中运行的 Java 类版本进行编译。
Since Jersey 2.26, all modules are build using Java SE 8 and there is no support for running it on older Java SE distributions.
从 Jersey 2.26 开始,所有模块都使用 Java SE 8 构建,并且不支持在较旧的 Java SE 发行版上运行它。