2013-07-17 252 views
3

我試圖在具有單獨配置的maven插件內部有兩個執行塊,但maven似乎忽略了執行塊內的配置塊並僅使用執行塊外的配置塊。Maven忽略執行配置

所以爲了縮小這個問題,我花了一個工作插件部分,將工作配置略微向上移到執行塊的內部,然後停止工作(wsdl仍然被拾起(實際上都是) ,但這只是因爲它位於默認目錄中,當配置節位於執行塊內部時,綁定文件和其他配置的綁定文件和非綁定文件將被拾取,事實上,它應該甚至不知道第二個wsdl,因爲我沒有地方指定它):

<build> 
    <pluginManagement> 
     <plugins> 
      <plugin> 
       <groupId>org.jvnet.jax-ws-commons</groupId> 
       <artifactId>jaxws-maven-plugin</artifactId> 
       <version>2.1</version> 
       <executions> 
        <execution> 
         <id>wsdla</id> 
         <phase>generate-sources</phase> 
         <configuration> 
          <packageName>com.mycee.project.model</packageName> 
          <sourceDestDir>src/main/java</sourceDestDir> 
          <wsdlFiles> 
           <wsdlFile> 
            ${basedir}/src/wsdl/a.wsdl 
           </wsdlFile>    
          </wsdlFiles> 
          <bindingDirectory> 
           ${basedir}/src/wsdl/binding 
          </bindingDirectory> 
          <verbose>true</verbose> 
         </configuration> 
         <goals> 
          <goal>wsimport</goal> 
         </goals>    
        </execution> 
       </executions> 
      </plugin> 
     </plugins> 
    </pluginManagement> 
</build> 

這是一個Maven的問題,我需要解決或JAXWS問題,如何解決這個問題?

如果我更改版本到2.3,我得到以下錯誤:

[錯誤]無法執行目標org.jvnet.jax-WS-公地:JAXWS-Maven的插件:2.3:wsimport的(默認-cli)項目mycee-project:執行目標的默認cli org.jvnet.jax-ws-commons:jaxws-maven-plugin:2.3:wsimport失敗:字符串索引超出範圍:-1 - > [Help 1]

運行MVN清潔JAXWS:

[DEBUG] ----------------------------------------------------------------------- 
[DEBUG] Goal:   org.jvnet.jax-ws-commons:jaxws-maven-plugin:2.3:wsimport (default-cli) 
[DEBUG] Style:   Regular 
[DEBUG] Configuration: <?xml version="1.0" encoding="UTF-8"?> 
<configuration> 
    <bindingDirectory default-value="${basedir}/src/jaxws"/> 
    <destDir default-value="${project.build.outputDirectory}"/> 
    <encoding>${project.build.sourceEncoding}</encoding> 
    <extension default-value="false"/> 
    <genJWS default-value="false"/> 
    <implDestDir default-value="${project.build.sourceDirectory}"/> 
    <keep default-value="true"/> 
    <localRepository default-value="${localRepository}"/> 
    <pluginArtifactMap>${plugin.artifactMap}</pluginArtifactMap> 
    <quiet default-value="false"/> 
    <remoteRepositories default-value="${project.pluginArtifactRepositories}"/> 
    <settings>${settings}</settings> 
    <sourceDestDir default-value="${project.build.directory}/generated-sources/wsimport"/> 
    <staleFile default-value="${project.build.directory}/jaxws/stale"/> 
    <verbose default-value="false"/> 
    <wsdlDirectory default-value="${basedir}/src/wsdl"/> 
    <xadditionalHeaders default-value="false"/> 
    <xdebug default-value="false"/> 
    <xdisableAuthenticator default-value="false"/> 
    <xdisableSSLHostnameVerification default-value="false"/> 
    <xnoAddressingDataBinding default-value="false"/> 
    <xnocompile default-value="true"/> 
    <xuseBaseResourceAndURLToLoadWSDL default-value="false"/> 
    <project default-value="${project}"/> 
</configuration> 
[DEBUG] ======================================================================= 
:wsimport的-X 我可以在調試輸出,它的使用默認值見

調試輸出索引超出範圍的錯誤:

[ERROR] Failed to execute goal org.jvnet.jax-ws-commons:jaxws-maven-plugin:2.3:wsimport (default-cli) on project mycee-project: Execution default-cli of goal org.jvnet.jax-ws-commons:jaxws-maven-plugin:2.3:wsimport failed: String index out of range: -1 -> [Help 1] 
org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal org.jvnet.jax-ws-commons:jaxws-maven-plugin:2.3:wsimport (default-cli) on project mycee-project: Execution default-cli of goal org.jvnet.jax-ws-c 
ommons:jaxws-maven-plugin:2.3:wsimport failed: String index out of range: -1 
     at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:225) 
     at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:153) 
     at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:145) 
     at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:84) 
     at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:59) 
     at org.apache.maven.lifecycle.internal.LifecycleStarter.singleThreadedBuild(LifecycleStarter.java:183) 
     at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:161) 
     at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:320) 
     at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:156) 
     at org.apache.maven.cli.MavenCli.execute(MavenCli.java:537) 
     at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:196) 
     at org.apache.maven.cli.MavenCli.main(MavenCli.java:141) 
     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 
     at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) 
     at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) 
     at java.lang.reflect.Method.invoke(Method.java:601) 
     at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:290) 
     at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:230) 
     at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:409) 
     at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:352) 
Caused by: org.apache.maven.plugin.PluginExecutionException: Execution default-cli of goal org.jvnet.jax-ws-commons:jaxws-maven-plugin:2.3:wsimport failed: String index out of range: -1 
     at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:110) 
     at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:209) 
     ... 19 more 
Caused by: java.lang.StringIndexOutOfBoundsException: String index out of range: -1 
     at java.lang.AbstractStringBuilder.substring(AbstractStringBuilder.java:872) 
     at java.lang.StringBuilder.substring(StringBuilder.java:72) 
     at org.jvnet.jax_ws_commons.jaxws.AbstractJaxwsMojo.getCP(AbstractJaxwsMojo.java:484) 
     at org.jvnet.jax_ws_commons.jaxws.AbstractJaxwsMojo.exec(AbstractJaxwsMojo.java:359) 
     at org.jvnet.jax_ws_commons.jaxws.WsImportMojo.processLocalWsdlFiles(WsImportMojo.java:319) 
     at org.jvnet.jax_ws_commons.jaxws.WsImportMojo.execute(WsImportMojo.java:283) 
     at org.jvnet.jax_ws_commons.jaxws.MainWsImportMojo.execute(MainWsImportMojo.java:50) 
     at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:101) 
     ... 20 more 
[ERROR] 
[ERROR] 
[ERROR] For more information about the errors and possible solutions, please read the following articles: 
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/PluginExecutionException 

完全POM的要求:

<?xml version="1.0" encoding="UTF-8" standalone="no"?> 
<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.mycee</groupId> 
    <artifactId>mycee-project</artifactId> 
    <version>0.0.1</version> 
    <packaging>jar</packaging> 

    <name>mycee</name> 
    <url>http://maven.apache.org</url> 

    <properties> 
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> 
    <slf4j.version>1.7.2</slf4j.version> 
    </properties> 

    <repositories> 

    </repositories> 
    <pluginRepositories> 

    </pluginRepositories> 
    <dependencies> 
    <!-- Junit4 Dependencies --> 
    <dependency> 
     <groupId>junit</groupId> 
     <artifactId>junit</artifactId> 
     <version>4.10</version> 
     <scope>test</scope> 
    </dependency> 

    <!-- XML Dependencies --> 
    <dependency> 
     <groupId>javax.xml</groupId> 
     <artifactId>webservices-api</artifactId> 
     <version>2.0.1</version> 
    </dependency> 
    <dependency> 
     <groupId>com.sun.xml.bind</groupId> 
     <artifactId>jaxb-xjc</artifactId> 
     <version>2.2.7</version> 
    </dependency> 
    <dependency> 
     <groupId>com.sun.xml.ws</groupId> 
     <artifactId>jaxws-rt</artifactId> 
     <version>2.2.8</version> 
    </dependency> 
    <!-- Log Dependencies --> 
    <dependency> 
     <groupId>log4j</groupId> 
     <artifactId>log4j</artifactId> 
     <version>1.2.16</version> 
    </dependency> 
    <dependency> 
     <groupId>org.slf4j</groupId> 
     <artifactId>slf4j-api</artifactId> 
     <version>${slf4j.version}</version> 
    </dependency> 
    <dependency> 
     <groupId>org.slf4j</groupId> 
     <artifactId>jcl-over-slf4j</artifactId> 
     <version>${slf4j.version}</version> 
    </dependency> 
    <dependency> 
     <groupId>org.slf4j</groupId> 
     <artifactId>slf4j-log4j12</artifactId> 
     <version>${slf4j.version}</version> 
    </dependency> 
    </dependencies> 

    <build> 
     <pluginManagement> 
     <plugins> 
      <plugin> 
       <groupId>org.jvnet.jax-ws-commons</groupId> 
       <artifactId>jaxws-maven-plugin</artifactId> 
       <version>2.1</version> 
       <executions> 
        <execution> 
         <id>basic</id> 
         <phase>generate-sources</phase> 
         <configuration> 
          <packageName>com.mycee.project.model</packageName> 
          <sourceDestDir>src/main/java</sourceDestDir> 
          <wsdlFiles> 
           <wsdlFile> 
            ${basedir}/src/wsdl/wsdla.wsdl 
           </wsdlFile>    
          </wsdlFiles> 
          <bindingDirectory> 
           ${basedir}/src/jaxws/binding 
          </bindingDirectory> 
          <verbose>true</verbose> 
          <target>2.1</target> 
         </configuration> 
         <goals> 
          <goal>wsimport</goal> 
         </goals>    
        </execution> 
       </executions> 
      </plugin> 
     </plugins> 
    </pluginManagement> 
    </build> 


</project> 
+0

根據要求添加完整的pom。我已經將 2.1添加到jaxws配置中,似乎擺脫了maven錯誤,但仍然無法解決配置在執行塊內部無法拾取的問題。 –

回答

3

你的POM應該是這樣的:

<build> 
    <pluginManagement> 
    <plugins> 
     <plugin> 
     <groupId>org.jvnet.jax-ws-commons</groupId> 
     <artifactId>jaxws-maven-plugin</artifactId> 
     <version>2.1</version> 
     </plugin> 
    </plugins> 
    </pluginManagement> 
    <plugins> 
    <plugin> 
     <groupId>org.jvnet.jax-ws-commons</groupId> 
     <artifactId>jaxws-maven-plugin</artifactId> 
     <executions> 
     <execution> 
      <id>basic</id> 
      <phase>generate-sources</phase> 
      <goals> 
      <goal>wsimport</goal> 
      </goals>    
      <configuration> 
      <packageName>com.mycee.project.model</packageName> 
      <wsdlFiles> 
       <wsdlFile>${basedir}/src/wsdl/wsdla.wsdl</wsdlFile>    
      </wsdlFiles> 
      <bindingDirectory>${basedir}/src/jaxws/binding</bindingDirectory> 
      <verbose>true</verbose> 
      <target>2.1</target> 
      </configuration> 
     </execution> 
     </executions> 
    </plugin> 
    </plugins>  
</build> 

的問題是基於因爲你在pluginManagement塊中做了所有的事情,而不是在構建塊中,這意味着它沒有真正執行。

+0

當我像你說的那樣做之後,直到我將bindingDirectory更改爲bindingFiles,它仍然無法工作。你是我的英雄:-) 感謝您教我這個寶貴的Maven提示! –

1

上述觀點是正確的,但您的maven忽略配置,因爲您在執行節點內有它。 (例如下面)將其移動到插件節點和配置應該工作

<plugin> 
    <groupId>org.jvnet.jax-ws-commons</groupId> 
    <artifactId>jaxws-maven-plugin</artifactId> 
    <version>2.1</version> 
    <executions> 
     <execution> 
      <id>wsdla</id> 
      <phase>generate-sources</phase> 
      <!-- 
      if you have one more than one execution node put your configuration here 
      --> 
      <goals> 
       <goal>wsimport</goal> 
      </goals>    
     </execution> 
    </executions> 
    <configuration> 
     <packageName>com.mycee.project.model</packageName> 
     <sourceDestDir>src/main/java</sourceDestDir> 
     <wsdlFiles> 
      <wsdlFile> 
       ${basedir}/src/wsdl/a.wsdl 
      </wsdlFile>    
     </wsdlFiles> 
     <bindingDirectory> 
      ${basedir}/src/wsdl/binding 
     </bindingDirectory> 
     <verbose>true</verbose> 
    </configuration> 
</plugin> 

我不得不它用來在工作的時候有一個以上的執行節點同樣的問題。在其他項目中使用相同的客戶端後,配置似乎被忽略。因此,要長話短說:如果你有一個執行節點保持外部配置,否則保持在裏面。

+2

如果配置是相同的,幾次執行的要點是什麼? –

+0

你有點重要 - 但根據文檔,配置應該在「執行」節點內。 –

+2

配置裏面的執行是允許的,因爲maven 3.3.1 https://maven.apache.org/docs/3.3.1/release-notes.html –