6
<build>
    <plugins>
        <plugin>
            <groupId>org.jvnet.jax-ws-commons</groupId>
            <artifactId>jaxws-maven-plugin</artifactId>
            <version>2.3</version>

            <executions>
                <execution>
                    <phase>generate-sources</phase>
                    <goals>
                        <goal>wsimport</goal>
                    </goals>
                    <id>generate-sei</id>

                    <configuration>
                        <sourceDestDir>${project.basedir}/src/main/java</sourceDestDir>
                    </configuration>
                </execution>
            </executions>
          <dependencies>...</dependencies>
        </plugin>
    </plugins>
</build>

The above XML snippet is from a POM file in a Java project. In this snippet I've defined the jaxws-maven-plugin to use a wsdl file to generate the SEI code and place it in the src/main/java directory. This plugin is bound to the generate-sources phase, and works fine.

I want to make it so that if I issue the plugin directly, using:

mvn jaxws:wsimport

it should place the files in the above mentioned folder. From the plugins reference site (https://jax-ws-commons.java.net/jaxws-maven-plugin/wsimport-mojo.html), I can't figure out how to pass the parameter (sourceDestDir) as a command line argument. Is there someway I can do this?

Tunaki
  • 132,869
  • 46
  • 340
  • 423
Aamir Khan
  • 2,945
  • 2
  • 25
  • 32

1 Answers1

10

###WARNING /!\

You are trying to generate sources under the source folder src/main/java. Unless there is a very strong reason, don't do this. All generated content should always be placed under the build directory (target by default) and not be version-controlled. You can always add the generated sources as source folder using the build-helper-maven-plugin:add-source, if the plugin does not do it already itself.


To be able to set parameters directly on the command line, the plugin needs to define a user property. However, the org.jvnet.jax-ws-commons:jaxws-maven-plugin does not define a user property for the sourceDestDir parameter. This is noticeable because the documentation does not have a "User Property" set.

You can also find this in the source code:

@Parameter(defaultValue = "${project.build.directory}/generated-sources/wsimport")
private File sourceDestDir;

The @Parameter annotation, used to declare the parameter of the Maven plugin, does not have a corresponding property.

As such, you will need to have the following:

  1. Define a Maven property jaxws.sourceDestDir with a value of ${project.basedir}/src/main/java with

    <properties>
      <jaxws.sourceDestDir>${project.basedir}/src/main/java</jaxws.sourceDestDir>
    </properties>
    

Preferably, you would have ${project.build.directory}/some/path instead of src/main/java.

  1. Configure the plugin to use this Maven property:

    <configuration>
      <sourceDestDir>${jaxws.sourceDestDir}</sourceDestDir>
    </configuration>
    
  2. If you want to override it, you can now do so directly on the command line with -Djaxws.sourceDestDir=/my/new/value. This system property will take precedence over the value of the Maven property.

Darshit Patel
  • 121
  • 1
  • 1
  • 12
Tunaki
  • 132,869
  • 46
  • 340
  • 423
  • Hi Tuanki. Thank you for the extremely comprehensive answer. Just to clarify, any configurations added (using the tag) to the POM are not used by the plugin if it's run directly from the CLI, as opposed to being run in the build process in the phase it's bound to? – Aamir Khan Jul 18 '16 at 12:14
  • 2
    @AamirKhan That's where plugin execution, with ``, come into play. When invoked on the command line, you launch a new custom execution so any configuration that is under `` won't be used. However, configuration added in the global `` (not under any ``) will be used. Note that, on the command line, you can also execute a specific existing execution (instead of creating a new one by default) using the `@` syntax http://stackoverflow.com/questions/3166538/how-to-execute-maven-plugin-execution-directly-from-command-line. – Tunaki Jul 18 '16 at 13:03
  • Just what I needed. Thanks @Tunaki! – Aamir Khan Jul 18 '16 at 13:05