Im trying to generate classes from multiple WSDLs using jaxws-maven-plugin.
But it generates classes only from the wsdl defined in the first execution block.
I have seen this topic has been discussed in several places and i have changed my pom according to the comments. Still i cannot get it work.
<plugin>
<groupId>org.jvnet.jax-ws-commons</groupId>
<artifactId>jaxws-maven-plugin</artifactId>
<executions>
<execution>
<id>session-wsdl</id>
<goals>
<goal>wsimport</goal>
</goals>
<configuration>
<wsdlFiles>
<wsdlFile>src/main/resources/wsdl/SESSION.wsdl</wsdlFile>
</wsdlFiles>
<bindingDirectory>${project.basedir}</bindingDirectory>
<keep>true</keep>
<sourceDestDir>${genSrc.directory}</sourceDestDir>
</configuration>
</execution>
<execution>
<id>api-wsdl</id>
<goals>
<goal>wsimport</goal>
</goals>
<configuration>
<wsdlFiles>
<wsdlFile>src/main/resources/wsdl/STAGE.wsdl</wsdlFile>
</wsdlFiles>
<bindingDirectory>${project.basedir}</bindingDirectory>
<keep>true</keep>
<sourceDestDir>${genSrc.directory}</sourceDestDir>
</configuration>
</execution>
</executions>
<configuration>
<verbose>true</verbose>
<wsdlDirectory>
${basedir}/
</wsdlDirectory>
</configuration>
</plugin>
I think the issue here is related to this configuration:
<sourceDestDir>${genSrc.directory}</sourceDestDir>
Both executions have the same sourceDestDir. You should specify 2 different sourceDestDir, something like this:
<!-- sourceDestDir for the first execution -->
<sourceDestDir>${genSrc.directory}/session</sourceDestDir>
<!-- sourceDestDir for the second execution -->
<sourceDestDir>${genSrc.directory}/stage</sourceDestDir>
Related
I have added 2 plugins under build tag, functionality of both the plugin's is to generate some classes under target folder. Whenever I am trying to clean install maven application, by default target gets clean each time and then installs a fresh content into target folder which is the ideal way.
But in the following code Java classes are generated only when, if there is only single plugin. I have to manually comment any one of the plugin and then I need to install maven goal and then Java classes get generated for a single plugin, same thing I need to repeat for second plugin.
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<executions>
<execution>
<id>add-source</id>
<phase>generate-sources</phase>
<goals>
<goal>add-source</goal>
</goals>
<configuration>
<sources>
<source>${project.build.directory}/generated-sources/somefolder</source>
</sources>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.jvnet.jax-ws-commons</groupId>
<artifactId>jaxws-maven-plugin</artifactId>
<executions>
<execution>
<id>somefolder</id>
<phase>generate-sources</phase>
<goals>
<goal>wsimport</goal>
</goals>
</execution>
</executions>
<configuration>
<wsdlDirectory>src/main/webapp/WEB-INF/wsdl</wsdlDirectory>
<wsdlFiles>
<wsdlFile>myfirstwsdl.wsdl</wsdlFile>
</wsdlFiles>
<wsdlLocation>/WEB-INF/wsdl/*</wsdlLocation>
<extension>true</extension>
<target>2.2</target>
</configuration>
</plugin>
<plugin>
<groupId>org.jvnet.jax-ws-commons</groupId>
<artifactId>jaxws-maven-plugin</artifactId>
<executions>
<execution>
<id>wsimport</id>
<phase>generate-sources</phase>
<goals>
<goal>wsimport</goal>
</goals>
</execution>
</executions>
<configuration>
<wsdlDirectory>src/main/webapp/WEB-INF/wsdl</wsdlDirectory>
<wsdlFiles>
<wsdlFile>mysecondwsdl.wsdl</wsdlFile>
</wsdlFiles>
<wsdlLocation>/WEB-INF/wsdl/*</wsdlLocation>
<extension>true</extension>
<target>2.2</target>
</configuration>
</plugin>
</plugins>
</build>
My question is, how can I generate Java classes simultaneously without commenting any one of the plugin under target folder?
You're specifying the same plugin twice, that's not going to work. You need to merge the two like this (move <configuration> inside <execution>):
<plugin>
<groupId>org.jvnet.jax-ws-commons</groupId>
<artifactId>jaxws-maven-plugin</artifactId>
<executions>
<execution>
<id>somefolder</id>
<phase>generate-sources</phase>
<goals>
<goal>wsimport</goal>
</goals>
<configuration>
<wsdlDirectory>src/main/webapp/WEB-INF/wsdl</wsdlDirectory>
<wsdlFiles>
<wsdlFile>myfirstwsdl.wsdl</wsdlFile>
</wsdlFiles>
<wsdlLocation>/WEB-INF/wsdl/*</wsdlLocation>
<extension>true</extension>
<target>2.2</target>
</configuration>
</execution>
<execution>
<id>wsimport</id>
<phase>generate-sources</phase>
<goals>
<goal>wsimport</goal>
</goals>
<configuration>
<wsdlDirectory>src/main/webapp/WEB-INF/wsdl</wsdlDirectory>
<wsdlFiles>
<wsdlFile>mysecondwsdl.wsdl</wsdlFile>
</wsdlFiles>
<wsdlLocation>/WEB-INF/wsdl/*</wsdlLocation>
<extension>true</extension>
<target>2.2</target>
</configuration>
</execution>
</executions>
</plugin>
I have a JSON File and I want to convert it to POJO, for this I am using the plugin of org.jsonschema2pojo in maven. I am not able to generate the resultant pojo.Here's the snippet from pom.xml
<build>
<plugins>
<plugin>
<groupId>org.jsonschema2pojo</groupId>
<artifactId>jsonschema2pojo-maven-plugin</artifactId>
<version>0.4.23</version>
<configuration>
<sourceDirectory>${basedir}/src/main/resources/schema</sourceDirectory>
<targetPackage>${basedir}/src/main/resources/result</targetPackage>
</configuration>
<executions>
<execution>
<goals>
<goal>generate</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
I am using the generate sources goal in maven. My expectation is that it should give me pojo files at ${basedir}/src/main/resources/result location. However I am getting so. Please help me out.
Thanks,
Rajit
You want to use <outputDirectory> instead of <targetPackage>. More details here:
http://joelittlejohn.github.io/jsonschema2pojo/site/0.4.23/generate-mojo.html#outputDirectory
http://joelittlejohn.github.io/jsonschema2pojo/site/0.4.23/generate-mojo.html#targetPackage
Target package is the Java package you want your types to use, e.g. com.youcompany.model.
Also, typically you want the generated output to go into the target directory, not src. Derived files usually go there since anything inside target is usually omitted from source control. You don't need to specify outputDirectory if you don't want to, by default the generated output will go into /target/java-gen.
Below code works for me.
<plugin>
<groupId>org.jsonschema2pojo</groupId>
<artifactId>jsonschema2pojo-maven-plugin</artifactId>
<executions>
<execution>
<id>1</id>
<configuration>
<annotationStyle>jackson2</annotationStyle>
<includeAdditionalProperties>false</includeAdditionalProperties>
<sourcePaths>
<sourcePath>${project.basedir}/src/main/resource/jsd/your_schema.json</sourcePath>
</sourcePaths>
<targetPackage>your target package</targetPackage>
</configuration>
<goals>
<goal>generate</goal>
</goals>
</execution>
<execution>
<id>2</id>
<configuration>
<annotationStyle>jackson2</annotationStyle>
<includeAdditionalProperties>false</includeAdditionalProperties>
<sourcePaths>
<sourcePath>${project.basedir}/src/main/resource/jsd/your_schema2.json</sourcePath>
</sourcePaths>
<targetPackage>your target package</targetPackage>
</configuration>
<goals>
<goal>generate</goal>
</goals>
</execution>
</executions>
</plugin>
Use both targetPackage and outputDirectory.
<plugin>
<groupId>org.jsonschema2pojo</groupId>
<artifactId>jsonschema2pojo-maven-plugin</artifactId>
<version>1.0.2</version>
<configuration>
<sourceDirectory>${basedir}/src/main/resources/schema</sourceDirectory>
<outputDirectory>src/main/java</outputDirectory>
<targetPackage>com.your.package</targetPackage>
</configuration>
<executions>
<execution>
<goals>
<goal>generate</goal>
</goals>
</execution>
</executions>
</plugin>
I have the following configuration within my pom.xml that checks for PMD violations:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-pmd-plugin</artifactId>
<version>${pmd.version}</version>
<configuration>
<linkXRef>true</linkXRef>
<sourceEncoding>UTF-8</sourceEncoding>
<minimumTokens>100</minimumTokens>
<targetJdk>1.7</targetJdk>
</configuration>
<executions>
<execution>
<goals>
<goal>check</goal>
<goal>cpd-check</goal>
</goals>
</execution>
</executions>
</plugin>
When I run a build using the command mvn clean install, the PMD checks are run as last step of the build process. Rather, I would want the PMD checks to run as the first step of the build.
Does anybody know how could I achieve this?
Add the phase element to your POM.
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-pmd-plugin</artifactId>
<version>${pmd.version}</version>
<configuration>
<linkXRef>true</linkXRef>
<sourceEncoding>UTF-8</sourceEncoding>
<minimumTokens>100</minimumTokens>
<targetJdk>1.7</targetJdk>
</configuration>
<executions>
<execution>
<phase>validate</phase>
<goals>
<goal>check</goal>
<goal>cpd-check</goal>
</goals>
</execution>
</executions>
</plugin>
The validate phase is the first phase of the maven lifecycle: http://maven.apache.org/guides/introduction/introduction-to-the-lifecycle.html
Thanks for your answers #JamesB and #PetrMensik for letting me know about the phase element within the POM. It helped me solve my problem. I finally settled for this:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-pmd-plugin</artifactId>
<version>${pmd.version}</version>
<configuration>
<linkXRef>true</linkXRef>
<sourceEncoding>UTF-8</sourceEncoding>
<minimumTokens>100</minimumTokens>
<targetJdk>1.7</targetJdk>
</configuration>
<executions>
<execution>
<phase>compile</phase>
<goals>
<goal>check</goal>
<goal>cpd-check</goal>
</goals>
</execution>
</executions>
</plugin>
I used the phase:compile, the reason being I have plenty of tests in my project which take up a lot of time to execute. And, its quite irritating to wait for those tests to finish and be notified about a PMD violation at the end of all the tests. I needed something just before the tests. Hence, I settled for compile.
Further suggestions are welcome. :)
You need to hook execution of this plugin to a different Maven lifecycle phase (validation comes as the first one in default lifecycle).
<executions>
<execution>
<phase>validate</phase>
<goals>
<goal>check</goal>
<goal>cpd-check</goal>
</goals>
</execution>
</executions>
See this the list of the available Maven phases for reference.
I set build configuration
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-pmd-plugin</artifactId>
<version>${pmd.plugin.version}</version>
<configuration>
<failOnViolation>true</failOnViolation>
<printFailingErrors>true</printFailingErrors>
</configuration>
<executions>
<execution>
<goals>
<goal>check</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
I have a legacy application using struts 1 and torque. I have made an effort last week to refactor it a bit and tried to decouple some groups of classes and introduced unit tests. As I can not test all areas of the application through unit tests, I wanted to add HtmlUnit tests.
To to this, I added the maven-failsafe-plugin and jetty to my project, like so:
<build>
...
<plugins>
...
<plugin>
<artifactId>maven-failsafe-plugin</artifactId>
<version>2.6</version>
<executions>
<execution>
<goals>
<goal>integration-test</goal>
<goal>verify</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.mortbay.jetty</groupId>
<artifactId>maven-jetty-plugin</artifactId>
<version>6.1.16</version>
<configuration>
<scanIntervalSeconds>10</scanIntervalSeconds>
<stopPort>8005</stopPort>
<stopKey>STOP</stopKey>
<contextPath>/</contextPath>
</configuration>
<executions>
<execution>
<id>start-jetty</id>
<phase>pre-integration-test</phase>
<goals>
<goal>run</goal>
</goals>
<configuration>
<scanIntervalSeconds>0</scanIntervalSeconds>
<daemon>true</daemon>
</configuration>
</execution>
<execution>
<id>stop-jetty</id>
<phase>post-integration-test</phase>
<goals>
<goal>stop</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
The problem is, that when I run mvn verify, I get the following exception:
java.lang.SecurityException: sealing violation: can't seal package javax.naming: already loaded
I am using javax.naming in some classes, but can't find any dependency that overrides javax.naming!
Does anybody have a clue about how to figure this problem out?
I tried to generate two xmlbeans in one project. Each one, for example, gets participant object, so I can't put them in one configuration. The way I did was using two excution, here is my pom file:
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>xmlbeans-maven-plugin</artifactId>
<version>2.3.3</version>
<executions>
<execution>
<id>xmlbean1</id>
<phase>generate-sources</phase>
<goals>
<goal>xmlbeans</goal>
</goals>
<configuration>
<xmlConfigs>
<xmlConfig implementation="java.io.File">src/main/xsdconfig/xmlbean1</xmlConfig>
</xmlConfigs>
<verbose>true</verbose>
<schemaDirectory>src/main/xsd/xmlbean1</schemaDirectory>
</configuration>
</execution>
<execution>
<id>xmlbean2</id>
<phase>generate-sources</phase>
<goals>
<goal>xmlbeans</goal>
</goals>
<configuration>
<xmlConfigs>
<xmlConfig implementation="java.io.File">src/main/xsdconfig/xmlbean2</xmlConfig>
</xmlConfigs>
<verbose>true</verbose>
<schemaDirectory>src/main/xsd/xmlbean2</schemaDirectory>
</configuration>
</execution>
</executions>
<inherited>true</inherited>
</plugin>
But it is not working at all. Could anyone help me with that, thanks
Thanks everybody, i got the answer, the following pom is working fine:
<executions>
<execution>
<id>id1</id>
<phase>generate-sources</phase>
<goals>
<goal>xmlbeans</goal>
</goals>
<configuration>
<schemaDirectory>src/main/xsd/first</schemaDirectory>
<xmlConfigs>
<xmlConfig implementation="java.io.File">src/main/xsdconfig/first</xmlConfig>
</xmlConfigs>
<verbose>true</verbose>
<sourceGenerationDirectory>target/first-resource</sourceGenerationDirectory>
<classGenerationDirectory>target/first-class</classGenerationDirectory>
<staleFile>target/first/first.stale</staleFile>
</configuration>
</execution>
<execution>
<id>id2</id>
<phase>generate-sources</phase>
<goals>
<goal>xmlbeans</goal>
</goals>
<configuration>
<schemaDirectory>src/main/xsd/second</schemaDirectory>
<xmlConfigs>
<xmlConfig implementation="java.io.File">src/main/xsdconfig/second</xmlConfig>
</xmlConfigs>
<verbose>true</verbose>
<sourceGenerationDirectory>target/second-resource</sourceGenerationDirectory>
<classGenerationDirectory>target/second-class</classGenerationDirectory>
<staleFile>target/second/second.stale</staleFile>
</configuration>
</execution>
</executions>
This doesn't work because the id is only used to find an existing execution (when you want to tweak it).
Your problem is that Maven can't run the same plugin twice in the same phase.
What are your options?
Split that into different sub modules
Use Ant to create xmlbeans and use the antrun element.
But I wonder why you can't use two xmlConfig elements. Just put all your .xsd files into one directory and create as many beans from them as necessary (see "Multiple XSDConfig Directories")
You should try using another, distinct phase for the second invocation. AFAIK the same plugin cannot be executed twice in the same lifecycle phase.