Assuming, you're not going to try to use the generated stubs in the same project that you're doing this in (which would create circular dependencies and be a bad idea...) then, yes, you can do something like this.
The config is not all that tricky, in fact you'd kind of guessed it in your question but here goes:
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>jaxws-maven-plugin</artifactId>
<executions>
<execution>
<id>generate-wsdl</id>
<phase>process-classes</phase>
<goals>
<goal>wsgen</goal>
</goals>
<configuration>
<sei><!-- fully qualified class name goes here --></sei>
<genWsdl>true</genWsdl>
</configuration>
</execution>
<execution>
<id>generate-stubs</id>
<phase>process-classes</phase>
<goals>
<goal>wsimport</goal>
</goals>
<configuration>
<wsdlDirectory>target/jaxws/wsgen/wsdl</wsdlDirectory>
<wsdlFiles>
<wsdlFile><!-- class name goes here -->Service.wsdl</wsdlFile>
</wsdlFiles>
<!-- *** you need the next line to set the wsdlLocation in the generated stubs *** -->
<wsdlLocation>http://localhost:8080/test</wsdlLocation>
</configuration>
</execution>
</executions>
</plugin>
Update - to package up the generated code into a jar I would use the maven-jar-plugin like so:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<executions>
<execution>
<id>package-wsclient-jars</id>
<phase>package</phase>
<goals>
<goal>jar</goal>
</goals>
<configuration>
<classesDirectory>target/jaxws/<!-- rest of the path here, can't remember it right now --></classesDirectory>
<classifier>wsclient</classifier>
</configuration>
</execution>
</executions>
</plugin>
I've quickly pasted this from our config but our usage is a little different (as we zip up the wsdl files not the generated client but I believe this will get you pretty close). You'll probably have to setup the version for the maven-jar-plugin if you're not already using it - 2.3.1 seems to be the latest.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…