I trying to use this example and learn how to call to rest service,
when I put this code I getting error since the eclipse doesn’t know
the org.example.Customer; .the error in definition Customer customer.
how can I import it to my project ?
I have tried to use the eclipse suggestion without success. (fix project setup etc)
import java.util.List;
import javax.ws.rs.core.MediaType;
import org.example.Customer;
import com.sun.jersey.api.client.*;
public class JerseyClient {
public static void main(String[] args) {
Client client = Client.create();
WebResource resource =
client.resource("http://localhost:8080/CustomerService/rest/customers");
// Get response as String
String string = resource.path("1")
.accept(MediaType.APPLICATION_XML)
.get(String.class);
System.out.println(string);
// Get response as Customer
Customer customer = resource.path("1") ------"*Here is the error in customer*-------
.accept(MediaType.APPLICATION_XML)
.get(Customer.class);
System.out.println(customer.getLastName() + ", "+ customer.getFirstName());
// Get response as List<Customer>
List<Customer> customers = resource.path("findCustomersByCity/Any%20Town")
.accept(MediaType.APPLICATION_XML)
.get(new GenericType<List<Customer>>(){});
System.out.println(customers.size());
}
}
I have used the code from this blog
http://blog.bdoughan.com/2010/08/creating-restful-web-service-part-55.html
Could be
1: is the import statement
import org.example.Customer;underlined in red?2: the class
Customeris that inside a jar? or another project in your workspace? or where is it located?3: Are there any chances that there could be two jars on your classpath that contains the class
Customer?4: if its in a project, did you first build that project?
update , see in the link here
they have shown the packaging and deployment organization, see the Customer class is inside
CustomerService.jarwhich is insideCustomerService.war. do you have these items?Dude did you follow the tutorial well?