Using org.apache.axis2 maven plugin, I am trying to generate stubs out of two WSDL files. I have mentioned the wsdl file names in to <wsdlFile>My/WSDL/File</wsdlFile>. The plugin is still picking up the default WSDL file name /src/main/resources/service.wsdl. Since my wsdlFile names are not service.wsdl, I am getting java.io.FileNotFoundException. Please help me to change the wsdlFile name to my required wsdlFile name.
<plugin>
<groupId>org.apache.axis2</groupId>
<artifactId>axis2-wsdl2code-maven-plugin</artifactId>
<version>1.7.9</version>
<executions>
<execution>
<id>ws1</id>
<goals>
<goal>wsdl2code</goal>
</goals>
<configuration>
<databindingName>xmlbeans</databindingName>
<wsdlFile>src/main/resources/service1.wsdl</wsdlFile>
<outputDirectory>target/generated-sources</outputDirectory>
</configuration>
</execution>
<execution>
<id>ws2</id>
<goals>
<goal>wsdl2code</goal>
</goals>
<configuration>
<databindingName>xmlbeans</databindingName>
<wsdlFile>src/main/resources/service2.wsdl</wsdlFile>
<outputDirectory>target/generated-sources</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>
Related
I am using the mojohaus jaxb2-maven-plugin to generate Java sources out of xsd schema files. My pom.xml looks like this:
...
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>jaxb2-maven-plugin</artifactId>
<version>2.5.0</version>
<executions>
<execution>
<id>xjc-1</id>
<goals>
<goal>xjc</goal>
</goals>
<configuration>
<packageName>my.first.package.types</packageName>
<sources>
<source>src/main/java/META-INF/wsdl/firstSchema.xsd</source>
</sources>
</configuration>
</execution>
<execution>
<id>xjc-2</id>
<goals>
<goal>xjc</goal>
</goals>
<configuration>
<packageName>my.second.package.types</packageName>
<sources>
<source>src/main/java/META-INF/wsdl/secondSchema.xsd</source>
</sources>
<clearOutputDir>false</clearOutputDir>
</configuration>
</execution>
</executions>
<configuration>
<outputDirectory>src/main/javagen</outputDirectory>
</configuration>
</plugin>
This plugin configuration should correspond to the one found here.
When I run the build, the generated source files from the first schema are also put into the second package. Can anyone explain to me why this is the case? Is that a bug or am I missing something?
Thanks a lot for any input!
Edit:
I tried the maven-jaxb2-plugin as well. Same result! So this seems to be a generell maven issue. My plugin configuration for the maven-jaxb2-plugin is as follows:
...
<plugin>
<groupId>org.jvnet.jaxb2.maven2</groupId>
<artifactId>maven-jaxb2-plugin</artifactId>
<version>0.14.0</version>
<executions>
<execution>
<id>first</id>
<goals>
<goal>generate</goal>
</goals>
<configuration>
<schemaIncludes>
<include>firstSchema.xsd</include>
</schemaIncludes>
<generatePackage>my.first.package.types</generatePackage>
</configuration>
</execution>
<execution>
<id>second</id>
<goals>
<goal>generate</goal>
</goals>
<configuration>
<schemaIncludes>
<include>secondSchema.xsd</include>
</schemaIncludes>
<generatePackage>my.second.package.types</generatePackage>
</configuration>
</execution>
</executions>
<configuration>
<schemaDirectory>src/main/java/META-INF/wsdl</schemaDirectory>
<generateDirectory>src/main/javagen</generateDirectory>
</configuration>
</plugin>
Does anyone have any ideas? This is starting to annoy me somewhat...
Edit:
I found out that this has to do with the fact that some xsd files have imported files like so:
<xs:import namespace="http://referenced/namespace"
schemaLocation="referencedSchema.xsd" />
Seems to me like Maven is ignoring the namespace tag. How can I tell Maven to stop doing that?
I can answer my own question from a very, very long time ago. The problem was that we also used the maven jaxws plugin to generate web services from wsdl files. Both plugins actually take the underlying xsf files and generate the data structure classes to the respective packages. So the solution is to remove the jaxb plugin from the pom. All xsds get only generated once.
I am using Apache Maven Checkstyle plugin in my pom.xml.
I am trying to exclude the target directory from the check style scan but no luck so far. Here is the pom code i am trying.
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
<executions>
<execution>
<id>checkstyle-check</id>
<phase>test</phase>
<goals>
<goal>check</goal>
</goals>
</execution>
</executions>
<configuration>
<configLocation>checkstyles.xml</configLocation>
<failsOnError>true</failsOnError>
<failOnViolation>true</failOnViolation>
<consoleOutput>true</consoleOutput>
<includes>**\/*.java,**\/*.groovy</includes>
<excludes>**WHAT GOES HERE TO EXCLUDE THE TARGET DIRECTORY**</excludes>
</configuration>
</plugin>
In Apache Maven Checkstyle Plugin version 3 to specify the location of the source directories we have to use sourceDirectories parameter. Then we can specify only directories of application/library and test sources to be used for Checkstyle:
<sourceDirectories>
<sourceDirectory>${project.build.sourceDirectory}</sourceDirectory>
<sourceDirectory>${project.build.testSourceDirectory}</sourceDirectory>
</sourceDirectories>
Now only src/main/java and src/test/java will be analysed.
Here is my full working example:
<!-- Apache Maven Checkstyle Plugin (checks Java code adheres to a coding standard) -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
<version>${maven-checkstyle-plugin.version}</version>
<executions>
<execution>
<phase>test</phase>
<goals>
<goal>check</goal>
</goals>
</execution>
</executions>
<configuration>
<sourceDirectories>
<sourceDirectory>${project.build.sourceDirectory}</sourceDirectory>
<sourceDirectory>${project.build.testSourceDirectory}</sourceDirectory>
</sourceDirectories>
<!-- relates to https://github.com/checkstyle/checkstyle/blob/master/src/main/resources/google_checks.xml -->
<configLocation>/src/main/resources/checkstyle.xml</configLocation>
</configuration>
</plugin>
<excludes>**/generated/**/*</excludes>
This will remove the generated files from the plugin.
I am using download-maven-plugin to download some of resources to be used in my project. The download is successful and I can use the downloaded file.
However, what I want is to include the downloaded file in the JAR.
Note : The resource file will be included in the JAR when it was pre-downloaded before running the build, but if it is not present (e.g. deleted or I want to update it perhaps) the resource file is not included in the JAR.
Basically what I want is to include the recently downloaded file (from mvn clean install) in the output JAR.
<plugin>
<groupId>com.googlecode.maven-download-plugin</groupId>
<artifactId>download-maven-plugin</artifactId>
<version>1.4.0</version>
<executions>
<execution>
<phase>prepare-package</phase>
<goals>
<goal>wget</goal>
</goals>
<configuration>
<url>https://downloadurl</url>
<outputFileName>error.json</outputFileName>
<outputDirectory>${project.resources.dir}/commons</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>
Same thing happens when I use maven-ant-run plugin.
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<executions>
<execution>
<id>download-files</id>
<phase>prepare-package</phase>
<goals>
<goal>run</goal>
</goals>
<configuration>
<tasks>
<get src="https://downloadurl"
dest="${project.resources.dir}/commons/data.json"
verbose="true"
usetimestamp="true"/>
</tasks>
</configuration>
</execution>
</executions>
</plugin>
Just download it to ${basedir}/target/classes before packaging phase. You don't need it to be in sources in order to include it to JAR.
Solved!
I changed the phase to process-resources..
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<executions>
<execution>
<id>download-files</id>
<phase>process-sources</phase>
<goals>
<goal>run</goal>
</goals>
<configuration>
<tasks>
<get src="https://downloadUrl"
dest="${project.resources.dir}/commons/error.json"
verbose="true"
usetimestamp="true"/>
</tasks>
</configuration>
</execution>
</executions>
</plugin>
We are moving our existing project from Ant + Eclipse to Maven + IntelliJ IDEA.
I am currently using JAXB to generate classes from xsd files. I want to continue the current project structure so i want jaxb2-maven-plugin to generate the classes in a specific location. I have multiple schemes and want to generate the classes in different locations. I'm using multiple plugin execution bindings in order to do that as instructed in the JAXB-2 Maven plugin site.
My problem is that only the first execution is performed. None of the classes in the second execution are generated.
Here is my POM.xml file relevant part:
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>jaxb2-maven-plugin</artifactId>
<version>1.5</version>
<executions>
<execution>
<id>schema1</id>
<goals>
<goal>xjc</goal>
</goals>
<configuration>
<schemaDirectory>${basedir}/src/main/resources/schemes</schemaDirectory>
<schemaFiles>myschema1.xsd</schemaFiles>
<packageName>xml</packageName>
<outputDirectory>${basedir}/src/main/java/com/example/dor/a</outputDirectory>
<arguments>-extension -Xcloneable -Xdefault-value -Xsetters -Xannotate</arguments>
<staleFile>${build.directory}/.jaxb-staleFlag-1</staleFile>
<clearOutputDir>false</clearOutputDir>
</configuration>
</execution>
<execution>
<id>schema2</id>
<goals>
<goal>xjc</goal>
</goals>
<configuration>
<schemaDirectory>${basedir}/src/main/resources/schemes</schemaDirectory>
<schemaFiles>myschema2.xsd</schemaFiles>
<packageName>xml</packageName>
<outputDirectory>${basedir}/src/main/java/com/example/dor/b</outputDirectory>
<arguments>-extension -Xcloneable -Xdefault-value -Xsetters -Xannotate</arguments>
<staleFile>${build.directory}/.jaxb-staleFlag-1</staleFile>
<clearOutputDir>false</clearOutputDir>
</configuration>
</execution>
</executions>
</plugin>
An update answer using version 2.5.0 of the plugin. This would be the configuration:
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>jaxb2-maven-plugin</artifactId>
<version>2.5.0</version>
<executions>
<execution>
<id>schema1</id>
<goals>
<goal>xjc</goal>
</goals>
<configuration>
<packageName>com.your.package</packageName>
<sources>
<source>${project.basedir}/src/main/resources/xsd/sample1/sample1.xsd</source>
</sources>
<clearOutputDir>false</clearOutputDir>
</configuration>
</execution>
<execution>
<id>schema2</id>
<goals>
<goal>xjc</goal>
</goals>
<configuration>
<packageName>com.your.package</packageName>
<sources>
<source>${project.basedir}/src/main/resources/xsd/sample2/sample2.xsd</source>
</sources>
<clearOutputDir>false</clearOutputDir>
</configuration>
</execution>
</executions>
</plugin>
Hope it helps for newer configurations.
I would upgrade to 1.6, and you will have to put the 2 schemas in different packages to stop a conflict in the generated ObjectFactory. Below works for me:
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>jaxb2-maven-plugin</artifactId>
<version>1.6</version>
<executions>
<execution>
<id>schema1</id>
<goals>
<goal>xjc</goal>
</goals>
<configuration>
<schemaDirectory>${basedir}/src/main/resources/schemes</schemaDirectory>
<schemaFiles>myschema1.xsd</schemaFiles>
<packageName>xml.a</packageName>
<outputDirectory>${basedir}/src/main/generated1</outputDirectory>
<clearOutputDir>true</clearOutputDir>
</configuration>
</execution>
<execution>
<id>schema2</id>
<goals>
<goal>xjc</goal>
</goals>
<configuration>
<schemaDirectory>${basedir}/src/main/resources/schemes</schemaDirectory>
<schemaFiles>myschema2.xsd</schemaFiles>
<packageName>xml.b</packageName>
<outputDirectory>${basedir}/src/main/generated2</outputDirectory>
<clearOutputDir>true</clearOutputDir>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
Had the same problem.
Enabled the -X option of maven to see why the second generation is not performed.
The second generation was not run because the staleFile was the same. I had to add to both executions the parameter staleFile having different values:
<staleFile>${project.build.directory}/jaxb2/.xjcStaleFlag1</staleFile>
........
<staleFile>${project.build.directory}/jaxb2/.xjcStaleFlag2</staleFile>
Im using maven-war-plugin in a non-standar file structure.
I can't change the folder names nor the structure; so i use the following to overcome those problems:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.4</version>
<executions>
<execution>
<id>myProject</id>
<phase>package</phase>
<goals>
<goal>war</goal>
</goals>
<configuration>
<warName>myProject</warName>
<warSourceDirectory>${project.basedir}\WebContent</warSourceDirectory>
<webXml>${project.basedir}\WebContent\WEB-INF\web.xml</webXml>
</configuration>
</execution>
</executions>
</plugin>
As you can see, the name of the folder is diferent, but Netbeans find it without problems. I can even see them web. From the project view in the IDE.
But when i try to compile, maven fails to find the web.xml (wich is in that route)
I've already compared the web.xml file path agains the efective pom's path of the webXml tag and they are the same.
I have tried changing the version of the plugin, but it's worthless.
Please help.
The configuration block should be within plugin and not within executions.
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.4</version>
<executions>
<execution>
<id>myProject</id>
<phase>package</phase>
<goals>
<goal>war</goal>
</goals>
</execution>
</executions>
<configuration>
<warName>myProject</warName>
<warSourceDirectory>${project.basedir}\WebContent</warSourceDirectory>
<webXml>${project.basedir}\WebContent\WEB-INF\web.xml</webXml>
</configuration>
</plugin>