我一直在将应用程序从websphere服务器迁移到tomcat。但是现在我发现了访问wsdl文件的问题。该文件位于正确的文件夹中,但我无法在代码中访问它,即使它在websphere中工作。迁移到tomcat后需要更改什么?
Java的类:
//
// 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)
有什么想法吗?
谢谢
答案 0 :(得分:1)
而不是:
url = new URL("file:./WEB-INF/wsdl/BIT05.wsdl");
尝试:
url = BIT05.class.getClassLoader().getResource("wsdl/BIT05.wsdl");
当文件在类路径中时,使用类加载器或ServletContext
(如果有的话)而不是直接文件系统总是更好。