Java – Unable to resolve type javax.ws.rs.core.MediaType

Unable to resolve type javax.ws.rs.core.MediaType… here is a solution to the problem.

Unable to resolve type javax.ws.rs.core.MediaType

I’m developing a Rest Client tester. I’m new here. I downloaded jersey-client-1.19.4.jar from the web and added it to the build path in Eclipse. Everything is fine, except that webResource.accept gives the following error.

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

I’m referring to the REST tutorial mentioned in the following URL as a reference to my tester development.

REST Client Tutorial

Here’s my code: Please 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);
}

Solution

@yoav’s solution is great, but if someone has the same problem and doesn’t want to/doesn’t need to convert to maven (which is better for dependency management), you just need to include all the files in your zip file found below link .

You will find:

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

Put them all into your library.

Related Problems and Solutions