Java wsimport -clientjar 在(默认包)中生成类
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/18967016/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
wsimport -clientjar generates classes in (default package)
提问by Bubumuk
I'm using the -clientjar wsimport parameter to export my WebService into a jar.
我正在使用 -clientjar wsimport 参数将我的 WebService 导出到 jar 中。
>wsimport -d C:\webservice -keep -clientjar webservice.jar http://localhost:8080/WebService?wsdl
A folder with the source code (.java files) and a webservice.jar are created.
创建一个包含源代码(.java 文件)和 webservice.jar 的文件夹。
The jar looks like this:
罐子看起来像这样:
com
|
company
|
webservice
|
a bunch of .class files
META-INF
|
wsdl
|
wsdl file
However, when I put it on the WEB-INF/lib folder in my project, the classes are in the (default package)and are named like
但是,当我将它放在项目中的 WEB-INF/lib 文件夹中时,这些类位于(默认包)中并命名为
com\company\webservice\file.class
I can't understand why. I've also used the -p parameter to specify a package name but it doesn't work.
我不明白为什么。我还使用了 -p 参数来指定包名称,但它不起作用。
Any clues?
有什么线索吗?
采纳答案by Stas
There are two options of achieving this , both works like a charm. And both options can be automated from ant\gradle you name it .
有两种选择可以实现这一点,两者都像魅力一样。并且这两个选项都可以从您命名的 ant\gradle 自动化。
1.To use -clientjar and then to repack the sources
1.使用-clientjar然后重新打包源
2.Manually insert the wsdl into jar and customize the wsdLlocation URL
2.手动将wsdl插入jar中,自定义wsdLlocation URL
Assuming you have C:\WSDL\SO\stas.wsdl (I was running on windows)
假设你有 C:\WSDL\SO\stas.wsdl (我在 Windows 上运行)
CD C:\WSDL\SO\
First option
第一个选项
C:\WSDL\SO>wsimport -clientjar StasWebServiceClient.jar stas.wsdl
This creates StasWebServiceClient.jar jar file , but when importing it to eclipse, the sources are not importable , because of the topic problem (default package).
这将创建 StasWebServiceClient.jar jar 文件,但是在将其导入 eclipse 时,由于主题问题(默认包),源代码不可导入。
=> Unzip the jar file to current folder , you can use 7zip, or any other great zip tool , or you can run
=> 将 jar 文件解压缩到当前文件夹,您可以使用 7zip 或任何其他出色的 zip 工具,或者您可以运行
C:\WSDL\SO>jar xf StasWebServiceClient.jar
to unzip the jar .
解压缩 jar 。
Folder hierarchy should look like
文件夹层次结构应如下所示
C:\WSDL\SO\META-INF
C:\WSDL\SO\stas.wsdl(original wsdl)
C:\WSDL\SO\StasWebServiceClient.jar(generated jar file)
C:\WSDL\SO\META-INF\wsdl(created by -clientjar)
C:\WSDL\SO\META-INF\wsdl\stas.wsdl(copied by -clientjar)
C:\WSDL\SO\com\...
/* all generated classes\sources */
C:\WSDL\SO\com\...
=> Do
=> 做
C:\WSDL\SO>jar -cvf StasWebServiceClientCorrect.jar com META-INF
this will create another jar , StasWebServiceClientCorrect.jar , which now has the correct packaging .
这将创建另一个 jar StasWebServiceClientCorrect.jar,它现在具有正确的包装。
Second option
第二种选择
=> Run wsimport
=> 运行 wsimport
C:\WSDL\SO>wsimport -keep stas.wsdl
to generate the code .I always like to have -keep option there , but it's up to you.
生成代码。我总是喜欢在那里使用 -keep 选项,但这取决于您。
=> create META-INF folder
=> 创建 META-INF 文件夹
C:\WSDL\SO>mkdir META-INF
=> Create META-INF/wsdl folder
=> 创建 META-INF/wsdl 文件夹
C:\WSDL\SO>cd META-INF
C:\WSDL\SO\META-INF>mkdir wsdl
=> go one folder up .
=> 上一个文件夹。
C:\WSDL\SO\META-INF>cd ..
=> Copy stas.wsdl file into META-INF\wsdl\stas.wsdl
=> 将 stas.wsdl 文件复制到 META-INF\wsdl\stas.wsdl
C:\WSDL\SO>copy stas.wsdl META-INF\wsdl\stas.wsdl
=> Create a jar archive
=> 创建一个 jar 档案
C:\WSDL\SO>jar -cvf StasWebServiceClient.jar com META-INF
Import the jar to workspace. When you will be creating the actual call to the service , use :
将 jar 导入到工作区。当您要创建对服务的实际调用时,请使用:
StasService stasService = new StasService(StasService.class.getClassLoader().getResource("META-INF/wsdl/stas.wsdl") )
回答by Marc T
I had the same problem. Finally decided not to use the -clientjar option and generated a jar manually with jar.exe and works.
我有同样的问题。最后决定不使用 -clientjar 选项并使用 jar.exe 手动生成一个 jar 并工作。
回答by Bienvenido David
I used -clientjar so it will do all the work for me, but used my favorite file archiver to unzjar and jar it again.
我使用了 -clientjar 所以它会为我做所有的工作,但使用我最喜欢的文件归档器来 unzjar 并再次 jar 它。
回答by peterh
I think the problem here is that -clientjar
option is meant for an entirely different purpose than the OP expects.
我认为这里的问题是该-clientjar
选项的目的与 OP 预期的完全不同。
The purpose of the -clientjar
option is to embed a copy of the WSDL inside the generated artifacts so that it can become part of the application's jar file. The benefit of having a bundled WSDL (and actually using it of course) is that the web service consumer does not have to make a call to the endpoint to download the WSDL every time it initiates itself.
该-clientjar
选项的目的是在生成的工件中嵌入 WSDL 的副本,以便它可以成为应用程序 jar 文件的一部分。拥有捆绑的 WSDL(当然也是实际使用它)的好处是,Web 服务使用者不必在每次启动时调用端点来下载 WSDL。
Links:
链接:
回答by mel3kings
1.) Unzip/unjar clientjar
1.) 解压/解压clientjar
2.) jar file using
2.) jar 文件使用
jar cvf <jarName>.jar <root_folders>
example:
例子:
jar cvf weather.jar com META_INF