Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Maven ignores execution configuration

Tags:

maven

jax-ws

I'm trying to have two execution blocks inside a maven plugin with separate configurations, but maven seems to ignore the configuration blocks inside the execution blocks and only uses the configuration block outside the executions block.

So to narrow down the problem, I took a working plugin section and moved the working configuration just slightly up towards the inside of the execution block and then it stopped working (the wsdl is still being picked up (actually both are), but that's simply because it's sitting in the default directory, the binding file and non of the other configuration is being picked up when the configuration section is sitting inside the execution block and in fact, it should not even be aware of the second wsdl since I haven't specified it anywhere):

<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>

Is this a maven issue I need to resolve or a jaxws issue and how do I resolve this?

If I change the version to 2.3, I get the following error:

[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]

running mvn clean jaxws:wsimport -X I can see in the debug output that it's using the defaults:

[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] =======================================================================

The debug output for the index out of range error:

[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

Full pom as requested:

<?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>
like image 932
Jan Vladimir Mostert Avatar asked Jul 17 '13 09:07

Jan Vladimir Mostert


People also ask

What is pluginManagement in Maven?

From Maven documentation: pluginManagement: is an element that is seen along side plugins. Plugin Management contains plugin elements in much the same way, except that rather than configuring plugin information for this particular project build, it is intended to configure project builds that inherit from this one.

What is Mojo in Maven?

What is a Mojo? A mojo is a Maven plain Old Java Object. Each mojo is an executable goal in Maven, and a plugin is a distribution of one or more related mojos.

What is the correct syntax for executing a Maven plugin?

Usage of a Maven Plugin xml you can use the shorthand notation to execute the plugin: mvn <prefix>:<goal> , commonly the “prefix” is the artifact ID minus the “-maven-plugin”. For example mvn example:version .

Where do I put pom xml plugins?

They execute during the build process and should be configured in the <build/> element of pom. xml. They execute during the site generation process and they should be configured in the <reporting/> element of the pom.


2 Answers

Your pom should look like this:

<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>

The problem is based on that you do all stuff in the pluginManagement block and not in build block which means it's not really executed.

like image 188
khmarbaise Avatar answered Nov 15 '22 07:11

khmarbaise


The above point is correct but your maven is ignoring configuration because you have it inside of the execution node. Move it into the plugin node and configuration should work (e.g. below)

<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> 

I had same problem which used to work when i had more than one execution node. After i used same client in other project the configuration seemed to be ignored.

So to keep long story short: if you have one execution node keep the configuration outside otherwise keep it inside.

like image 24
Patrik Bego Avatar answered Nov 15 '22 09:11

Patrik Bego