我需要为JDK 1.6下载哪个Jersey版本? [英] What Jersey Version i need to download for JDK 1.6?

查看:158
本文介绍了我需要为JDK 1.6下载哪个Jersey版本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要为JDK 1.6下载哪个Jersey(具有RESTful Web服务支持)版本?请提供下载网址,这将对您有所帮助. 我还需要文件上传支持.客户端和服务器端的jar依赖项是什么?

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?

用于文件上传的REST服务器代码如下所示:

The REST server code for file upload looks like as follows:

@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 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()));

推荐答案

您需要Jersey 2.6版.用Java 7编译2.6之后的所有内容.从Maven中心.该捆绑包将所有核心jar捆绑到一个jar中

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

  • 抢夺 (包括服务器和客户端)
  • Grab the jaxrs-ri-2.6.jar (this includes server and client)

核心捆绑包不提供Multipart支持.您需要添加jersey-media-multipart jar.您可以从此处下载它.除了这个罐子,您还需要一个.如果向下滚动链接,将看到mimepull 1.9.3的链接.您还需要下载.

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.

如果您使用的是Maven,则实际上只需要这两个依赖项

If you're using Maven, you really only need these two dependencies

<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>

如果客户端项目未使用Maven或其他依赖项管理系统,则将很难使所有jar井井有条,因为没有单个jar包含仅用于客户端的所有内置jar .您可以使用上面的jaxrs-ri jar,但是它是一个大jar,因为它也具有所有服务器类.因此,如果您需要一个Android客户端,那么使用它可能不是一个好主意.在这种情况下,最好使用诸如Maven或Gradle之类的依赖项管理器.

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 could just 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.

另请参见:

如果仅jaxrs-ri-2.6.jar jar不能使用它,请尝试从上面的同一链接下载jaxrs-ri-2.6.tar.gz.解压缩并添加每个目录中的所有jars

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

这篇关于我需要为JDK 1.6下载哪个Jersey版本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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