Noel
Noel

Reputation: 10525

Logging in web services on weblogic

I have been trying to deploy JAX-WS services on Weblogic server as demonstrated in this link, Creating a Simple HelloWorld Web Service. I have deployed this and found to be working perfectly fine.

Now I also want to write data to log files, whenever this service is invoked. For this I'm using log4j. This is how i tried modifying the code in the link.

package examples.webservices.hello_world;

import javax.jws.WebService;
import org.apache.log4j.Logger; 

@WebService(name="HelloWorldPortType", serviceName="HelloWorldService")
public class HelloWorldImpl {

    public static Logger log = Logger.getLogger(HelloWorldImpl.class);

    public String sayHelloWorld(String message) {
    try {
        log.info("Start");
        System.out.println("sayHelloWorld:" + message);
    } catch (Exception ex) { ex.printStackTrace(); }
        return "Here is the message: '" + message + "'";
    }
}

I have set the path of log4j-1.2.8.jar file in CLASSPATH variable. But when i try to build the web service, it errs out saying, java.lang.ClassNotFoundException: org.apache.log4j.Logger.

I'm using the same build.xml file as given in the link. Are any modifications required in build.xml file? Where should i place the log4j.properties file? Any help is appreciated.

Upvotes: 3

Views: 2185

Answers (1)

Chris
Chris

Reputation: 5654

Even if your classpath is set, this issue has to be because weblogic is not able to find log4j at runtime. To be more specific, the Classloader of the war is not able to find the log4j.

Here are the ways to troubleshoot:

  1. Check your build.xml if you are infact bundling log4j in your WAR.
  2. Go to the autodeploy directory, copy the war file to a different location, deflate it and check if WEB-INF/lib and check if log4j indeed exists
  3. Check if there is more than one log4j version in your classpath.

Finally, the preferred approach for deploying set of reusable jars in weblogic is by a shared library and reference it through weblogic.xml.

It helps in:

  • Avoiding repetitive bundling of a jar file in different wars.
  • Making sure that all your deployment are streamlined to a preferred version of a library.

Upvotes: 1

Related Questions