jaxws-maven-plugin to create stubs and include wsdls in target location - maven-2

During the development, I am facing some issues to generate stubs with maven jaxws-maven-plugin. My requirment is given below.
I have some wsdls in my specified location, now my jaxws-maven-plugin will read them from the specified location and will create the stubs files for me. In the In the stubs files wsdlLocation will be the name of the wsdl files exist on the each location and I will specify the location manually.
Secondly, maven will also copy the wsdl files in the location where classes are build. So, latter I can refer to those wsdls locally.
I have written my plugin where I am able to generate the stub classes but wsdl file locations not containing the location I want. Also need help to copy the wsdl files to the location I need.
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>jaxws-maven-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>wsimport</goal>
</goals>
<configuration>
<wsdlDirectory>${project.build.directory}/wsdl/coh/BCS_COH-CXP9022427-${coh.version}/wsdl</wsdlDirectory>
<wsdlfiles>
<wsdlfile>\Service.wsdl</wsdlfile>
</wsdlfiles>
<wsdlLocation>/*</wsdlLocation>
<sourceDestDir>src/main/java</sourceDestDir>
<verbose>true</verbose>
</configuration>
</execution>
</executions>
</plugin>

After several googling, I found the answer. Firstly I was using org.codehaus.mojo's jaxws-maven-plugin but above code will work if one use
<groupId>org.jvnet.jax-ws-commons</groupId>
<artifactId>jaxws-maven-plugin</artifactId>
<version>2.2.1</version>

Related

Intellij path rule to automatically recognize generated sources folder

I would like to know if it is possible to set up a rule that marks a generated sources folder as generated sources root in Intellij Idea automatically.
Usually, Intellij detects the target/generated-sources directory as generated sources. My problem is that I also need it to automatically recognize the directory target/generated as generated sources, which Intellij never did in my case.
This is because of a maven plugin that I use for generating code from XSD schema:
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-xjc-plugin</artifactId>
<version>${cxf.version}</version>
<configuration>
<extensions>
<extension>org.apache.cxf.xjcplugins:cxf-xjc-dv:${cxf.version}</extension>
</extensions>
</configuration>
<executions>
<execution>
<id>generate-sources</id>
<phase>generate-sources</phase>
<goals>
<goal>xsdtojava</goal>
</goals>
<configuration>
<xsdOptions>
<xsdOption>
<xsd>src/main/resources/schema.xsd</xsd>
<packagename>org.example.project.common.request</packagename>
</xsdOption>
</xsdOptions>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
For some reason, this plugin generates code into the target/generated directory, and not into the target/generates-sources, of which I read that it is the convention and the default from many points of view.
I've tried searching on the web with similar keywords like in the title, but this was the closest solution to what I wanted to achieve. And even this solution doesn't solve my problem because Intellij doesn't allow setting some path patterns; it only offers a few options that don't include target/generated directory.
Another solution suggests changing the target output, which I can't do in every single project I work on; that is not a solution either.
This is important to me because I work with many projects, and sometimes when my code builds with maven but doesn't compile with Intellij I forget to check whether I marked all the generated folders as sources, or I don't even know there are generated sources in the project.
Does someone know a way I can achieve that Intellij automatically detects source files in target/generated directory?

Including maven built assemblies in another module

I have 2 maven modules. One module builds bunch of zip files using maven-assembly-plugin. Second module needs to include some of the zip files built by the first module in its package. What is the way to do this. Thank you.
The easiest thing would be to deploy the zips to a repository. For the local repository use install:install-file and for central repositories use deploy:deploy-file.
You can declare the zips as dependencies in your second module.
So someone else mentioned to deploy it to your repository. If you're already setup to deploy built artifacts to a repository this is easy, if not, check out http://maven.apache.org/plugins/maven-deploy-plugin/
Next, you need to use a plugin to get the zip file checked out of the repository. You could use shade, or the maven-dependency-plugin. Let's assume maven-dependency-plugin http://maven.apache.org/plugins/maven-dependency-plugin/usage.html
So add this to your maven pom file in the plugins section:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<id>unpack</id>
<phase>process-sources</phase>
<goals>
<goal>unpack</goal>
</goals>
<configuration>
<artifactItems>
<artifactItem>
<groupId>my.artifact.group.id</groupId>
<artifactId>my-artifact</artifactId>
<version>My-version</version>
<type>zip</type>
<overWrite>false</overWrite>
<outputDirectory>${project.build.directory}/see</outputDirectory>
</artifactItem>
</artifactItems>
</configuration>
</execution>
</executions>
</plugin>
Obviously you need to change the specifics of the artifact. That will unzip your zip file into target/see. If you want the actual zip file (which seems like what you were asking for but it's not clear), just change the goal from "unpack" to "copy-dependencies". You might also have to remove the outputDirectory or change some other bit of the configuration. Just play with it to get it where you need it, and see the page on the maven-dependency-plugin I mentioned above for more details.
Hope that helps.

Maven - Have an XSD as a dependency

We have one project that defines the message formats it produces with XSD files.
What is the easiest way to make these XSD files as dependencies of another project?
I was looking at using the maven-build-helper attach-artifact goal to attach my XSD files.
Is there a better mechanism?
I don't know the attach-artifact goal but I did something like you asked for. I had wsdl and xsd files to write Webservice artifacts and its client artifacts with axis2.
I put my wsdl and xsd in an own
project named 'wsdl' to
src/main/resources/META-INF and
nothing else.
I made a own project
named 'soap' for the generated
Java-SOAP-Code. In this project I
added the the wsdl project as
dependency and unpacked the wsdl and
xsd files via
maven-dependency-plugin to the
target folder in the
initialize-phase. So I can use it to
generate the SOAP-Code.
The soap
project I used as dependency for the
Webservice project and for the
client project.
I put all these projects to a multi module project so that I can build all together.
I think the important part for you is the configuration of dependency-plugin:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<id>unpack-wsdl-dependency</id>
<phase>initialize</phase>
<goals>
<goal>unpack</goal>
</goals>
</execution>
</executions>
<configuration>
<artifactItems>
<artifactItem>
<groupId>${groupId}</groupId>
<artifactId>wsdl</artifactId>
<outputDirectory>target/wsdl</outputDirectory>
<includes>META-INF/*.wsdl,META-INF/*.xsd</includes>
</artifactItem>
</artifactItems>
<!-- other configurations here -->
</configuration>
</plugin>
Hope that helps.
Greetings Michael

maven: add arbitrary file as a servlet context resource

I have a maven war project which produces webapp.war, and a maven 'skin' project which produces skin.zip (a file full of resources and XML files). Now I want to add this zip file as a servlet context resource (e.g WEB-INF/skin.zip).
I tried using overlays, but it expands the zip file into WEB-INF instead of placing the un-expanded file there:
<plugin>
<artifactId>maven-war-plugin</artifactId>
<configuration>
<overlays>
<overlay>
<groupId>com.mycompany</groupId>
<artifactId>skin</artifactId>
<type>zip</type>
<targetPath>WEB-INF</targetPath>
</overlay>
</overlays>
</configuration>
</plugin>
Is there any way to prevent it from expanding the resource -- or somehow stick the file in there (without using ant-plugin).
Note: type is a totally unnecessary and unhelpful configuration element -- it does not tell the plugin how to expand the artifact, as you might expect -- it tells it how to FIND it. For example if you change type from zip to jar, it complains that it can't find the artifact (in the most unhelpful way possible).
I tried using overlays, but it expands the zip file into WEB-INF
Yes, that's what overlays do, the content is unpacked to be merged with the war. That's just not the right tool in your case.
Is there any way to prevent it from expanding the resource -- or somehow stick the file in there
I would use the Maven Dependency Plugin and its dependency:copy goal:
dependency:copy takes a list of artifacts defined in the plugin configuration section and copies them to a specified location, renaming them or stripping the version if desired. This goal can resolve the artifacts from remote repositories if they don't exist in local.
And bind it on the prepare-package phase. Below, some starting point:
<project>
[...]
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<id>copy-prepare-package</id>
<phase>prepare-package</phase>
<goals>
<goal>copy</goal>
</goals>
<configuration>
<artifactItems>
<artifactItem>
<groupId>com.mycompany</groupId><!-- or ${project.groupId} -->
<artifactId>skin</artifactId>
<version>X.Y.Z</version><!-- or ${project.version} -->
<type>zip</type>
</artifactItem>
</artifactItems>
<outputDirectory>${project.build.directory}/${project.build.finalName}/WEB-INF</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
[...]
</project>
See Copying specific artifacts for more examples.

Maven configuration for two projects

I am having a project A being built with mvn assembly:assembly which gives me a jar file with dependencies. This project basically gets a file path and converts it to XML.
Now I need to create a new project B which will wrap A by walking a directory and calling several times to A. NOTE: They must be different applications. I am not able to modify A changing it's parameters.
I would like that when B builds, it will first build A and gets it's jar file.
Which is the best way to configure this in a pom file? Should I have two poms?
Same pom but two jars being build?
Thanks for reading!
I would handle this by adding an aggregator POM with A and B as modules. Then you simply build the aggregator each time to have A built before B. This gives you the flexibility to build A and B individually as well as both together.
If you are determined to invoke A's build from within B, it could be done by using the maven-exec-plugin to invoke another Maven instance.
For example:
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.1</version>
<executions>
<execution>
<goals>
<goal>exec</goal>
</goals>
</execution>
</executions>
<configuration>
<executable>mvn</executable>
<!--specified as a property below-->
<workingDirectory>${projectA.path}</workingDirectory>
<arguments>
<argument>clean</argument>
<argument>install</argument>
</arguments>
</configuration>
</plugin>
...
<properties>
<projectA.path>/path/to/project/a</projectA.path>
</properties>