Don't seem to know where (what directory - source or classes) to properly use wsgen against my WebService class...
Create a sample document literal based WebService:
package hello;
import javax.jws.WebSer开发者_StackOverflow中文版vice;
@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.
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?
When I tried it inside:
/code/jaxws_sample/src/wsgen -cp . hello.HelloWorld
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?
Thank you for taking the time to read this.
It looks like you have to compile the files into class files first and then feed them to 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
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.
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.
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
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.
@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
First, you need to create the directory "jaxws" under your "hello" directory.
Then, try running this command from the "/code/jws_sample" directory:
wsgen -keep -cp classes/ -s src/ HelloWorld
The -s command tells the generator where to place the source files.
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.
It's strange that your generated class files are not in /classes/hello/ as your package says...
Well, considering that your class files IS in /classes/hello/HelloWorld.class as it should be, all you have to do from your classes folder is:
wsgen -keep -cp . -d . -s ../src hello.HelloWorld
Just checked and worked fine for me. Remebember, call CMD from your classes folder.
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 -verbose option is to show the logs.<> The -cp option is in case your current working directory is not same a where the .class files are present. The -s is for destination source files. The -keep option is to keep generated the files.
精彩评论