wsimport与maven失败了

时间:2013-01-31 17:22:02

标签: web-services java-ee maven netbeans

我正在尝试使用maven和netbeans(7.2)创建一个ssl webservice客户端。 web服务非常完美,我使用ant项目测试它。

当我尝试构建项目并生成webservice存根时,我收到此错误:

Failed to execute goal org.jvnet.jax-ws-commons:jaxws-maven-plugin:2.2:wsimport (wsimport-generate-test_project_ws_v1) on project mavenproject3: Error executing: wsimport [-keep, -s, C:\Users\no_name\Documents\NetBeansProjects\mavenproject3\target\generated-sources\jaxws-wsimport, -verbose, -encoding, UTF-8, -extension, -Xnocompile, -catalog, C:\Users\no_name\Documents\NetBeansProjects\mavenproject3\src\jax-ws-catalog.xml, -wsdllocation, https://localhost:8181/test_project_ws_v1/test_project_ws_v1?wsdl, file:/C:/Users/no_name/Documents/NetBeansProjects/mavenproject3/src/wsdl/localhost_8181/test_project_ws_v1/test_project_ws_v1.wsdl]: UndeclaredThrowableException: javax.xml.bind.annotation.XmlElementRef.required() -> [Help 1]

这是我的pom(由netbeans生成)

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>

  <groupId>com.procc</groupId>
  <artifactId>mavenproject3</artifactId>
  <version>1.0-SNAPSHOT</version>
  <packaging>jar</packaging>

  <name>mavenproject3</name>
  <url>http://maven.apache.org</url>
  <build>
    <resources>
      <resource>
        <targetPath>META-INF</targetPath>
        <directory>src</directory>
        <includes>
          <include>jax-ws-catalog.xml</include>
          <include>wsdl/**</include>
        </includes>
      </resource>
      <resource>
        <directory>src/main/resources</directory>
      </resource>
    </resources>
    <plugins>
      <plugin>
        <groupId>org.jvnet.jax-ws-commons</groupId>
        <artifactId>jaxws-maven-plugin</artifactId>
        <version>2.2</version>
        <executions>
          <execution>
            <goals>
              <goal>wsimport</goal>
            </goals>
            <configuration>
              <wsdlFiles>
                <wsdlFile>localhost_8181/test_project_ws_v1/test_project_ws_v1.wsdl</wsdlFile>
              </wsdlFiles>
              <wsdlLocation>https://localhost:8181/test_project_ws_v1/test_project_ws_v1?wsdl</wsdlLocation>
              <staleFile>${project.build.directory}/jaxws/stale/test_project_ws_v1.stale</staleFile>
            </configuration>
            <id>wsimport-generate-test_project_ws_v1</id>
            <phase>generate-sources</phase>
          </execution>
        </executions>
        <dependencies>
          <dependency>
            <groupId>javax.xml</groupId>
            <artifactId>webservices-api</artifactId>
            <version>1.4</version>
          </dependency>
        </dependencies>
        <configuration>
          <sourceDestDir>${project.build.directory}/generated-sources/jaxws-wsimport</sourceDestDir>
          <xnocompile>true</xnocompile>
          <verbose>true</verbose>
          <extension>true</extension>
          <catalog>${basedir}/src/jax-ws-catalog.xml</catalog>
        </configuration>
      </plugin>
    </plugins>
  </build>
  <properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
  </properties>

  <dependencies>
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>3.8.1</version>
      <scope>test</scope>
    </dependency>
    <dependency>
      <groupId>com.sun.xml.ws</groupId>
      <artifactId>webservices-rt</artifactId>
      <version>1.4</version>
      <scope>compile</scope>
    </dependency>
  </dependencies>
</project>

感谢。

3 个答案:

答案 0 :(得分:0)

我最近遇到了同样的错误。

似乎发生这种情况是因为 wsimport jaxb 2.1 2.2 版本相混淆。

我能够通过编辑项目 pom.xml 并在每个导入的wsdl的配置中添加<target>2.1</target>标记来正确生成Web服务源,如下所示:

             <execution>
                <goals>
                   <goal>wsimport</goal>
                </goals>
                <configuration>
                   <wsdlFiles>
                      <wsdlFile>path/to/file.wsdl</wsdlFile>
                   </wsdlFiles>
                   <wsdlLocation>http://path/to/webservice?wsdl</wsdlLocation>
                   <staleFile>path/to/file.stale</staleFile>
                   <target>2.1</target>
                </configuration>
                <id>wsimport-generate-WebServiceName</id>
                <phase>generate-sources</phase>
             </execution>

希望无论谁遇到这个问题都会有所帮助。

答案 1 :(得分:0)

我们遇到了类似的问题。在执行wsimport时,我们收到命令行错误,指出-encoding是一个无效的参数。

查看POM和jaxws-maven-plugin的插件部分,存在以下依赖关系:

<dependencies>
    <dependency>
        <groupId>com.sun.xml.ws</groupId>
        <artifactId>jaxws-tools</artifactId>
        <version>2.2.5</version>
   </dependency>
</dependencies>

删除此问题解决了这个问题。我们还使用了jaxws-maven-plugin的2.3版本

答案 2 :(得分:0)

我可以在一台机器上构建但不能在另一台机器上构建 - 问题是由环境变量引起的

检查您的maven环境变量, M2 M2_HOME

M2_HOME - &#34;&lt; Apache-maven-root-directory&gt;&#34;例如(&#34; C:\工具\ APACH-行家&#34)

M2 - &#34;% M2_HOME %\ bin&#34; (对于Windows机器)