【问题标题】:Where to use wsgen?在哪里使用wsgen?
【发布时间】:2011-06-23 20:29:57
【问题描述】:

似乎不知道在哪里(什么目录 - 源或类)正确使用 wsgen 来处理我的 WebService 类...

创建一个基于 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?

当我在里面尝试时:

/code/jaxws_sample/src/wsgen -cp 。你好.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/classes 发出 wsgen 命令时,它实际上确实创建了一个包含 SayHelloResponse.class 文件而不是 SayHelloResponse.java 文件的 jaxws 文件夹?

感谢您抽出宝贵时间阅读本文。

【问题讨论】:

    标签: java jax-ws wsgen


    【解决方案1】:

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

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

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

    谢谢,

    杰弗里·凯文·普瑞

    【讨论】:

    • 我做到了... Eclipse 创建了相应的类目录并这样做: $MyProject/classes/wsgen -cp 。 hello.HelloWorld 确实有效,但它将生成的存根放在类目录中。如何使用 -d 将它们放在 src 目录中?
    【解决方案2】:

    您需要启用“-keep”,并且可以选择指定“-s /path/to/src”来保存 JAXWS 生成的文件。由于这些是生成的文件,最佳实践通常会指导您不要保留这些文件,而只生成它们用于打包。保留文件并可能对其进行编辑的缺点是,如果您重新生成文件,您的更改可能会丢失。

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

    【讨论】:

      【解决方案3】:

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

      【讨论】:

        【解决方案4】:

        回答有点晚,但我可以帮助其他人。我在需要时使用此脚本生成 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
        

        【讨论】:

          【解决方案5】:

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

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

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

          -s 命令告诉生成器将源文件放在哪里。

          这是使用我在工作中使用的脚本创建的,在提交之前无法实际测试。不过,我希望这能给你一些指导。

          【讨论】:

            【解决方案6】:

            奇怪的是,你生成的类文件不像你的包所说的那样在 /classes/hello/ 中......

            好吧,考虑到您的类文件应该在 /classes/hello/HelloWorld.class 中,您只需从您的类文件夹中做:

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

            刚刚检查并为我工作正常。请记住,从您的课程文件夹中调用 CMD

            【讨论】:

              【解决方案7】:

              这是很晚的回复,但为了他人的利益:

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

              -verbose 选项用于显示日志。 -cp 选项是为了以防您当前的工作目录与 .class 文件所在的位置不同。 -s 用于目标源文件。 -keep 选项是保留生成的文件。

              【讨论】:

                猜你喜欢
                • 1970-01-01
                • 1970-01-01
                • 1970-01-01
                • 2016-09-24
                • 1970-01-01
                • 2012-10-07
                • 2018-07-23
                • 1970-01-01
                • 1970-01-01
                相关资源
                最近更新 更多