Can we call another project java class from our project in eclipse

前端 未结 9 1553
心在旅途
心在旅途 2020-11-30 07:40
import ...

public class TriggerJob {

    String jobStatus = \"\";
    SchedulerMetaData metaData = null;

    public void rightNow(HashMap ParamMap){ 

AnotherProj         


        
9条回答
  •  失恋的感觉
    2020-11-30 08:20

    I have done like this in my project:

    ClientResponse response=WebServiceClient.invokeGRODService("document","get",documentId);
    
    • invokeGRODService() is a method in WebServiceClient class where URL is mentioned.
    • "document" is method level path,"get" is class level path and documentId is parameter to be passed as an input to other class in other project.
    • invokeGRODService() is as follows:

         public static ClientResponse invokeGRODService(String classLevelPath, String methodLevelPath,Object request){
    >           LOGGER.info("invokeGRODService()...Start");
    >           ClientConfig config = new DefaultClientConfig();
    >           Client client = Client.create(config);
    >           WebResource service=null;
    >           try{
    >               service = client.resource(UriBuilder.fromUri(AppProperties.getProperty(AppConstants.GROD_REST_SERVICE_URL)).build());
    >       }catch(PropertyNotFoundException pe){
    >           LOGGER.error("Error getting the--- "+pe);
    >       }
    >       try {
    >           ClientResponse response = service.path(classLevelPath).path(methodLevelPath).type(MediaType.APPLICATION_XML).post(ClientResponse.class,
    > request);
    >           if (response.getClientResponseStatus() != ClientResponse.Status.OK) {
    >               String errorResponse = response.getEntity(String.class);
    >               LOGGER.error("RECEIVED ERROR FROM WEBSERVICE.."+errorResponse);
    >           }
    >           LOGGER.info("invokeGRODService()...End");
    >           return response;
    >       } catch (Exception e) {
    >           LOGGER.error("Error while calling GRoD web service: ",e);
    >       }
    >       return null;
    >     }
    
    • Mention your URL in "AppConstants.GROD_REST_SERVICE_URL". I have taken it from constant through AppProperties.

    ClientResponse response = service.path(classLevelPath).path(methodLevelPath).type(MediaType.APPLICATION_XML).post(ClientResponse.class, request);

    • If URL is correct you should get data in response object with status 200(OK).

提交回复
热议问题