I've been trying to get cxf-codegen-plugin working on Java 9 with some resistance. So far I've added java.se.ee to the runtime modules and added the necessary dependencies to maven.
However, when I try to build my sources I get the following error:
DefaultValidationEventHandler: [ERROR]: unexpected element (uri:"http://cxf.apache.org/tools/plugin", local:"databinding"). Expected elements are <{}databinding>,<{}frontend>
Location: node: [databinding: null]
apr. 21, 2018 8:23:57 EM org.apache.cxf.tools.wsdlto.core.PluginLoader loadPlugin
ALLVARLIG: Tools plugin jar:file:/C:/Users/Daniel/.m2/repository/org/apache/cxf/cxf-tools-wsdlto-core/3.2.4/cxf-tools-wsdlto-core-3.2.4.jar!/META-INF/tools-plugin.xml load failed
Any ideas what might be causing this or how to fix it?
Run into the same issue, I ended up changing the plugin configuration and adding the required modules explicitly:
<plugin>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-codegen-plugin</artifactId>
<version>3.2.4</version>
<configuration>
<additionalJvmArgs>--add-modules java.xml.bind,java.xml.ws</additionalJvmArgs>
<fork>once</fork>
</configuration>
</plugin>
It seems to work for Java 9/10 but certainly not going to work for Java 11.
As the documentation said you have to start with version 3.2.5 cxf documentation for java 9
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-codegen-plugin</artifactId>
<version>3.2.5</version>
I tested with java 10:
<plugin>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-codegen-plugin</artifactId>
<version>3.2.4</version>
<configuration>
<fork>true</fork>
<additionalJvmArgs>--add-modules java.activation,java.xml.bind,java.xml.ws --add-exports=java.xml.bind/com.sun.xml.internal.bind.v2.runtime=ALL-UNNAMED --add-exports=jdk.xml.dom/org.w3c.dom.html=ALL-UNNAMED --add-exports=java.xml/com.sun.org.apache.xerces.internal.impl.xs=ALL-UNNAMED --add-exports=java.xml.bind/com.sun.xml.internal.bind.marshaller=ALL-UNNAMED --add-opens java.xml.ws/javax.xml.ws.wsaddressing=ALL-UNNAMED --add-opens java.base/java.security=ALL-UNNAMED --add-opens java.base/java.net=ALL-UNNAMED --add-opens java.base/java.lang=ALL-UNNAMED --add-opens java.base/java.util=ALL-UNNAMED --add-opens java.base/java.util.concurrent=ALL-UNNAMED</additionalJvmArgs>
</configuration>
</plugin>
My maven execution file (windows):
set PATH=C:\Users\user\Documents\programs\jdk-10\bin;%PATH%
set JAVA_HOME=C:\Users\user\Documents\programs\jdk-10
set MAVEN_OPTS=--add-modules java.xml.bind
mvn clean install
Using --add-modules fails when running with Java 8. To make the build compatible with both Java 8 and Java 9, I've added javax.xml.bind:jaxb-api as dependency of the plugin instead, which seems to work fine.
<plugin>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-codegen-plugin</artifactId>
<version>${cxf.version}</version>
<executions>
<!-- ... -->
</executions>
<dependencies>
<dependency>
<groupId>javax.xml.bind</groupId>
<artifactId>jaxb-api</artifactId>
<version>2.3.1</version>
</dependency>
</dependencies>
</plugin>
Related
Recently , the project has been migrated from Java8 to Java17 . The mutation test coverage is also checked for the project and before migration there was no known issues during the command run of mvn clean install org.pitest:pitest-maven:mutationCoverage
After migration , the issue is reported as Execution default-cli of goal org.pitest:pitest-maven:1.7.6:mutationCoverage failed: 6 tests did no
t pass without mutation when calculating line coverage. Mutation testing requires a green suite.
The pom.xml file has
<plugin>
<groupId>org.pitest</groupId>
<artifactId>pitest-maven</artifactId>
<version>1.6.2</version>
<dependencies>
<dependency>
<groupId>org.pitest</groupId>
<artifactId>pitest-junit5-plugin</artifactId>
<version>0.12</version>
</dependency>
</dependencies>
</plugin>
Note: There are few test cases contain Whitebox.invokeMethod to invoke the private method. There are no issues during the run of the test cases - mvn clean install.
The actual problem occurred during the run of mutation test coverage with the command - mvn clean install org.pitest:pitest-maven:mutationCoverage
I tried to include the option --add-opens java.base/jdk.internal.misc=ALL-UNNAMED in pom.xml file but of no use.
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<argLine>
--add-opens java.base/jdk.internal.misc=ALL-UNNAMED
</argLine>
</configuration>
</plugin>
I tried to change the version of pitest-maven as 1.7.3 from 1.6.2 and pitest-junit5-plugin as 0.15 from 0.12. This is also not useful.
Any idea or suggestion to overcome the pitest-maven in Java17 with WhiteBox.invokeMethod in test cases.
The correct version of pitest-junit5-plugin was helpful to get rid of the error.
<groupId>org.pitest</groupId>
<artifactId>pitest-maven</artifactId>
<version>1.11.0</version>
<groupId>org.pitest</groupId>
<artifactId>pitest-junit5-plugin</artifactId>
<version>1.1.2</version>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>5.8.2</version>
Along with the junit pitest-junit5-plugin addition , adding --add-opens is also required ,
<plugin>
<groupId>org.pitest</groupId>
<artifactId>pitest-maven</artifactId>
<version>1.11.0</version>
<dependencies>
<dependency>
<groupId>org.pitest</groupId>
<artifactId>pitest-junit5-plugin</artifactId>
<version>1.1.2</version>
</dependency>
</dependencies>
<configuration>
<argLine>
--add-opens java.base/java.lang=ALL-UNNAMED
</argLine>
</configuration>
</plugin>
I'm using the swagger-codegen-maven-plugin within my pom to generate a client. Here is my plugin info:
<plugins>
<plugin>
<groupId>io.swagger</groupId>
<artifactId>swagger-codegen-maven-plugin</artifactId>
<version>2.4.9</version>
<executions>
<execution>
<goals>
<goal>generate</goal>
</goals>
<configuration>
<inputSpec>${project.basedir}/src/main/resources/api.json</inputSpec>
<language>java</language>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
Using:
java version "1.8.0_221"
Apache Maven 3.6.1
I had many errors when running mvn compile, as the package names could not be found in my repo e.g.
[ERROR]
//target/generated-sources/swagger/src/main/java/io/swagger/client/model/.java:[18,23]
package com.google.gson does not exist
To overcome the errors and enable a successful mvn compile, I have had to name the missing packages within my pom's dependencies e.g.
<dependencies>
<dependency>
<groupId>io.gsonfire</groupId>
<artifactId>gson-fire</artifactId>
<version>1.0.0</version>
</dependency>
</dependencies>
I don't believe this is best practice, as I have to specify the version myself without knowing the actual version that the source has used.
My question is, what is the best practice for generating a client using maven when there are packages which can't be resolved by the swagger-codegen-plugin? Alternatively, please advise if the resolution I have found to overcome the issue is actually the best practice in this scenario?
Thanks.
To generate java classes from XSD (for reading XML files), we used jaxb2-maven-plugin and Java8.
For java 11, we get many issues...
What libraries and plugins do work (today), allowing to generate java code from XSD using java 11 and maven? If possible point out different solutions, such as with cxf-xjc-plugin, jaxb2-Maven-Plugin and others.
I've just investigated the same topic. The best way for Java 11 is to use cxf-xjc-plugin. It's a Maven plugin. No other Maven plugin is able to work under Java 11 without annoying workarounds.
I've published a complete example with cxf-xjc-plugin here: https://artofcode.wordpress.com/2019/02/28/generating-classes-from-xsd-under-java-11-the-right-way/
I was able to get Jaxb2-maven-plugin to work with Java 11. By default the generated classes will be created in the generated classes package. My only gripe is that it doesn't implement toString methods. If I ever figure that out i'll update this.
<dependency>
<groupId>org.codehaus.mojo</groupId>
<artifactId>jaxb2-maven-plugin</artifactId>
<version>2.5.0</version>
</dependency>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>jaxb2-maven-plugin</artifactId>
<version>2.5.0</version>
<executions>
<execution>
<id>xjc-foo</id>
<goals>
<goal>xjc</goal>
</goals>
<configuration>
<sourceType>wsdl</sourceType>
<sources>
<!-- if you put path only, it will read any wsdl or xsd file -->
<!-- if you have xsd that is imported in wsdl, then make sure you point it wsdl file -->
<source>${project.basedir}/src/main/resources/schemas/foo.wsdl</source>
</sources>
<clearOutputDir>false</clearOutputDir>
<packageName>foo</packageName>
</configuration>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>javax.activation</groupId>
<artifactId>javax.activation.api</artifactId>
<version>1.2.0</version>
</dependency>
</dependencies>
</plugin>
Since today we can't build our jasper file any more. We use the jasperreports-maven-plugin for this.
In maven 2.2.1, this was configured like this:
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>jasperreports-maven-plugin</artifactId>
<version>1.0-beta-2</version>
<executions>
<execution>
<goals>
<goal>compile-reports</goal>
</goals>
<configuration>
<sourceDirectory>${basedir}/src/main/resources/reports</sourceDirectory>
<outputDirectory>>${project.build.directory}/classes/reports</outputDirectory>
</configuration>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>net.sf.jasperreports</groupId>
<artifactId>jasperreports</artifactId>
<version>5.5.1</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
<version>2.5</version>
<scope>compile</scope>
</dependency>
</dependencies>
<configuration>
<sourceDirectory>C:\Windows\TEMP/src/main/resources/reports</sourceDirectory>
<outputDirectory>C:\Windows\TEMP\target/classes/reports</outputDirectory>
</configuration>
</plugin>
But, as said, since today, we got this build error:
...
Downloading: http://repo1.maven.org/maven2/itext/itext/4.2.0/itext-4.2.0.jar
[INFO] ------------------------------------------------------------------------
[ERROR] BUILD ERROR
[INFO] ------------------------------------------------------------------------
[INFO] Failed to resolve artifact.
Missing:
----------
1) itext:itext:jar:4.2.0
Try downloading the file manually from the project website.
Then, install it using the command:
mvn install:install-file -DgroupId=itext -DartifactId=itext -Dversion=4.2.0 -Dpackaging=jar -Dfile=/path/to/file
Alternatively, if you host your own repository you can deploy the file there:
mvn deploy:deploy-file -DgroupId=itext -DartifactId=itext -Dversion=4.2.0 -Dpackaging=jar -Dfile=/path/to/file -Durl=[url] -DrepositoryId=[id]
Path to dependency:
1) org.codehaus.mojo:jasperreports-maven-plugin:maven-plugin:1.0-beta-2
2) jasperreports:jasperreports:jar:1.2.0
3) itext:itext:jar:4.2.0
I think another question (Dependency error in jasper-reports from itext) is related to his. And I tried the solution of Meher to use maven 3.2.3. This seems to be a solution, but we can't upgrade (now) to this maven version. So I need another solution to resolve this issue. Any ideas? I already tried to exclude dependencies and use fixed versions, but I haven't managed to succeed my build. What I mean is this:
<!-- Compile jasper reports -->
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>jasperreports-maven-plugin</artifactId>
<version>1.0-beta-2</version>
<configuration>
<sourceDirectory>${basedir}/src/main/resources/reports</sourceDirectory>
<outputDirectory>${project.build.directory}/classes/reports</outputDirectory>
</configuration>
<executions>
<execution>
<goals>
<goal>compile-reports</goal>
</goals>
<phase>generate-sources</phase>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>org.codehaus.mojo</groupId>
<artifactId>jasperreports-maven-plugin</artifactId>
<version>1.0-beta-2</version>
<exclusions>
<exclusion>
<groupId>net.sf.jasperreports</groupId>
<artifactId>jasperreports</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>net.sf.jasperreports</groupId>
<artifactId>jasperreports</artifactId>
<version>5.5.1</version>
<exclusions>
<exclusion>
<groupId>com.lowagie</groupId>
<artifactId>itext</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>com.lowagie</groupId>
<artifactId>itext</artifactId>
<version>2.1.7</version>
</dependency>
</dependencies>
</plugin>
Why is the plugin still searching for itext:itext:jar:4.2.0? Any ideas or suggestions to solve this?
Thanks!
Background:
iText Group NV is owner of the groupId com.lowagie and com.itextpdf on Maven Central. iText Group NV released com.lowagie:itext version 2.1.7 in July 2009. The next release by iText Group NV was com.itextpdf:itextpdf version 5.0.0, in December 2009. The current version (as of December 2015) is 5.5.8.
iText Group NV never released a version 4.x.x.
Somewhere in 2011, a company called InProTopia "hijacked" com.lowagie and released a fork of iText with version number 4.2.0. According to the [Guidelines of Maven Central][1], they should have published this as com.inprotopia:itext, but they didn't. Later they published a 4.2.1 with their own patches. Recently iText Group NV took ownership of com.lowagie and published a version 4.2.2 with redirection to com.itextpdf:itextpdf version 5.5.6 (the current version at that time).
Possible solutions:
If you need com.lowagie iText, you need to set a fixed version in your pom.xml. The last official release is 2.1.7.
If you need iText 4.x.x, contact InProTopia. Good luck with that, because their website is down, and as far as I could find out, that company no longer exists.
If you don’t mind which version of iText you use, use the current version of iText published by iText Group NV, com.itextpdf:itextpdf 5.5.8 (as of December 2015).
Use the latest version of jasperreports. It has an explicit dependency on iText 2.1.7.js, which a custom iText version for Jasper Reports.
More info at the iText blog.
http://itextpdf.com/maven-update-problem-with-itext-4.2.2
[1] https://maven.apache.org/guides/mini/guide-central-repository-upload.html
I resolved my issue by using ant to build my jasper report. So I skipped the plugin.
My ant task looks like this:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<version>${maven-antrun-plugin.version}</version>
<executions>
<execution>
<id>compile-jasper-reports</id>
<goals>
<goal>run</goal>
</goals>
<phase>generate-sources</phase>
<configuration>
<target>
<echo message="Start compile of jasper reports"/>
<mkdir dir="${project.build.directory}/classes/reports"/>
<taskdef name="jrc" classname="net.sf.jasperreports.ant.JRAntCompileTask" classpathref="maven.compile.classpath" />
<jrc srcdir="${basedir}/src/main/resources/reports"
destdir="${project.build.directory}/classes/reports"
tempdir="${project.build.directory}/classes/reports"
keepjava="true"
xmlvalidation="true">
<classpath refid="maven.compile.classpath"/>
<include name="**/*.jrxml"/>
</jrc>
</target>
</configuration>
</execution>
</executions>
</plugin>
Try add this repository:
<repository>
<url>https://repository.liferay.com/nexus/content/groups/public/</url>
<id>liferay</id>
<name>Liferay</name>
</repository>
Good luck!
What are the appropriate configuration/versions/plugin versions for the aspectj plugin to use Java 7?
I am trying to upgrade from Java 6 to Java 7, and the aspectj compiler seems to not be compiling Java 7. I'm specifying the java source and target version as 1.7 in the plugin configuration for aspectj plugin and for the maven compiler plugin. I introduced Java7-specific syntax to my code, adding several language features such as string in switch and the diamond operator. During the build, I get errors from aspectj about the Java7 syntax. The first sign that things are going wrong is:
[INFO] --- aspectj-maven-plugin:1.4:compile (default) # site ---
[ERROR] Cannot switch on a value of type String. Only int values or enum constants are permitted
[ERROR] Cannot instantiate the type HashSet<?>
[ERROR] Syntax error on token "<", ? expected after this token
If I remove the executions section from the aspectj maven plugin so it doesn't run, and use mvn clean install, the new code compiles fine. So I think it's something misconfigured with aspectj. Here is my plugin configuration:
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<java-version>1.7</java-version>
<org.aspectj-version>1.6.11</org.aspectj-version>
</properties>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>aspectj-maven-plugin</artifactId>
<version>1.4</version>
<dependencies>
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjrt</artifactId>
<version>${org.aspectj-version}</version>
</dependency>
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjtools</artifactId>
<version>${org.aspectj-version}</version>
</dependency>
</dependencies>
<executions>
<execution>
<goals>
<goal>compile</goal>
<goal>test-compile</goal>
</goals>
</execution>
</executions>
<configuration>
<complianceLevel>${java-version}</complianceLevel>
<encoding>${project.build.sourceEncoding}</encoding>
<outxml>true</outxml>
<source>${java-version}</source>
<target>${java-version}</target>
</configuration>
</plugin>
Also aspectjrt is defined as a dependency outside of the plugins section
<dependencies>
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjrt</artifactId>
<version>${org.aspectj-version}</version>
</dependency>
<dependencies>
I updated from 1.6.11 to 1.7.0, which has been released since I asked this question. I no longer have any aspectj/Java1.7 issues, so that resolves this question.