What Jersey Version i need to download for JDK 1.6?

别来无恙 提交于 2021-02-07 03:19:41

问题


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?

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

回答1:


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)

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.

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>

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.

See Also:

  • For server side multipart configuration

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




回答2:


2.1. Java SE Compatibility

2.x branch:

Until version 2.6, Jersey was compiled with Java SE 6. This has changed in 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.

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.



来源:https://stackoverflow.com/questions/36643869/what-jersey-version-i-need-to-download-for-jdk-1-6

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!