2017-08-18 41 views
0

我有一個基於Spring的Web應用程序,我試圖使用SOAP服務。我正在使用jaxb2-maven-plugin(org.codehaus.mojo)。然而,我看到一個空的jaxb2文件夾,這是目標下的carch,我沒有看到它的任何Java類。我已將wsdl正確放置在資源文件夾本身下。無法使用codehaus.mojo創建java類jaxb2-maven-plugin

下面是pom.xml中

<build> 
     <finalName>${project.artifactId}</finalName> 
     <resources> 
      <resource> 
       <directory>src/main/resources</directory> 
      </resource> 
      <resource> 
       <directory>src/main/java/com/xyz/rap/service/impl/wsdl</directory> 
       <targetPath>wsdl</targetPath> 
      </resource> 
      <resource> 
       <directory>src/main/config</directory> 
       <targetPath>config</targetPath> 
      </resource> 
     </resources> 
     <plugins> 
     <plugin> 
       <groupId>org.codehaus.mojo</groupId> 
       <artifactId>jaxb2-maven-plugin</artifactId> 
       <version>1.6</version> 
       <executions> 
        <execution> 
         <id>xjc</id> 
         <goals> 
          <goal>xjc</goal> 
         </goals> 
        </execution> 
       </executions> 
       <configuration> 
        <!-- Package to store the generated file --> 
        <packageName>com.xxx.gen.retail.abc</packageName> 
        <!-- Treat the input as WSDL --> 
        <wsdl>true</wsdl> 
        <!-- Input is not XML schema --> 
        <xmlschema>false</xmlschema> 
        <!-- The location of the WSDL file --> 
        <schemaDirectory>${project.basedir}/src/main/resources</schemaDirectory> 
        <!-- The WSDL file that you saved earlier --> 
        <schemaFiles>gene.wsdl</schemaFiles> 
        <!-- Don't clear output directory on each run --> 
        <clearOutputDir>false</clearOutputDir> 
       </configuration> 
      </plugin> 
      <plugin> 
       <groupId>org.apache.maven.plugins</groupId> 
       <artifactId>maven-compiler-plugin</artifactId> 
       <configuration> 
        <!-- or whatever version you use --> 
        <source>1.7</source> 
        <target>1.7</target> 
       </configuration> 
      </plugin> 
     </plugins> 
    </build> 
</project> 

下創建的插件配置,那麼日誌當我運行"maven install"

[INFO] Building rap-web Maven Webapp 0.0.1-SNAPSHOT 
[INFO] ------------------------------------------------------------------------ 
[INFO] 
**[INFO] --- jaxb2-maven-plugin:1.6:xjc (xjc) @ rap-web --- 
[INFO] Generating source... 
[WARNING] No encoding specified; default platform encoding will be used for generated sources. 
[INFO] parsing a schema... 
[INFO] compiling a schema... 
[INFO] 
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ rap-web --- 
[WARNING] Using platform encoding (Cp1252 actually) to copy filtered resources, i.e. build is platform dependent! 
[INFO] Copying 15 resources 
[INFO] Copying 3 resources to wsdl 
[INFO] Copying 1 resource to config 
[INFO] 
[INFO] --- maven-compiler-plugin:2.5.1:compile (default-compile) @ rap-web --- 
[WARNING] File encoding has not been set, using platform encoding Cp1252, i.e. build is platform dependent! 
[INFO] Compiling 50 source files to C:\Users\xx67047\DSA-GIT-Projects\10.22.17-dsa-rap-services\rap-web\target\classes** 
[INFO] 
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ rap-web --- 
[WARNING] Using platform encoding (Cp1252 actually) to copy filtered resources, i.e. build is platform dependent! 
[INFO] skip non existing resourceDirectory C:\Users\xx67047\DSA-GIT-Projects\10.22.17-dsa-rap-services\rap-web\src\test\resources 
[INFO] 
[INFO] --- maven-compiler-plugin:2.5.1:testCompile (default-testCompile) @ rap-web --- 
[INFO] Nothing to compile - all classes are up to date 
[INFO] 
[INFO] --- maven-surefire-plugin:2.12.4:test (default-test) @ rap-web --- 

它說,解析和編譯在日誌的模式,但我沒有看到任何在日誌中創建java類,我看到一個空的jaxb2文件夾和其他空的generated-sources文件夾被創建。請參考下面的圖片爲:

enter image description here

回答

0

jaxb2-maven-plugin將創建默認類爲target/generated-sources/jaxb。如果您沒有將類放入目標文件夾中,那麼如果您使用的是Eclipse,則可以將此文件夾添加到項目構建路徑中:右鍵單擊項目並選擇「構建路徑>使用源文件夾」

然後您需要要運行mvn clean install它將清理或刪除目標文件夾並重新生成所有內容

+0

我試過了,但沒有在target/generated-sources中創建任何jaxb文件夾。我懷疑問題是否與WSDL本身有關。但是,我能夠使用wsimport生成存根,但不能使用jaxb2-maven-plugin生成存根。 – RRN

0

試試codehaus的2.2版請記住,您需要稍微更改xml,因爲1.x和2.x.

說了我想告訴你,我有類似的問題,但可能是由其他原因造成的,我使用IntelliJ,它生成空的j/target/generated-sources /下的axb文件夾。

<plugin> 
       <groupId>org.codehaus.mojo</groupId> 
       <artifactId>jaxb2-maven-plugin</artifactId> 
       <version>2.2</version> 
       <executions> 
        <execution> 
         <id>xjc</id> 
         <goals> 
          <goal>xjc</goal> 
         </goals> 
        </execution> 
       </executions> 
       <configuration> 
        <sources> 
         <source>/src/main/resources/xsd/</source> 
        </sources> 
        <outputDirectory>${project.basedir}/target/generated-sources/jaxb</outputDirectory> 
        <clearOutputDir>false</clearOutputDir> 
       </configuration> 
</plugin>