2010-10-21 54 views
0

一般情况下,WSIT-client.xml的有import语句像这样的文件:导入位置到另一个JAR文件,使用URL字符串来定位classpath中

<import location="foo.xml" namespace="http://foo.org/" /> 

我我发现它们可以在类路径/ META-INF中的一个wsit-client.xml上联机,但我可以引用位于该wsit-client.xml中另一个jar中的xml吗?喜欢的东西:

<import location="classPathResource/WEB-INF/foo.xml" namespace="http://foo.org/" /> 

我想创建一个WSIT-client.xml的谁包含了我所有的web服务的进口,但我要为所有不同的web服务的配置在不同的项目中分离出来。

+0

我发现添加前导斜杠有助于在类路径中搜索文件,但它不适用于/foo.xml或/WEB-INF/foo.xml。我也发现该位置使用网址。 – 2010-10-25 08:32:30

回答

1

我已经在WSIT-client.xml的,现在我可以定义位置=创建的URLStreamHandler固定为“myprotocol://foo.xml”

我使用Spring的PathMatchingResourcePatternResolver找到我的xml文件在另一个项目/罐子里。

public class Handler extends URLStreamHandler { 

@Override 
protected URLConnection openConnection(URL u) throws IOException { 
    PathMatchingResourcePatternResolver resolver = new PathMatchingResourcePatternResolver(); 
    final URL resourceUrl = resolver.getResource(u.getPath()).getURL(); 
    if (resourceUrl == null) { 
     throw new IOException(String.format("File %s not found on the classpath", u.getFile())); 
    } 
    return resourceUrl.openConnection(); 
} 
} 

我不使用VM参数来定义处理程序,但我实现了一个URLStreamHandlerFActory在这里URL to load resources from the classpath in Java

更多信息如何编写自己的协议处理程序可以找到这个网站,如解释说: http://java.sun.com/developer/onlineTraining/protocolhandlers/

我仍然有1个项目包含单个wsit-client.xml引用所有我的Web服务配置,但至少我已经设法分开不同Maven项目中所有不同服务的配置。

相关问题