Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

The type javax.ws.rs.core.MediaType cannot be resolved

I am developing a Rest Client test program. I am new to this. From net I downloaded jersey-client-1.19.4.jar and added to Build Path in the eclipse. Every thing is fine except that webResource.accept gives below error.

The type javax.ws.rs.core.MediaType cannot be resolved

I am referring to REST Tutorials mentioned in below URL as reference for my test program development.

REST Client Tutorial

Below is my code: Kindly help

import java.io.*;

import com.sun.jersey.api.client.Client;
import com.sun.jersey.api.client.ClientResponse;
import com.sun.jersey.api.client.WebResource;

public class Test {

public static void main(String[] args) throws IOException{
    // TODO Auto-generated method stub
    System.out.println("File Name: "+args[0]);
    String fileName = args[0];

    Client client = Client.create();
    WebResource webResource = client.resource("http://services.groupkt.com/country/get/iso2code/AX");
    ClientResponse response = webResource.accept("application/json").get(ClientResponse.class);

    if (response.getStatus() != 200) 
    {
       throw new Exception("Exception Occured - HTTP Error Code : "
        + response.getStatus());
    }

    String output = response.getEntity(String.class);

    System.out.println("Fetching Output....");
    System.out.println(output);
}

}

like image 281
K Raghu Avatar asked Sep 03 '25 04:09

K Raghu


1 Answers

The solution from @yoav is great, but if someone has the same issue and doesn't want / need to convert to maven (which is better for dependency management) you just need to include all files from the zip file that you find following this link.

You will find:

  • jersey-client-1.19.4.jar
  • jersey-core-1.19.4.jar
  • jsr311-api-1.1.1.jar

Put all of them into your lib.

like image 165
sstlv_seraph Avatar answered Sep 05 '25 21:09

sstlv_seraph