2011-06-23 43 views
7

好像不知道在哪里(哪个目录 - 源或类)正确使用WSGEN对我的WebService类...在哪里可以使用wsgen?

创建一个基于文本样本文档的WebService:

package hello; 

import javax.jws.WebService; 

@WebService 
public class HelloWorld { 

public void sayHello() { 
     System.out.println("Welcome to JAX-WS 2!"); 
    } 
} 

创建发布像这样:

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()); 
    } 
} 

使用Eclipse Helios,我会自动将这两个文件构建为相应类目录下的* .classes。

所以,从文件系统,我的项目是这样的:

/code/jws_sample 
      | 
      src 
      | 
       hello 
        | 
        HelloWorld.java 
        Publisher.java 
      | 
      classes 
        | 
        HelloWorld.class 
        Publisher.class 

在该目录中我会运行WSGEN?

当我想这里面:

/代码/ jaxws_sample/src目录/ WSGEN -cp。 hello.HelloWorld

收稿日期:

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 &lt;path&gt; 

    -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 

它实际上并告诉我在浏览器中的WSDL,也当我试图从发行$ MyProject的/班WSGEN命令时,它实际上没有建立与一个JAXWS文件夹SayHelloResponse.class文件但不包含SayHelloResponse.java文件?

感谢您花时间阅读本文。

回答

7

它看起来像你必须先将文件编译成类文件,然后将它们提供给wsgen。

classpath <path>   specify where to find input **class files** 

我可能是错的,但我相信我必须在过去也这样做。

感谢,

杰弗里·凯文撬

+0

我这样做了...... Eclipse创建了相应的类目录,并像这样做:$ MyProject/classes/wsgen -cp。 hello.HelloWorld确实有效,但它会将生成的存根放入类dir中。如何使用-d将它们放入src目录中? –

1

您需要启用 '-keep',你可以选择指定 '-s /路径/到/ src' 中保存JAXWS生成的文件。由于这些是生成的文件,因此最佳做法通常会指导您不要将文件保留在周围,并且仅生成它们以供打包。保留文件或编辑文件的缺点是,如果重新生成文件,可能会导致更改丢失。

例如,我有一个在Maven项目中定义的JAX-WS端点,每次打包服务时都会调用WSGEN目标。

1

您需要针对您的sei类文件而不是源文件运行wsgen。 cd出src目录,并进入类目录和wsgen反对HelloWorld.class

0

首先,您需要在“hello”目录下创建目录“jaxws”。

然后,尝试从“/代码/ jws_sample”目录运行此命令:

wsgen -keep -cp classes/ -s src/ HelloWorld 

-s命令告诉发电机在何处放置源文件。

这是使用我在工作中使用的脚本创建的,在提交之前无法真正测试这个脚本。不过,我希望这给你一些方向。

0

很奇怪,你生成的类文件不在/班/你好/作为您的包说...

好,考虑到你的类文件/classes/hello/HelloWorld.class是理所应当是,所有你必须做的从你的类文件夹是:

wsgen -keep -cp。 -d。 -s ../src hello.HelloWorld

刚刚检查过,对我来说工作得很好。 Remebember,从你的classes文件夹中调用CMD

1

有点迟来的答案,但我可以帮助别人。我正在使用此脚本在需要时生成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 
0

这是非常晚的答复,但对别人的好处:

wsgen -verbose -keep -cp <folder with .class files> hello.HelloWorld -s <folder where u want the generated artifacts> 

-verbose选项来显示日志。 <> -cp选项用于防止当前工作目录与.class文件存在的位置不同。 -s用于目标源文件。 -keep选项是保持生成的文件。

+0

不起作用。仍然给出相同的错误 – bademba