0

我在 Eclipse 中有以下设置:

项目 A - 用作 Web 服务代码的动态 Web 项目。项目 B - 类包含 Main() 的测试客户端,以便我可以测试项目 A。

项目 A 包含一个属性文件,当项目 A 部署为 Web 服务时该文件可以正常工作。但是当我从测试客户端项目 B 运行测试时,无法识别属性文件。我创建了一个名为“resources”的文件夹,它与项目 A 中的“src”文件夹处于同一级别,并且此资源文件夹包含属性文件。项目 B 在其构建路径中有项目 A。

Project B - Client=> 下面是 Ecipe 中 Client 项目的示例代码:

public class Match {
  public static void main(String[] args) {
     MatchService service = new MatchService();
     SearviceRequest request = new ServiceRequest();
     request.setId(1);
     System.out.println("Output -> " + service.process(request)); 
  }
}

Web Project Under Test (Project A):

public class MatchService{
       public ServiceResponse process(SearviceRequest request){
              ServiceResponse resp = new ServiceResponse();
              if (request != null){
                  ServiceProcessor processor = new ServiceProcessor();
                  resp = processor.findMatch(request.getID());

              }
       }
}

public class ServiceProcessor{
       public ServiceResponse findMatch(ID id){
              if (id != null){
                  // Read Properties File. 
                  File file = new File("resources/My.properties") <---This fails when code is called from client. (Gives file no found exception. But File is present.
                  // Connect to database
                  // Get Data
                  // Build Response
                  // Send Response
              }
       }
}
4

0 回答 0