【问题标题】:How to generate @Stateless using wsimport如何使用 wsimport 生成 @Stateless
【发布时间】:2016-09-12 17:22:35
【问题描述】:

我有一个 EJB 项目(在 Websphere 中运行),它也是一个 WebService 客户端。以前,我们使用wsimport 命令手动创建客户端类。现在我们想使用JAX-WS Maven Plugin,目标jaxws:wsimport 来自动化这个过程。

这一代几乎是完美的,除了一个事实:webservice 类(带有注释@WebService)也应该有@Stateless 注释。如果没有这个,Eclipse 会抱怨 EJB 模块中的@WebService 注释只能用于无状态会话 bean。实际上,这些类的早期版本(可能是使用手动 wsimport 创建的)具有 @Stateless 注释。

我想它应该有一些配置告诉wsimport 以将类生成为无状态。但是,我在 wsimport 文档和 Maven 插件中都没有找到它。

下面我展示了我的 POM 配置:

<properties>
    <wsdl.dirs>${basedir}/src/main/resources/META-INF</wsdl.dirs>
    <wsdl.package.basic>com.porto.sinistro.orcamentomultiempresa</wsdl.package.basic>
</properties>

<plugin>
    <groupId>org.jvnet.jax-ws-commons</groupId>
    <artifactId>jaxws-maven-plugin</artifactId>
    <version>2.3</version>
    <executions>

        <!--
        Other executions, using other WSDL files.
        -->

        <execution>
            <id>wsdl-cartaAutorizacao-exec</id>
            <goals>
                <goal>wsimport</goal>
            </goals>
            <configuration>
                <packageName>${wsdl.package.basic}.upload.cartaAutorizacao.client</packageName>
                <wsdlFiles>
                    <wsdlFile>${wsdl.dirs}/CartaAutorizacaoWSService.wsdl</wsdlFile>
                </wsdlFiles>
                <wsdlLocation>META-INF/CartaAutorizacaoWSService.wsdl</wsdlLocation>
            </configuration>
        </execution> 

    </executions>

    <configuration> 
        <bindingDirectory>${basedir}/src/main/java</bindingDirectory>
        <sourceDestDir>${basedir}/src/main/java</sourceDestDir>
        <verbose>true</verbose>
        <target>2.0</target>
        <xnocompile>true</xnocompile>
    </configuration>

    </plugin>
</plugins>

对于上面提到的WSDL,Webservice类有这样的形式:

@WebService(name = "CartaAutorizacaoWS", targetNamespace = "http://client.ws.soma.upload.sinistro.porto.com/cartaautorizacao")
// Where is the @Stateless?
public interface CartaAutorizacaoWS {
    // ...
}

要生成@StatelessWebServices,应该做哪些配置?

谢谢,

拉斐尔·阿方索

【问题讨论】:

    标签: maven wsimport


    【解决方案1】:

    我使用 ANT 找到了我的解决方案。

    我的 POM 文件改为:

    <plugin>
        <groupId>org.jvnet.jax-ws-commons</groupId>
        <artifactId>jaxws-maven-plugin</artifactId>
        <version>2.3</version>
        <executions>
    
            <!--
            Other executions, using other WSDL files.
            -->
    
            <execution>
                <id>wsdl-cartaAutorizacao-exec</id>
                <goals>
                    <goal>wsimport</goal>
                </goals>
                <configuration>
                    <packageName>${wsdl.package.basic}.upload.cartaAutorizacao.client</packageName>
                    <wsdlFiles>
                        <wsdlFile>${wsdl.dirs}/CartaAutorizacaoWSService.wsdl</wsdlFile>
                    </wsdlFiles>
                    <wsdlLocation>META-INF/CartaAutorizacaoWSService.wsdl</wsdlLocation>
                </configuration>
            </execution> 
    
        </executions>
    
        <configuration> 
            <bindingDirectory>${basedir}/src/main/java</bindingDirectory>
            <sourceDestDir>${basedir}/src/main/java</sourceDestDir>
            <verbose>true</verbose>
            <target>2.0</target>
            <xnocompile>true</xnocompile>
        </configuration>
    
        </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-antrun-plugin</artifactId>
                <version>1.8</version>
                <executions>
                    <execution> <!-- Eclipse error message. See below. -->
                        <id>inject-stateless</id>
                        <phase>generate-sources</phase>
                        <goals>
                            <goal>run</goal>
                        </goals>
                        <configuration>
                            <tasks>
                                <ant antfile="${basedir}/inject-stateless.xml" target="main" />
                            </tasks>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
    
    </plugins>
    

    我的 ANT 脚本:

    <?xml version="1.0"?>
    <project default="main" basedir=".">
        <property name="base.source.dir" value="./src/main/java/com/porto/sinistro/orcamentomultiempresa"/>
    
        <target name="main" >
            <antcall target="replace">
                <param name="file.path" value="client/controlevagas/ControleVagasWeb.java"/>
            </antcall>
            <antcall target="replace">
                <param name="file.path" value="client/somavistoriaweb/VistoriaWeb.java"/>
            </antcall>
            <!-- Other java files ... -->
        </target>
    
        <target name="replace">
            <property name="java.file" location="${base.source.dir}/${file.path}"/>
            <echo message="Ajustando classe ${java.file}"/>
            <replace file="${java.file}">
                <replacetoken><![CDATA[import javax.jws.WebMethod;]]></replacetoken>
                <replacevalue><![CDATA[import javax.ejb.Stateless;
    import javax.jws.WebMethod;]]></replacevalue>
            </replace>
            <replace file="${java.file}">
                <replacetoken><![CDATA[public interface]]></replacetoken>
                <replacevalue><![CDATA[@Stateless
    public interface]]></replacevalue>
            </replace>
        </target>
    
    </project>
    

    虽然我的 Eclipse 显示错误消息 生命周期配置未涵盖插件执行:org.apache.maven.plugins:maven-antrun-plugin:1.8:run (execution: inject-stateless, phase: generate-sources),我发现它对 Maven 执行没有影响。见我的帖子Maven (m2e) is not executing ant task

    【讨论】:

      猜你喜欢
      • 2012-06-27
      • 1970-01-01
      • 2012-08-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多