从 websphere 迁移到 tomcat 后无法访问 wsdl 文件

Cant access wsdl file after migrating from websphere to tomcat

我一直在将应用程序从 websphere 服务器迁移到 tomcat。但是现在我发现访问wsdl文件有问题。该文件位于正确的文件夹中,但即使它在 websphere 中工作,我也无法在代码中访问它。迁移到 tomcat 后我需要更改什么?

Java-class:

    //
// Generated By:JAX-WS RI IBM 2.1.1 in JDK 6 (JAXB RI IBM JAXB 2.1.3 in JDK 1.6)
//

package iseries.wsbeans.bit05;

import java.net.MalformedURLException;
import java.net.URL;

import javax.xml.namespace.QName;
import javax.xml.ws.Service;
import javax.xml.ws.WebEndpoint;
import javax.xml.ws.WebServiceClient;
import javax.xml.ws.WebServiceFeature;

@WebServiceClient(name = "BIT05", targetNamespace = "http://bit05.wsbeans.iseries", wsdlLocation = "WEB-INF/wsdl/BIT05.wsdl")
public class BIT05
    extends Service
{

    private final static URL BIT05_WSDL_LOCATION;

    static {
        URL url = null;

        try {
            url = new URL("file:./WEB-INF/wsdl/BIT05.wsdl");
        } catch (MalformedURLException e) {
            e.printStackTrace();
        }

        BIT05_WSDL_LOCATION = url;
    }

    public BIT05(URL wsdlLocation, QName serviceName) {
        super(wsdlLocation, serviceName);
    }

    public BIT05() {
        super(BIT05_WSDL_LOCATION, new QName("http://bit05.wsbeans.iseries", "BIT05"));
    }

日志:

javax.xml.ws.WebServiceException: Failed to access the WSDL at: file:./WEB-INF/wsdl/BIT05.wsdl. It failed with: 
    Got .\WEB-INF\wsdl\BIT05.wsdl (The system cannot find the path specified) while opening stream from file:./WEB-INF/wsdl/BIT05.wsdl.
    at com.sun.xml.internal.ws.wsdl.parser.RuntimeWSDLParser.tryWithMex(Unknown Source)

有什么想法吗?

谢谢

而不是:

url = new URL("file:./WEB-INF/wsdl/BIT05.wsdl");

试试:

url = BIT05.class.getClassLoader().getResource("wsdl/BIT05.wsdl");

当文件位于类路径中时,最好使用类加载器或 ServletContext(如果有的话)而不是直接使用文件系统。