定位.jar文件中的内部目录 - java [英] Targeting inner directories within a .jar file -- java
问题描述
我有一个非常好的Web服务客户端,其中有一行定义了WSDL的位置:
I have a web service client which works perfectly fine, within which there is a line that defines the location of the WSDL:
@WebServiceClient(name = "CReceiveMOMessageService",
targetNamespace = "http://...",
wsdlLocation = "CReceiveMOMessageService.wsdl")
代码段应该作为可运行的JAR导出,并且可以在远程位置工作。
The code piece should be exported as a runnable JAR and is intended to work on a remote location.
当我如上所述定义WSDL的位置时,它会在我运行JAR文件的目录中查找WSDL文件。相反,我想要做的是将WSDL文件添加到项目文件夹并在此之后导出为JAR,并以指向WSDL的方式配置 wsdlLocation
参数在JAR文件中。
When I define the location of the WSDL as above, it looks for a WSDL file at the directory in which I run the JAR file. Instead what I would like to do is to add the WSDL file to the project folder and export as JAR after that, and configure wsdlLocation
parameter in a way that it points to the WSDL within the JAR file.
如何实现?
推荐答案
可以将WSDL添加到JAR。似乎惯例是将WSDL放在JAR的 META-INF / wsdl
位置(尽管Oracle工具似乎支持 META-INF / wsdls
(参见第9点例如,这个Oracle教程。
It is possible to add the WSDL to the JAR. It seems that the convention is to place the WSDL in the JAR at the META-INF/wsdl
location (although Oracle tools seem to favor META-INF/wsdls
(see point 9 of this Oracle tutorial for example).
我没有使用Eclipse的Oracle Enterprise Pack,我猜OEPE ClientGen任务正确生成了指定在JAR中打包WSDL时的客户端类,但我不认为它与传递 -wsdllocation META-INF / wsdls / YourService.wsdl
参数相同运行 wsimport.exe
:
I haven't used the Oracle Enterprise Pack for Eclipse and I guess the OEPE ClientGen task does the correct generation of the client classes when you specify to package the WSDL inside the JAR but I don't think it's the same as passing a -wsdllocation META-INF/wsdls/YourService.wsdl
parameter when running wsimport.exe
:
wsimport.exe
将输出 @ WebServiceClient(... wsdlLocation =META-INF / wsdls / YourService.wsdl)
但通常也会生成这样的代码在类的静态初始值设定项中:
wsimport.exe
will output @WebServiceClient(... wsdlLocation = "META-INF/wsdls/YourService.wsdl")
but will also normally generate code like this in the static initializer of the class:
baseUrl = YourService.class.getResource(".");
url = new URL(baseUrl, "META-INF/wsdls/YourService.wsdl");
它仍将指向一个根文件夹,然后它将所提供的WSDL路径添加到最终得到一个不存在的路径。
which will still point to a root folder to which it then adds the provided WSDL path to finally get a non existent path.
您必须在生成后更改类,以包含类似的内容:
You will have to change the class after it's generated to include something like this instead:
url = YourService.class.getClassLoader().getResource("META-INF/wsdls/YourService.wsdl");
现在将指向JAR。当然,在构建客户端JAR时,您必须在该位置打包WSDL。
which will now point within the JAR. Off course you must pack the WSDL at that location when building the client JAR.
这篇关于定位.jar文件中的内部目录 - java的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!