当前位置: 首页 > 面试题库 >

尝试在Spring MVC中使用Maven从WSDL生成类时出错

况繁
2023-03-14
问题内容

您好,我尝试按照此示例https://spring.io/guides/gs/consumption-web-
service/
,我在pom.xml文件中收到以下错误

这是我的pom.xml文件,我添加的新部分是注释后的部分<-Web Services->

这是问题所在的部分:

<plugin>
                <groupId>org.jvnet.jaxb2.maven2</groupId>
                <artifactId>maven-jaxb2-plugin</artifactId>
                <executions>
                    <execution>
                        <goals>
                            <goal>generate</goal>
                        </goals>
                    </execution>
                </executions>       
                <configuration>
                    <schemaLanguage>WSDL</schemaLanguage>
                    <generatePackage>hello.wsdl</generatePackage>
                    <forceRegenerate>true</forceRegenerate>
                    <schemas>
                        <schema>
                            <url>http://wsf.cdyne.com/WeatherWS/Weather.asmx?wsdl</url>
                        </schema>
                    </schemas>
                </configuration>
            </plugin>

这是整个pom.xml

<?xml version="1.0" encoding="UTF-8"?>
<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/maven-v4_0_0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>com.pruebaWsCompany</groupId>
    <artifactId>app</artifactId>
    <name>PruebaWSproy</name>
    <packaging>war</packaging>
    <version>1.0.0-BUILD-SNAPSHOT</version>
    <properties>
        <java-version>1.6</java-version>
        <org.springframework-version>3.1.1.RELEASE</org.springframework-version>
        <org.aspectj-version>1.6.10</org.aspectj-version>
        <org.slf4j-version>1.6.6</org.slf4j-version>
    </properties>
    <dependencies>
        <!-- Spring -->
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-context</artifactId>
            <version>${org.springframework-version}</version>
            <exclusions>
                <!-- Exclude Commons Logging in favor of SLF4j -->
                <exclusion>
                    <groupId>commons-logging</groupId>
                    <artifactId>commons-logging</artifactId>
                 </exclusion>
            </exclusions>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-webmvc</artifactId>
            <version>${org.springframework-version}</version>
        </dependency>

        <!-- AspectJ -->
        <dependency>
            <groupId>org.aspectj</groupId>
            <artifactId>aspectjrt</artifactId>
            <version>${org.aspectj-version}</version>
        </dependency>

        <!-- Logging -->
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-api</artifactId>
            <version>${org.slf4j-version}</version>
        </dependency>
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>jcl-over-slf4j</artifactId>
            <version>${org.slf4j-version}</version>
            <scope>runtime</scope>
        </dependency>
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-log4j12</artifactId>
            <version>${org.slf4j-version}</version>
            <scope>runtime</scope>
        </dependency>
        <dependency>
            <groupId>log4j</groupId>
            <artifactId>log4j</artifactId>
            <version>1.2.15</version>
            <exclusions>
                <exclusion>
                    <groupId>javax.mail</groupId>
                    <artifactId>mail</artifactId>
                </exclusion>
                <exclusion>
                    <groupId>javax.jms</groupId>
                    <artifactId>jms</artifactId>
                </exclusion>
                <exclusion>
                    <groupId>com.sun.jdmk</groupId>
                    <artifactId>jmxtools</artifactId>
                </exclusion>
                <exclusion>
                    <groupId>com.sun.jmx</groupId>
                    <artifactId>jmxri</artifactId>
                </exclusion>
            </exclusions>
            <scope>runtime</scope>
        </dependency>

        <!-- @Inject -->
        <dependency>
            <groupId>javax.inject</groupId>
            <artifactId>javax.inject</artifactId>
            <version>1</version>
        </dependency>

        <!-- Servlet -->
        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>servlet-api</artifactId>
            <version>2.5</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>javax.servlet.jsp</groupId>
            <artifactId>jsp-api</artifactId>
            <version>2.1</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>jstl</artifactId>
            <version>1.2</version>
        </dependency>




        <!-- Test -->
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.7</version>
            <scope>test</scope>
        </dependency>        
    </dependencies>
    <build>
        <plugins>
            <plugin>
                <artifactId>maven-eclipse-plugin</artifactId>
                <version>2.9</version>
                <configuration>
                    <additionalProjectnatures>
                        <projectnature>org.springframework.ide.eclipse.core.springnature</projectnature>
                    </additionalProjectnatures>
                    <additionalBuildcommands>
                        <buildcommand>org.springframework.ide.eclipse.core.springbuilder</buildcommand>
                    </additionalBuildcommands>
                    <downloadSources>true</downloadSources>
                    <downloadJavadocs>true</downloadJavadocs>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>2.5.1</version>
                <configuration>
                    <source>1.6</source>
                    <target>1.6</target>
                    <compilerArgument>-Xlint:all</compilerArgument>
                    <showWarnings>true</showWarnings>
                    <showDeprecation>true</showDeprecation>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>exec-maven-plugin</artifactId>
                <version>1.2.1</version>
                <configuration>
                    <mainClass>org.test.int1.Main</mainClass>
                </configuration>
            </plugin>

            <!--WEB SERVICES -->
            <plugin>
                <groupId>org.jvnet.jaxb2.maven2</groupId>
                <artifactId>maven-jaxb2-plugin</artifactId>
                <executions>
                    <execution>
                        <goals>
                            <goal>generate</goal>
                        </goals>
                    </execution>
                </executions>       
                <configuration>
                    <schemaLanguage>WSDL</schemaLanguage>
                    <generatePackage>hello.wsdl</generatePackage>
                    <forceRegenerate>true</forceRegenerate>
                    <schemas>
                        <schema>
                            <url>http://wsf.cdyne.com/WeatherWS/Weather.asmx?wsdl</url>
                        </schema>
                    </schemas>
                </configuration>
            </plugin>

        </plugins>
    </build>
</project>

这是我得到的错误,我尝试在我的spring-tools套件IDE中使用Maven更新,但仍然出现相同的错误

这是错误

Description Resource    Path    Location    Type
Execution default of goal org.jvnet.jaxb2.maven2:maven-jaxb2-plugin:0.12.3:generate failed: A required class was missing while executing org.jvnet.jaxb2.maven2:maven-jaxb2-plugin:0.12.3:generate: com/sun/codemodel/CodeWriter
-----------------------------------------------------
realm =    plugin>org.jvnet.jaxb2.maven2:maven-jaxb2-plugin:0.12.3
strategy = org.codehaus.plexus.classworlds.strategy.SelfFirstStrategy
urls[0] = file:/d:/Users/myUser/.m2/repository/org/jvnet/jaxb2/maven2/maven-jaxb2-plugin/0.12.3/maven-jaxb2-plugin-0.12.3.jar
urls[1] = file:/d:/Users/myUser/.m2/repository/org/jvnet/jaxb2/maven2/maven-jaxb2-plugin-core/0.12.3/maven-jaxb2-plugin-core-0.12.3.jar
urls[2] = file:/d:/Users/myUser/.m2/repository/org/slf4j/slf4j-api/1.7.7/slf4j-api-1.7.7.jar
urls[3] = file:/d:/Users/myUser/.m2/repository/org/apache/commons/commons-lang3/3.2.1/commons-lang3-3.2.1.jar
urls[4] = file:/d:/Users/myUser/.m2/repository/com/sun/org/apache/xml/internal/resolver/20050927/resolver-20050927.jar
urls[5] = file:/d:/Users/myUser/.m2/repository/junit/junit/4.8.1/junit-4.8.1.jar
urls[6] = file:/d:/Users/myUser/.m2/repository/org/codehaus/plexus/plexus-utils/1.5.15/plexus-utils-1.5.15.jar
urls[7] = file:/d:/Users/myUser/.m2/repository/org/jvnet/jaxb2/maven2/maven-jaxb22-plugin/0.12.3/maven-jaxb22-plugin-0.12.3.jar
urls[8] = file:/d:/Users/myUser/.m2/repository/org/glassfish/jaxb/jaxb-runtime/2.2.11/jaxb-runtime-2.2.11.jar
urls[9] = file:/d:/Users/myUser/.m2/repository/org/glassfish/jaxb/jaxb-xjc/2.2.11/jaxb-xjc-2.2.11.jar
urls[10] = file:/d:/Users/myUser/.m2/repository/org/apache/maven/plugin-tools/maven-plugin-annotations/3.2/maven-plugin-annotations-3.2.jar
Number of foreign imports: 5
import: Entry[import org.sonatype.plexus.build.incremental from realm ClassRealm[plexus.core, parent: null]]
import: Entry[import org.codehaus.plexus.util.Scanner from realm ClassRealm[plexus.core, parent: null]]
import: Entry[import org.codehaus.plexus.util.DirectoryScanner from realm ClassRealm[plexus.core, parent: null]]
import: Entry[import org.codehaus.plexus.util.AbstractScanner from realm ClassRealm[plexus.core, parent: null]]
import: Entry[import  from realm ClassRealm[maven.api, parent: null]]

-----------------------------------------------------
 (org.jvnet.jaxb2.maven2:maven-jaxb2-plugin:0.12.3:generate:default:generate-sources)   pom.xml /PruebaWSproy   line 165    Maven Build Problem

+++编辑

我在插件标签的开头使用了此标签,在结尾使用了此标签,我不再遇到这个问题 Execution default of goal org.jvnet.jaxb2.maven2:maven-jaxb2-plugin:0.12.3:generate failed:

这是我如何编辑它

<build>
    <pluginManagement>
    <plugins>
        <plugin>
            <artifactId>maven-eclipse-plugin</artifactId>
            <version>2.9</version>
            <configuration>
                <additionalProjectnatures>
                    <projectnature>org.springframework.ide.eclipse.core.springnature</projectnature>
                </additionalProjectnatures>
                <additionalBuildcommands>
                    <buildcommand>org.springframework.ide.eclipse.core.springbuilder</buildcommand>
                </additionalBuildcommands>
                <downloadSources>true</downloadSources>
                <downloadJavadocs>true</downloadJavadocs>
            </configuration>
        </plugin>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>2.5.1</version>
            <configuration>
                <source>1.6</source>
                <target>1.6</target>
                <compilerArgument>-Xlint:all</compilerArgument>
                <showWarnings>true</showWarnings>
                <showDeprecation>true</showDeprecation>
            </configuration>
        </plugin>

        <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>exec-maven-plugin</artifactId>
            <version>1.2.1</version>
            <configuration>
                <mainClass>org.test.int1.Main</mainClass>
            </configuration>
        </plugin>

        <!--WEB SERVICES -->

        <plugin>
            <groupId>org.jvnet.jaxb2.maven2</groupId>
            <artifactId>maven-jaxb2-plugin</artifactId>
            <version>${project.version}</version>
            <executions>
                <execution>
                    <goals>
                        <goal>generate</goal>
                    </goals>
                </execution>
            </executions>
            <configuration>
                <schemaLanguage>WSDL</schemaLanguage>
                <generatePackage>hello.wsdl</generatePackage>
                <forceRegenerate>true</forceRegenerate>
                <schemas>
                    <schema>
                        <url>http://wsf.cdyne.com/WeatherWS/Weather.asmx?wsdl</url>
                    </schema>
                </schemas>
            </configuration>
        </plugin>
    </plugins>
</pluginManagement>

但是在我更新了Maven之后,没有新的包或类,这应该为我带来新的类和包吗?

++++编辑2

我尝试放置此标签,但仍然没有生成任何类

<plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>jaxws-maven-plugin</artifactId>
                <version>1.12</version>
                <executions>
                    <execution>
                        <goals>
                            <goal>wsimport</goal>
                        </goals>
                        <configuration>
                        <schemaLanguage>WSDL</schemaLanguage>
                        <generateDirectory>D:/Users/myUser/Documents/workspace-sts-3.6.0.RELEASE/ProjectTryWSDL/src/gensrc</generateDirectory>
                        <generatePackage>com.wsdl.src</generatePackage>
                        <schemas>
                            <schema>
                                <url>http://wsf.cdyne.com/WeatherWS/Weather.asmx?wsdl</url>
                            </schema>
                        </schemas>              
                        </configuration>
                    </execution>
                </executions>
            </plugin>

我认为我的文件夹有权通过外部应用程序创建文件夹,还是我需要通过mysefl创建该文件夹?

+ 编辑3

我在generate标签中添加了这条路线

<plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>jaxws-maven-plugin</artifactId>
                <version>1.12</version>
                <executions>
                    <execution>
                        <goals>
                            <goal>wsimport</goal>
                        </goals>
                        <configuration>
                        <schemaLanguage>WSDL</schemaLanguage>
                        <generateDirectory>${project.build.sourceDirectory}/gensrc</generateDirectory>
                        <generatePackage>com.wsdl.src</generatePackage>
                        <schemas>
                            <schema>
                                <url>http://wsf.cdyne.com/WeatherWS/Weather.asmx?wsdl</url>
                            </schema>
                        </schemas>              
                        </configuration>
                    </execution>
                </executions>
            </plugin>

这是我的属性标签

<properties>
    <java-version>1.6</java-version>
    <org.springframework-version>3.1.1.RELEASE</org.springframework-version>
    <org.aspectj-version>1.6.10</org.aspectj-version>
    <org.slf4j-version>1.6.6</org.slf4j-version>
    <project.version>0.12.3</project.version>
</properties>

问题答案:

您需要像下面那样更改配置以生成源。

generateDirectory 是创建源文件的实际目录。

generatePackage 是您从WSDL生成的源文件的软件包名称,因此您应该在其中找到这些软件包子文件夹 generateDirectory

      <configuration>
               <schemaLanguage>WSDL</schemaLanguage>
               <generateDirectory>${project.build.sourceDirectory}/gensrc
                      </generateDirectory>
               <generatePackage>com.wsdl.src</generatePackage>
                <schemas>
                    <schema>
                        <url>http://wsf.cdyne.com/WeatherWS/Weather.asmx?wsdl</url>
                    </schema>
                </schemas>
       </configuration>

您可以用来mvn jaxb2:generateproject/src/gensrc目录内生成源文件。有关可能配置的更多详细信息,请查看此备忘单 :)



 类似资料:
  • 问题内容: 我在配置时无法从WSDL和都存在于同一标准目录中的多个XSD文件生成Java类的问题。 如何在内联XSD中使用jaxb2 maven插件?仅在答案正确地建议使用插件配置中的参数这一点上相关,而该问题确实与内联XSD有关,而我的XSD是外部的。 插件目标参数在此处列出。 我的插件配置是: 我正在用进行测试,但插件忽略了调试输出中看到的 问题答案: 通过检查传递给JAXB XJC的参数的M

  • 我在配置以从WSDL和多个XSD文件生成Java类时遇到问题,这些文件都存在于同一个标准目录。 如何将jaxb2 maven插件与内联XSD一起使用?只因为答案正确地建议在插件配置中使用参数,但这个问题实际上与内联XSD有关,而我的XSD是外部的。 这里列出了插件目标参数。 我的插件配置是: 我正在用

  • 我正在尝试使用pluggin从wsdl创建Java类。 在版本1.5中,这段代码来自WSDL中的Generate classes With jaxb2 maven plugin: 但当使用插件版本2.3.1时,我会出现以下错误: 有人知道如何在这个新的插件版本中使用WSDL文件吗?

  • 我一直在尝试使用Acceleo。我使用Enterprise Architect设计我的类,并将它们导出为XMI。 在Eclipse中,当我试图使用Acceleo生成哪怕是一个简单的类时,我会得到以下错误。 有人能告诉我我做错了什么吗? Im使用:

  • 问题内容: 我有一个带有“逻辑”类的包(例如CheckAuthenticationDataLogic.java,GetVocabulariesLogic.java)。还有另一个类- ApiService.java用于生成wsdl。ApiService.java充满了这样的方法: 如您所见,它只是一个代理方法…所以我想避免做两次相同的工作,而无需编写ApiService.java就直接从逻辑类生成W

  • 问题内容: 我想将我的Maven2构建文件切换到gradle。使用gradle从WSDL + XSD生成Java类似乎没有进一步的文档记录,对此没有gradle插件。我将以下配置与maven一起使用,并搜索等效的gradle。 问题答案: 我解决了…

  • 有几种从wsdl生成java类的方法,例如Apache CXF、JAXB和JAX-WS。 我需要一个解决方案,工作与maven和曲库文件。 我的问题是,我有两个Maven模块A和B。其中一个模块(模块A)包含逻辑类,另一个模块(模块B)包含作为资源的xsd文件。现在我想从逻辑模块(模块A)生成类,xsd文件不应该作为资源添加到此模块。 我已经创建了一个catalag。包含公共名称空间并指向mave

  • 我试图为我的应用程序生成一个签名的APK,但是,我得到了下面的两个错误消息。请看我的Android宣言文件。 我收到以下两条错误消息,请有人帮助我,因为我正在努力生成一个唱歌的APK。我能够构建我的应用程序,但是,在尝试创建API时,我总是收到下面指示的两条错误消息。 错误:任务“:移动:转换类与DexForRelease”的执行失败。 com.android.build.api.transfor