Java 在哪里使用 wsgen?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/6460258/
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
Where to use wsgen?
提问by PacificNW_Lover
Don't seem to know where (what directory - source or classes) to properly use wsgen against my WebService class...
似乎不知道在哪里(什么目录 - 源或类)正确使用 wsgen 对我的 WebService 类...
Create a sample document literal based WebService:
创建一个基于 WebService 的示例文档文字:
package hello;
import javax.jws.WebService;
@WebService
public class HelloWorld {
public void sayHello() {
System.out.println("Welcome to JAX-WS 2!");
}
}
Created the Publisher like this:
像这样创建发布者:
package hello;
import javax.xml.ws.Endpoint;
public class Publisher {
public static void main(String[] args) {
Endpoint.publish("http://localhost:8080/jaxws/hello", new HelloWorld());
}
}
Using Eclipse Helios, I automatically build both of these files as *.classes underneath the corresponding classes directory.
使用 Eclipse Helios,我自动将这两个文件构建为相应类目录下的 *.classes。
So, from the filesystem, my project looks like this:
因此,从文件系统来看,我的项目如下所示:
/code/jws_sample
|
src
|
hello
|
HelloWorld.java
Publisher.java
|
classes
|
HelloWorld.class
Publisher.class
In which directory would I run wsgen?
我将在哪个目录中运行 wsgen?
When I tried it inside:
当我在里面尝试时:
/code/jaxws_sample/src/wsgen -cp . hello.HelloWorld
/code/jaxws_sample/src/wsgen -cp 。你好。你好世界
Received:
已收到:
Class not found: "hello.HelloWorld"
Usage: WSGEN [options] <SEI>
where [options] include:
-classpath <path> specify where to find input class files
-cp <path> same as -classpath <path>
-d <directory> specify where to place generated output files
-extension
allow vendor extensions - functionality not specified
by the specification. Use of extensions may
result in applications that are not portable or
may not interoperate with other implementations
-help display help
-keep keep generated files
-r <directory> resource destination directory, specify where to
place resouce files such as WSDLs
-s <directory> specify where to place generated source files
-verbose output messages about what the compiler is doing
-version print version information
-wsdl[:protocol] generate a WSDL file. The protocol is optional.
Valid protocols are [soap1.1, Xsoap1.2],
the default is soap1.1.
The non stanadard protocols [Xsoap1.2]
can only be used in conjunction with the
-extension option.
-servicename <name> specify the Service name to use in the generated WSDL
Used in conjunction with the -wsdl option.
-portname <name> specify the Port name to use in the generated WSDL
Used in conjunction with the -wsdl option.
Examples:
wsgen -cp . example.Stock
wsgen -cp . example.Stock -wsdl -servicename {http://mynamespace}MyService
It actually does show me the WSDL in a browser and also when I tried to issue the wsgen command from $MyProject/classes it actually did create a jaxws folder with the SayHelloResponse.class files but not the SayHelloResponse.java files?
它实际上确实在浏览器中向我显示了 WSDL,而且当我尝试从 $MyProject/classes 发出 wsgen 命令时,它实际上确实创建了一个包含 SayHelloResponse.class 文件的 jaxws 文件夹,而不是 SayHelloResponse.java 文件?
Thank you for taking the time to read this.
感谢您抽出时间来阅读。
回答by Jeffrey Kevin Pry
It looks like you have to compile the files into class files first and then feed them to wsgen.
看起来您必须先将文件编译为类文件,然后再将它们提供给 wsgen。
classpath <path> specify where to find input **class files**
I could be wrong, but I believe I had to do the same in the past.
我可能是错的,但我相信我过去也必须这样做。
Thanks,
谢谢,
Jeffrey Kevin Pry
杰弗里·凯文·普里
回答by Jeff West
You need to enable '-keep' and you can optionally specify '-s /path/to/src' to save the JAXWS generated files. Since these are generated files, best practice typically guides you to not keep the files around and to only generate them for packaging. The downside of keeping the files and perhaps editing them is that if you regenerate the files your changes could be lost.
您需要启用“-keep”,并且可以选择指定“-s /path/to/src”来保存 JAXWS 生成的文件。由于这些是生成的文件,因此最佳实践通常会指导您不要保留这些文件,而仅生成用于打包的文件。保留文件并可能对其进行编辑的缺点是,如果您重新生成文件,您的更改可能会丢失。
For example, I have a JAX-WS endpoint that is defined in a Maven project and the WSGEN goal is called each time the service is being packaged.
例如,我在 Maven 项目中定义了一个 JAX-WS 端点,每次打包服务时都会调用 WSGEN 目标。
回答by moeabdol
you need to run wsgen against your sei class file not the source file. cd out of the src directory and into the class directory and wsgen against HelloWorld.class
您需要针对 sei 类文件而不是源文件运行 wsgen 。cd 出 src 目录并进入 class 目录和 wsgen 针对 HelloWorld.class
回答by Ascalonian
First, you need to create the directory "jaxws" under your "hello" directory.
首先,您需要在“hello”目录下创建目录“jaxws”。
Then, try running this command from the "/code/jws_sample" directory:
然后,尝试从“/code/jws_sample”目录运行此命令:
wsgen -keep -cp classes/ -s src/ HelloWorld
The -scommand tells the generator where to place the source files.
该-s命令告诉发电机在何处放置源文件。
This was created using a script I use here at work and could not actually test this out before submitting. However, I hope this gives you some direction.
这是使用我在工作中使用的脚本创建的,在提交之前无法实际测试它。不过,我希望这能给你一些指导。
回答by PFROLIM
It's strange that your generated class files are not in /classes/hello/ as your package says...
奇怪的是,您生成的类文件不在 /classes/hello/ 中,正如您的包所说...
Well, considering that your class files IS in /classes/hello/HelloWorld.class as it should be, all you have to do from your classes folderis:
好吧,考虑到您的类文件应该在 /classes/hello/HelloWorld.class 中,您只需从 classes 文件夹中执行以下操作:
wsgen -keep -cp . -d . -s ../src hello.HelloWorld
wsgen -keep -cp 。-d。-s ../src hello.HelloWorld
Just checked and worked fine for me. Remebember, call CMD from your classes folder.
刚刚检查并为我工作正常。记住,从您的类文件夹中调用 CMD。
回答by Pujan Srivastava
A bit late answer but I may help others. I am using this script to generate WSDL and XSD when required (Windows Only). Can be easily prepared for Linux and Mac. I am using glassfish appserver's library. You can replace these libraries with yours app server or bare libs.
回答有点晚,但我可以帮助其他人。我正在使用此脚本在需要时生成 WSDL 和 XSD(仅限 Windows)。可以很容易地为 Linux 和 Mac 准备。我正在使用 glassfish appserver 的库。你可以用你的应用服务器或裸库替换这些库。
@echo off
set WSGEN="C:\Java\jdk1.6.0_39\bin\wsgen.exe"
set J1="C:\Java\jdk1.6.0_39\lib\tools.jar"
set J2="C:\Java\glassfish-3.1.2.2\glassfish\modules\webservices-osgi.jar"
set J3="C:\Java\glassfish-3.1.2.2\glassfish\modules\endorsed\webservices-api-osgi.jar"
set J4="C:\Java\glassfish-3.1.2.2\glassfish\modules\jaxb-osgi.jar"
set J5="C:\Java\glassfish-3.1.2.2\glassfish\modules\endorsed\jaxb-api-osgi.jar"
set J6="C:\Java\glassfish-3.1.2.2\glassfish\modules\javax.ejb.jar"
set J7="D:\NetBeansProjects\OTP\target\OTP-1.0\WEB-INF\lib\commons-lang3-3.1.jar"
set J8="D:\NetBeansProjects\OTP\target\OTP-1.0\WEB-INF\lib\commons-codec-1.8.jar"
set OUTPUT_DIR="D:\NetBeansProjects\OTP"
@echo on
%WSGEN% -classpath %J1%;%OUTPUT_DIR%\target\classes;%J2%;%J3%;%J4%;%J5%;%J6%;%J7%;%J8%; -d %OUTPUT_DIR%\jax-ws -Xendorsed -keep -wsdl -r %OUTPUT_DIR%\jax-ws -s %OUTPUT_DIR%\jax-ws -verbose com.avalant.ws.GenerateOTPWS
回答by nkrust
This is very late reply but for benefit of others:
这是很晚的答复,但为了他人的利益:
wsgen -verbose -keep -cp <folder with .class files> hello.HelloWorld -s <folder where u want the generated artifacts>
The -verboseoption is to show the logs.<> The -cpoption is in case your current working directory is not same a where the .class files are present. The -sis for destination source files. The -keepoption is to keep generated the files.
该-verbose选项来显示日志。<>的-cp选项的情况下,当前的工作目录是不是哪里的.class文件都存在同样的一个。该-s对于目标的源文件。该-keep选项是为了保持生成的文件。