I'm trying to generate Metamodel classes with Hibernate in IntelliJ idea.
I already saw oldest tutorials, but they didn't help me.
There are any other way to generate that files? The topics that I found about Metamodel support in IntelliJ are too old.
Maybe I'm doing something wrong. I'll explain what I'm doing.
I've already tried:
Enable the processing in IntelliJ settings: Settings > Build, Execution, Deployment > Compiler > Annotation Processors > [check] Enable annotation processing.
Put the maven-processor in pom.xml. (jpa.modelgen.CanonicalModelProcessor)
Rebuilt the project.
Plugin that I included in pom.xml:
<plugin>
<groupId>org.bsc.maven</groupId>
<artifactId>maven-processor-plugin</artifactId>
<version>1.3.5</version>
<executions>
<execution>
<id>process</id>
<goals>
<goal>process</goal>
</goals>
<phase>generate-sources</phase>
<configuration>
<outputDirectory>${project.build.directory}/generated-sources/metamodel</outputDirectory>
<compilerArguments>
-Aeclipselink.persistencexml=${project.basedir}/src/main/resources/META-INF/persistence.xml
</compilerArguments>
<processors>
<processor>org.eclipse.persistence.internal.jpa.modelgen.CanonicalModelProcessor
</processor>
</processors>
</configuration>
</execution>
</executions>
</plugin>
Put following dependency in pom.xml of project.
<!-- https://mvnrepository.com/artifact/org.hibernate/hibernate-jpamodelgen -->
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-jpamodelgen</artifactId>
<version>5.3.7.Final</version>
<scope>provided</scope>
</dependency>
Then use ..path_to_root_directory_of_module_of_entities/target/classes/ directory on the build path of module/project.
It will make available all auto generated static model classes to the runtime of project.
Related
I have a spring boot project that has a few local jar files dependencies like
mssql-jdbc-6.2.1.jre8.jar
internal-commons.jar
internal-db.jar
etc.
How do I package the project into a WAR file? Thanks in advance!
You can use existing libraries to achieve this.
If you use maven, you can use the maven-dependency-plugin
For example, in your pom.xml file, add the following to your dependencies:
<dependency>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>3.2.0</version>
</dependency>
And then, use it as a plugin in your pom.xml:
<plugin>
<!-- http://jonathangraham.github.io/2016/01/05/Local_Jar_Dependency_With_Maven -->
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<phase>compile</phase>
<goals>
<goal>copy-dependencies</goal>
</goals>
<configuration>
<outputDirectory>${project.build.directory}/lib</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>
The entire process is explained here in more detail.
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>
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>.
I'm trying to generate schema files from java classes with maven using the jaxb2-maven-plugin under java 6. Generally it works fine.
But additionally I'am using the jaxb-facets fork in order to support the full schema features. Generally jaxb-facets need to override the standard jaxb implementation in order to work. But this seems to be the problem. When using the jaxb2-maven-plugin, the plugin always downloads the original jaxb implementation. I tried using the endorsed strategy, but there seems to be no difference.
I'am banging my head for hours :-(((
This is the relevant part of my pom file:
<!-- The jaxb-facets depedencies: Note that jaxb-facets should be at the top of all dependencies (at least before any dependencies to JAXB libraries) -->
<dependency>
<groupId>javax.xml.bind</groupId>
<artifactId>jaxb-api</artifactId>
<version>2.2.7-facets-1.0.3</version>
</dependency>
<dependency>
<groupId>com.sun.xml.bind</groupId>
<artifactId>jaxb-xjc</artifactId>
<version>2.2.6</version>
</dependency> ...
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>jaxb2-maven-plugin</artifactId>
<version>1.5</version>
<configuration>
<argline>-Djava.endorsed.dirs="${project.build.directory}/endorsed"</argline>
</configuration>
<executions>
<execution>
<goals>
<goal>schemagen</goal>
</goals>
<phase>generate-resources</phase>
<configuration>
<includes>
<include>de/dvka/avaro/model/schema/*.java</include>
</includes>
<outputDirectory>src/main/java/de/dvka/avaro/model/schema</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>
I skipped the endorsed part here, because it is to long
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>