2010-10-21 25 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項目中所有不同服務的配置。

相關問題