Is it possible to add custom annotations to the XJC classpath, while they are defined within my project itself? This when using the maven jaxb2-annotate-plugin.
The problem regards this piece of the documentation:
Annotation classes must be known in compile time. I.e. annotation classes must be made available in the XJC classpath. If you want to use your own annotations, you have to pre-compile them and add your annotation classes to the XJC classpath.
When I make a seperate project and add it to the plugin, it works fine as shown in the documentation examples.
<plugin>
<groupId>org.jvnet.jaxb2.maven2</groupId>
<artifactId>maven-jaxb2-plugin</artifactId>
<version>0.12.3</version>
<executions>
<execution>
<id>generate</id>
<phase>process-resources</phase>
<goals>
<goal>generate</goal>
</goals>
<configuration>
<args>
<arg>-Xannotate</arg>
</args>
<plugins>
<plugin>
<groupId>org.jvnet.jaxb2_commons</groupId>
<artifactId>jaxb2-basics-annotate</artifactId>
<version>1.0.2</version>
</plugin>
<plugin>
<groupId>com.acme</groupId>
<artifactId>external-project</artifactId>
<version>1.0.0</version>
</plugin>
</plugins>
</configuration>
</execution>
</executions>
</plugin>
But I'd like to use the annotation that resides in the same project. How do I let it get picked up? If I compile it in a stage before process-resources, with the following piece:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.2</version>
<executions>
<execution>
<id>compile</id>
<phase>process-resources</phase>
<goals>
<goal>compile</goal>
</goals>
</execution>
</executions>
</plugin>
The class gets compiled before the generation from my XSD's, but I still get the exception AnnotationClassNotFoundException. I'd like to avoid making seperate projects and/or modules just for adding annotations. How come it can't find my classes and the only way to provide annotations seems to be external projects/modules?
I have found the solution to my problem.
When configuring the maven-jaxb2-plugin plugin, it's possible to provide dependencies for that plugin. When providing my own project as the dependency, it can find the classes for it. So the following works out:
<plugin>
<groupId>org.jvnet.jaxb2.maven2</groupId>
<artifactId>maven-jaxb2-plugin</artifactId>
<version>0.12.1</version>
<executions>
<execution>
<id>generate</id>
<phase>process-resources</phase>
<goals>
<goal>generate</goal>
</goals>
<configuration>
<args>
<arg>-Xannotate</arg>
</args>
<plugins>
<plugin>
<groupId>org.jvnet.jaxb2_commons</groupId>
<artifactId>jaxb2-basics-annotate</artifactId>
<version>1.0.2</version>
</plugin>
</plugins>
</configuration>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>com.example</groupId>
<artifactId>current-project</artifactId>
<version>${project.version}</version>
</dependency>
</dependencies>
</plugin>
It is required for your annotations to be compiled beforehand however. So to compile it beforehand, the following plugin should be added before the maven-jaxb2-plugin
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.5.1</version>
<executions>
<execution>
<phase>process-resources</phase>
<id>compile</id>
<goals>
<goal>compile</goal>
</goals>
</execution>
</executions>
</plugin>
The problem with that is the first time of mvn clean install.
What if you haven't compiled it yet? For example go to your .m2 or mavel-local-repo and cancel your project and then do mvn clean install and see if it fails
Related
I want to move Karate tests from src/test to a new folder src/it because it makes sense to me to have integration tests separated from unit tests.
Is that possible?
I tried to put java classes in src/it/java and features in src/it/resources and Karate tests run, but without test cases.
Thanks in advance.
Issue was solved using a Maven plugin to add src/it/java as test sources and src/it/resources as test resources:
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<version>1.5</version>
<executions>
<execution>
<id>add-test-source</id>
<goals>
<goal>add-test-source</goal>
</goals>
<configuration>
<sources>
<source>src/it/java</source>
</sources>
</configuration>
</execution>
<execution>
<id>add-test-resource</id>
<goals>
<goal>add-test-resource</goal>
</goals>
<configuration>
<resources>
<resource>
<directory>src/it/resources</directory>
</resource>
</resources>
</configuration>
</execution>
</executions>
</plugin>
I use maven-jaxb2-plugin. It generate my classes in the correct directory, but on Eclipse Neon.2 Release (4.6.2), the folder is not automaticaly added to the classpath.
Here is my plugin config :
<build>
<plugins>
<plugin>
<groupId>org.jvnet.jaxb2.maven2</groupId>
<artifactId>maven-jaxb2-plugin</artifactId>
<version>0.13.1</version>
<executions>
<execution>
<goals>
<goal>generate</goal>
</goals>
</execution>
</executions>
<configuration>
<addCompileSourceRoot>true</addCompileSourceRoot>
<generateDirectory>${project.build.directory}/generated-sources/jaxb</generateDirectory>
<schemaDirectory>src/main/resources/xsd</schemaDirectory>
<generatePackage>foo.bar.pojo</generatePackage>
</configuration>
</plugin>
</plugins>
</build>
Is it possible with maven-jaxb2-plugin to define the genearted directory as source folder ? If yes, how ?
Eclipse shows me an error in the pom.xml on <execution> :
Execution default of goal org.jvnet.jaxb2.maven2:maven-jaxb2-plugin:0.13.1:generate failed: A required class was missing while executing org.jvnet.jaxb2.maven2:maven-jaxb2-plugin:0.13.1:generate: com/sun/xml/bind/api/ErrorListener
To fix my problem, I had to change the version of the plugin.
From :
<version>0.13.1</version>
To :
<version>0.12.1</version>
I'm using JDK 1.6 (due to dependencies) and to generate classes from xsd, I have added maven-jaxb2 plugin as shown below in pom.xml.
But the eclipse (Kepler) complains as below.
Error parsing the command line [[-Xsimplify, -episode,
D:\test\workspace\sample\target\generated-sources\xjc\META-INF\sun-jaxb.episode]]
(org.jvnet.jaxb2.maven2:maven-jaxb2-plugin:0.8.1:generate:jaxb-test:generate-sources)
pom.xml
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
<plugin>
<groupId>org.jvnet.jaxb2.maven2</groupId>
<artifactId>maven-jaxb2-plugin</artifactId>
<version>0.9.0</version>
<executions>
<execution>
<id>jaxb-test</id>
<phase>generate-sources</phase>
<goals>
<goal>generate</goal>
</goals>
<configuration>
<forceRegenerate>true</forceRegenerate>
<schemaDirectory>src/main/resources</schemaDirectory>
<schemaIncludes>
<include>sample.xsd</include>
</schemaIncludes>
<xjbSources>
<xjbSource>bindings.xjb</xjbSource>
</xjbSources>
</configuration>
</execution>
</executions>
<configuration>
<extension>true</extension>
<args>
<arg>-Xsimplify</arg>
</args>
<plugins>
<plugin>
<groupId>org.jvnet.jaxb2_commons</groupId>
<artifactId>jaxb2-basics</artifactId>
<version>0.6.0</version>
</plugin>
</plugins>
</configuration>
</plugin>
</plugins>
Try to upgrade to maven-jaxb2-plugin 0.13.1, and jaxb2-basics 0.11.0.
The versions you have now are very old already.
I am trying to run Sonar build on Jenkins. My project contains both Junit and Cucumber tests. I verified the log files after build, the Sonar build kicks off after normal maven build and picks only the Junit tests but not Cucumber tests.
I have the following versions and plugins available in my POM file. Please let me know if any one has come across the similar issue and fixed it. Many Thanks!
Junit version 4.11
Cucumber version 1.1.2
Sonar version 3.5.1
<plugin>
<groupId>org.mortbay.jetty</groupId>
<artifactId>jetty-maven-plugin</artifactId>
<executions>
<execution>
<id>start-jetty</id>
<phase>process-test-classes</phase>
<goals>
<goal>run</goal>
</goals>
<configuration>
<scanIntervalSeconds>0</scanIntervalSeconds>
<daemon>true</daemon>
</configuration>
</execution>
<execution>
<id>stop-jetty</id>
<phase>prepare-package</phase>
<goals>
<goal>stop</goal>
</goals>
</execution>
</executions>
<configuration>
<stopPort>8999</stopPort>
<stopKey>STOP</stopKey>
<connectors>
<connector implementation="org.eclipse.jetty.server.nio.SelectChannelConnector">
<port>8997</port>
<maxIdleTime>3600000</maxIdleTime>
</connector>
</connectors>
<systemProperties>
<systemProperty>
<name>dqs.env</name>
<value>local</value>
</systemProperty>
</systemProperties>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<excludes>
<exclude>**/*RunDQSWsTest.java</exclude>
</excludes>
</configuration>
<executions>
<execution>
<id>integration-test</id>
<goals>
<goal>test</goal>
</goals>
<phase>integration-test</phase>
<configuration>
<excludes>
<exclude>none</exclude>
</excludes>
<includes>
<include>**/*RunDQSWsTest.java</include>
</includes>
</configuration>
</execution>
</executions>
</plugin>
RunDQSWsTest.java is the main file which runs all the .feature files
I am getting the following error on the annox plugin for jaxb generation
[ERROR] file:/Users/dhiller/Space/ifp-core/framework/src/main/resources/schemas/common_2012_04.xsd[5,136]
org.xml.sax.SAXParseException: Unsupported binding namespace "http://annox.dev.java.net". Perhaps you meant "http://java.sun.com/xml/ns/jaxb/xjc"?
Here is the code I have. The versions must be screwed up somehow? Anyone have some working example with all the version numbers
<plugin>
<groupId>org.jvnet.jaxb2.maven2</groupId>
<artifactId>maven-jaxb21-plugin</artifactId>
<version>0.8.1</version>
<executions>
<execution>
<goals>
<goal>generate</goal>
</goals>
</execution>
</executions>
<configuration>
<args>
<arg>-XtoString</arg>
<arg>-Xequals</arg>
<arg>-XhashCode</arg>
<arg>-Xcopyable</arg>
</args>
<plugins>
<plugin>
<groupId>org.jvnet.jaxb2_commons</groupId>
<artifactId>jaxb2-basics</artifactId>
<version>0.6.3</version>
</plugin>
</plugins>
</configuration>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>jaxb2-maven-plugin</artifactId>
<version>1.3.1</version>
<executions>
<execution>
<goals>
<goal>xjc</goal>
</goals>
</execution>
</executions>
<configuration>
<clearOutputDir>false</clearOutputDir>
<schemaDirectory>${basedir}/src/main/resources/schemas</schemaDirectory>
<schemaFiles>externalaction_2012_03.xsd,common_2012_04.xsd,utilities_2012_03.xsd</schemaFiles>
<outputDirectory>${project.build.directory}/generated-sources</outputDirectory>
<bindingDirectory>${basedir}/src/main/xjb</bindingDirectory>
<bindingFiles>bindings.xjb.xml</bindingFiles>
<extension>true</extension>
</configuration>
</plugin>
I think you are missing some dependencies from <plugin>. Try this code:
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>jaxb2-maven-plugin</artifactId>
<version>1.5</version>
<executions>
<execution>
<id>xjc</id>
<goals>
<goal>xjc</goal>
</goals>
<configuration>
<extension>true</extension>
<arguments>-Xannotate</arguments>
</configuration>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>org.jvnet.jaxb2_commons</groupId>
<artifactId>jaxb2-basics-annotate</artifactId>
<version>0.6.4</version>
</dependency>
<dependency>
<groupId>com.sun.codemodel</groupId>
<artifactId>codemodel</artifactId>
<version>2.6</version>
</dependency>
</dependencies>
</plugin>
why is this posting as a comment. Trying to post the answer which I posted here
JAXB External Custom Binding XJC Issue - Parsing results in empty node