Java 11 Hibernate Validator module not found error - java

I am having trouble migrating my project to Java 11 from Java 8 with Hibernate validator.
I get the following error while attempting to build my project with maven:
[INFO] --- maven-processor-plugin:3.3.3:process (default) # maple-orm ---
[ERROR] diagnostic: ...\module-info.java:19: error: module not found: org.hibernate.validator
requires org.hibernate.validator;
The plugin in the pom for maven-processor-plugin is defined as follows:
<groupId>org.bsc.maven</groupId>
<artifactId>maven-processor-plugin</artifactId>
<version>3.3.3</version>
<executions>
<execution>
<phase>generate-sources</phase>
<goals>
<goal>process</goal>
</goals>
<configuration>
<processors>
<processor>org.hibernate.jpamodelgen.JPAMetaModelEntityProcessor</processor>
</processors>
</configuration>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-jpamodelgen</artifactId>
<version>5.4.10.Final</version>
</dependency>
</dependencies>
</plugin>
And the module-info.java looks like this:
module test.module {
...
requires org.hibernate.validator;
}
Is there something specific that I am missing in order to fix this issue with JPMS?

As per documentation from Github repository, Release 3.3.3. maven-processor-plugin supports targets is 9
--release release
Compiles against the public, supported and documented API for a specific VM version.
Supported release targets are 6, 7, 8, and 9.

I was able to get a solution to this problem following fabfas answer. I would suggest upgrading to version 4.0 of maven-processor-plugin and specify the proper plugin to run. Please also keep in mind I am using the jakarta suffixed libraries so this may require some fine tuning.
The module name is indeed org.hibernate.validator
<plugin>
<groupId>org.bsc.maven</groupId>
<artifactId>maven-processor-plugin</artifactId>
<version>4.0</version>
<executions>
<execution>
<phase>generate-sources</phase>
<goals>
<goal>process</goal>
</goals>
<configuration>
<processors>
<processor>org.hibernate.jpamodelgen.JPAMetaModelEntityProcessor</processor>
</processors>
</configuration>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-jpamodelgen-jakarta</artifactId>
<version>${hibernate.version}</version>
</dependency>
</dependencies>
</plugin>

Related

Aspectj not working after transition java 8 to java 11 ee project

I have Java EE (javaee-api version: 8) project running and after migrating to java 11 aspect does not seem to work.
Compiled .class with an annotation that we use for aspects is not modified by the plugin also as it was before on java 8...
My dependencies at the moment are.
<dependencies>
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjrt</artifactId>
<version>1.9.5</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>aspectj-maven-plugin</artifactId>
<version>1.14.0</version>
<configuration>
<complianceLevel>11</complianceLevel>
<source>11</source>
<target>11</target>
</configuration>
<executions>
<execution>
<phase>process-sources</phase>
<goals>
<goal>compile</goal>
<goal>test-compile</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
Also tried to use this plugin.
<plugin>
<groupId>com.nickwongdev</groupId>
<artifactId>aspectj-maven-plugin</artifactId>
<version>1.12.6</version>
my aspect looks like this.
public aspect Aspect {
Object around(): execution(* *(..)) && #annotation(annotation) {
}
}
Any thoughts on this?
Found the solution.
I have also updated maven-compiler-plugin to version 3.10.1 which seems to be caused the issue.
But after downgrading it to 2.5.1 - everything is working fine

How to exclude maven plugin configuration (unrecognized parameter -encoding)

I am using jaxws-maven-plugin to generate some JAX-WS clients based on WSDL files.
I need to use JDK 1.6 so I am executing with JAX-WS Tools 2.1.7
<dependency>
<groupId>com.sun.xml.ws</groupId>
<artifactId>jaxws-tools</artifactId>
<version>2.1.7</version>
</dependency>
If I use recent versions of jaxws-maven-plugin 2.2.1 or 2.3 over the 2.1.7 jaxws-tools my build doesn't work because an invalid -encoding parameter is added to the command line.
unrecognized parameter -encoding
Full command is
[DEBUG] cmd.exe /X /C ""C:\Program Files\Java\jdk1.6.0_45\jre\bin\java.exe" -Xbootclasspath/p:.m2\repository\javax\xml\bind\jaxb-api\2.1\jaxb-api-2.1.jar;.m2\repository\javax\xml\soap\saaj-api\1.3\saaj-api-1.3.jar;.m2\repository\javax\xml\ws\jaxws-api\2.1\jaxws-api-2.1.jar org.jvnet.jax_ws_commons.jaxws.Invoker com.sun.tools.ws.wscompile.WsimportTool -keep -s <some dir> -d <some dir> -encoding UTF-8 -p <some package> file:<some wsdl file>"
The following pom.xml is working fine, I use 2.2 which does not send the encoding parameter.
<build>
<plugins>
<plugin>
<groupId>org.jvnet.jax-ws-commons</groupId>
<artifactId>jaxws-maven-plugin</artifactId>
<version>2.2</version> <!-- This version works fine -->
<executions>
<execution>
<goals>
<goal>wsimport</goal>
</goals>
</execution>
</executions>
<configuration>
<wsdlDirectory>src/wsdl</wsdlDirectory>
<sourceDestDir>src/main/java</sourceDestDir>
<wsdlFiles>
<wsdlFile>ConsultarStatusNfe.wsdl</wsdlFile>
</wsdlFiles>
<!-- for JDK 6 compilation compatibility -->
<xnocompile>false</xnocompile>
</configuration>
<dependencies>
<dependency>
<groupId>com.sun.xml.ws</groupId>
<artifactId>jaxws-tools</artifactId>
<version>2.1.7</version>
</dependency>
</dependencies>
</plugin>
</plugins>
</build>
I was able to use the latest versions by setting the <target>2.1</target> configuration.
<plugin>
<groupId>org.jvnet.jax-ws-commons</groupId>
<artifactId>jaxws-maven-plugin</artifactId>
<version>2.3</version>
<executions>
<execution>
<phase/>
<goals>
<goal>wsimport</goal>
</goals>
</execution>
</executions>
<configuration>
<wsdlDirectory>src/wsdl</wsdlDirectory>
<sourceDestDir>src/main/generated</sourceDestDir>
<wsdlFiles>
<wsdlFile>myfile.wsdl</wsdlFile>
</wsdlFiles>
<packageName>com.souzacruz.pwnfeintegrator</packageName>
<!-- for JDK 6 compilation compatibility -->
<xnocompile>false</xnocompile>
<target>2.1</target>
</configuration>
<dependencies>
<dependency>
<groupId>com.sun.xml.ws</groupId>
<artifactId>jaxws-tools</artifactId>
<version>2.2.10</version>
</dependency>
</dependencies>
</plugin>
the version 2.1.1 of the plug in jaxws-tools does not support the parameter "-encoding". Use a later version, for example 2.2.6 that it does.

JAXB mixed versions? undefined 'required' attribute

Im generating some classes from WSDL files with wsimport maven plugin # Mule Anypoint Studio 3.5 with JDK 1.7_55
I'm using jaxb 2.2.7 and remove version 2.1.9 from mule libs and replaced by 2.2.7.
When i compile, sometines works fine but others i take this error multiple times:
The attribute required is undefined for the annotation type XmlElementRef
I tried to create an endorsed folder in JDK and include .jars needed,
Do you know any way to avoid this error or replace this libs correctly?
I include this dependencies in pom.xml
<dependency>
<groupId>com.sun.xml.ws</groupId>
<artifactId>jaxws-tools</artifactId>
<version>2.2.7</version>
</dependency>
<dependency>
<groupId>com.sun.xml.bind</groupId>
<artifactId>jaxb-impl</artifactId>
<version>2.2.7</version>
</dependency>
<!-- xjc -->
<dependency>
<groupId>com.sun.xml.bind</groupId>
<artifactId>jaxb-xjc</artifactId>
<version>2.2.7</version>
</dependency>
<dependency>
<groupId>javax.xml.bind</groupId>
<artifactId>jaxb-api</artifactId>
<version>2.2.7</version>
</dependency>
<dependency>
<groupId>org.codehaus.mojo</groupId>
<artifactId>idlj-maven-plugin</artifactId>
<version>1.2.1</version>
</dependency>
wsimport is 2.2.7 to
wsimport settings:
<plugin>
<groupId>org.jvnet.jax-ws-commons</groupId>
<artifactId>jaxws-maven-plugin</artifactId>
<version>2.2.1</version>
<executions>
<execution>
<id>wsdl-AMANSequenceService-exec</id>
<goals>
<goal>wsimport</goal>
</goals>
<configuration>
<args>
<arg>-version</arg>
<arg>-B-nv</arg>
<arg>-Xdebug</arg>
<arg>-B-XautoNameResolution</arg>
<arg>-Xendorsed</arg>
</args>
<extension>true</extension>
<sourceDestDir>${basedir}/src/main/java</sourceDestDir>
<destDir>${basedir}/src/main/java</destDir>
<extension>true</extension>
<wsdlDirectory>${basedir}/src/main/resources/SICG/AMANSequenceService</wsdlDirectory>
<wsdlFiles>
<wsdlFile>AMANSequenceService.wsdl</wsdlFile>
</wsdlFiles>
<bindingFiles>
<bindingFile>${basedir}/src/main/resources/SICG/external/binding.xjb</bindingFile>
</bindingFiles>
</configuration>
</execution>
We can fix the above behavior by replacing the following jars in Mule CE Runtime Folder (C:\AnypointStudio\plugins\org.mule.tooling.server.3.5.0_3.5.0.201405141856\mule\lib\opt):
jaxb-api-2.1 with jaxb-api-2.2.jar
jaxb-impl-2.1.9 with jaxb-impl-2.2.7.jar
jaxb-xjc-2.1.9 with jaxb-xjc-2.2.7.jar
It would be useful if Mule developers updated these packages to the newest distributions.
The location of your endorsed jars is incorrect. It should be:
%JAVA_HOME%\jre\lib\endorsed
which in your case is:
C:\Java\jdk1.7.0_55\jre\lib\endorsed
Put the jaxb jars here, remove all others and re-try.
This is for people who find this old posting from the search engines.
I was getting the same error message in a new project that I created in Eclipse. The solution was to:
1.) create a new JAXB project instead of some other project type,
2.) specify JDK7,
3.) Specify version 2.2 of JAXB
In Mule specific case, if you are stuck with JAXB2.1, you can force Apache CXF WSDL2Java to generate JAXB2.1 compliant client code
<plugin>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-codegen-plugin</artifactId>
<version>3.1.6</version>
<executions>
<execution>
<id>generate-sources-file1</id>
<phase>generate-sources</phase>
<configuration>
<defaultOptions>
<frontEnd>jaxws21</frontEnd>
</defaultOptions>
<sourceRoot>${project.build.directory}/generated/service-file1</sourceRoot>
<wsdlOptions>
<wsdlOption>
<wsdl>${basedir}/src/main/resources/some.wsdl</wsdl>
<wsdlLocation>classpath:some.wsdl</wsdlLocation>
<extraargs>
<extraarg>-client</extraarg>
<extraarg>-verbose</extraarg>
</extraargs>
</wsdlOption>
</wsdlOptions>
</configuration>
<goals>
<goal>wsdl2java</goal>
</goals>
</execution>
</executions>
</plugin>
the key part is
<defaultOptions>
<frontEnd>jaxws21</frontEnd>
</defaultOptions>

Java and Scala not working together

I have 2 projects, one maven java and another maven Scala.
The scala one is a library, that I want to use in my java application.
I have the following dependencies in both :
<dependency>
<groupId>org.scala-lang</groupId>
<artifactId>scala-compiler</artifactId>
<version>2.9.0-1</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.scala-lang</groupId>
<artifactId>scala-library</artifactId>
<version>2.9.0-1</version>
</dependency>
and as found on googling, this maven-scala-plugin in both apps
<plugin>
<groupId>org.scala-tools</groupId>
<artifactId>maven-scala-plugin</artifactId>
<version>2.14.3</version>
<configuration>
<charset>UTF-8</charset>
<jvmArgs>
<jvmArg>-Xmx1024m</jvmArg>
</jvmArgs>
</configuration>
<executions>
<execution>
<id>compile</id>
<goals>
<goal>compile</goal>
</goals>
<phase>compile</phase>
</execution>
<execution>
<id>test-compile</id>
<goals>
<goal>testCompile</goal>
</goals>
<phase>test-compile</phase>
</execution>
<execution>
<phase>process-resources</phase>
<goals>
<goal>compile</goal>
</goals>
</execution>
</executions>
</plugin>
The source & target specified in maven for both are java 1.6 and I'm using Netbeans (tried even from command-line but no use)
I build the scala project and then mark a system dependency to it in the maven java project.
Infact, I'm using the goose parser (scala project - https://github.com/jiminoc/goose)
But whenever I run the java project/file, I get ClassNotFoundException for the parser classes.
Tried everything out there for hours now but no success.
Please help.
Also, to mention I've tried building with scala version 2.10.4 but it also has the same issue.
I build the scala project and then mark a system dependency to it in the maven java project.
System dependencies:
Dependencies with the scope system are always available and are not looked up in repository. They are usually used to tell Maven about dependencies which are provided by the JDK or the VM.
Since your Scala project isn't provided by the JDK or the VM, it isn't a system dependency. You would run into exactly the same problem if you had two Java projects. Just remove <scope>system</scope>.

Generate QueryDsl Q Classes From Package

How do I generate QueryDsl Q-Classes by only specifying a package name?
Given the source classes reside in my target/generated-sources folder since they are the product of other build plugins (WSDLs, XSDs, etc.)
I have tried using the following plugins, but can't find the right configuration:
<groupId>com.mysema.querydsl</groupId>
<artifactId>querydsl-maven-plugin</artifactId>
<version>2.9.0</version>
<executions>
<phase>generate-sources</phase>
<goals>
<goal>process</goal>
</goals>
<configuration>
<outputDirectory>target/generated-sources</outputDirectory>
<processor>${com.mysema.query.apt.ProcessorClass}</processor>
</configuration>
</executions>
and:
<groupId>com.mysema.maven</groupId>
<artifactId>maven-apt-plugin</artifactId>
<version>1.0.4</version>
What I'd like to do is something like this:
<configuration>
<packageName>com.my.package</packageName>
<sourceFolder>target/generated-sources</sourceFolder>
<targetFolder>target/generated-sources/querydsl</targetFolder>
</configuration>
...which would generate the classes:
com.my.package.QFoo.java
com.my.package.QBar.java
Since there's no common JPA or JDO annotation, and I don't have have access to the source files, I haven't been able to use any of the com.mysema.query.apt.*Processors for the maven-apt-plugin's <processor>.
EDIT 1: added full maven-apt-plugin configuration.
EDIT 2:
- I was able to get the maven-apt-plugin to work sporadically via the maven command line, but not Eclipse/STS by extending AbstractQuerydslProcessor to look for #XmlType-annotated classes. Double code-generation is admittedly not an ideal solution.
The answer is to generate the Q-classes using the strategy Timo outlined here: https://github.com/mysema/querydsl/issues/196
In my module's package-info.java:
#QueryEntities({ com.remote.module.Foo.class,
com.remote.module.Bar.class })
package com.my.local.module.querydsl;
import com.mysema.query.annotations.QueryEntities;
The plugin execution in the Maven POM:
<plugin>
<groupId>com.mysema.maven</groupId>
<artifactId>apt-maven-plugin</artifactId>
<executions>
<execution>
<id>apt-maven-plugin-remote-module-QuerydslAnnotationProcessor</id>
<goals>
<goal>process</goal>
</goals>
<configuration>
<outputDirectory>target/generated-sources</outputDirectory>
<showWarnings>true</showWarnings>
<!-- genereate Q-classes specified in package-info.java -->
<processor>com.mysema.query.apt.QuerydslAnnotationProcessor</processor>
</configuration>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>com.mysema.querydsl</groupId>
<artifactId>querydsl-apt</artifactId>
</dependency>
</dependencies>
</plugin>

Categories