首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >将wsit client.xml中的位置导入到另一个jar中的文件,使用URL字符串在类路径上定位文件

将wsit client.xml中的位置导入到另一个jar中的文件,使用URL字符串在类路径上定位文件
EN

Stack Overflow用户
提问于 2010-10-21 20:52:10
回答 1查看 1.1K关注 0票数 0

通常,wsit client.xml的import语句如下所示:

代码语言:javascript
复制
<import location="foo.xml" namespace="http://foo.org/" />

我发现它们可以在classpath/META-INF上的一个wsit client.xml中在线,但是我可以引用位于该wsit client.xml中的另一个jar中的xml吗?类似于:

代码语言:javascript
复制
<import location="classPathResource/WEB-INF/foo.xml" namespace="http://foo.org/" />

我想创建一个wsit client.xml,它包含我所有who服务的导入,但我想将所有不同who服务的配置分离到不同的项目中。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2010-10-27 16:05:42

现在我可以定义location="myprotocol://foo.xml“,通过在wsit client.xml中创建URLStreamHandler来修复它

我使用了spring在另一个项目/ PathMatchingResourcePatternResolver中定位我的xml文件。

代码语言:javascript
复制
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参数来定义处理程序,但我实现了一个类似于这里解释的URL to load resources from the classpath in Java的URLStreamHandlerFActory

有关编写自己的协议处理程序的更多信息,请访问以下站点:http://java.sun.com/developer/onlineTraining/protocolhandlers/

我仍然有一个项目,它包含单个wsit client.xml,其中引用了我所有的web服务配置,但至少我已经设法将不同maven项目中所有不同服务的配置分开。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/3987634

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档