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);
}
}
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:
Put all of them into your lib.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With