2

I am consuminbg a web service and I have places my WSDL in class path inside WEB-INF/classes directory. I am running the following code in a tomcat server.

First Approach

static {
    URL WSDL_LOC=WSClient.class.getClass().getClassLoader().getResource("Data.wsdl");
    System.out.println("Location here is : " + WSDL_LOC);
  }

Second Approach

static {
    URL WSDL_LOC =   Thread.currentThread().getContextClassLoader().getResource("Data.wsdl");
    System.out.println("Location here is : " + WSDL_LOC);
  }

When I run my war inside of tomcat tyhe first approach prints a null on the console while the second console actually prints it right. I just wanted to know why is it so and what is the right way of doing this.

station
  • 6,715
  • 14
  • 55
  • 89

1 Answers1

0

Well my expectation is that the first reference using static reference to WSClient uses the system classloader while the second reference using the current thread is hitting the Web application classloader of tomcat.

Read this link Difference between thread's context class loader and normal classloader

Alexander Petrov
  • 9,204
  • 31
  • 70