Hibernate MultiMap cannot be found while code generation - java

While i'm trying generate some classes by Hibernate using existing db relation it generates some error:
org.hibernate.console.HibernateConsoleRuntimeException: Received a NoClassDefFoundError, probably the console configuration classpath is incomplete or contains conflicting versions of the same class
Received a NoClassDefFoundError, probably the console configuration classpath is incomplete or contains conflicting versions of the same class
org.hibernate.console.HibernateConsoleRuntimeException: Received a NoClassDefFoundError, probably the console configuration classpath is incomplete or contains conflicting versions of the same class
Received a NoClassDefFoundError, probably the console configuration classpath is incomplete or contains conflicting versions of the same class
java.lang.NoClassDefFoundError: org/apache/commons/collections/MultiMap
org/apache/commons/collections/MultiMap
java.lang.ClassNotFoundException: org.apache.commons.collections.MultiMap cannot be found by org.jboss.tools.hibernate.runtime.v_5_1_5.0.1.Final-v20160331-1852-B88
org.apache.commons.collections.MultiMap cannot be found byorg.jboss.tools.hibernate.runtime.v_5_1_5.0.1.Final-v20160331-1852-B88
My maven file:
<build>
<sourceDirectory>src</sourceDirectory>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.3</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>org.firebirdsql.jdbc</groupId>
<artifactId>jaybird-jdk18</artifactId>
<version>2.2.10</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
<version>5.1.0.Final</version>
</dependency>
<dependency>
<groupId>commons-collections</groupId>
<artifactId>commons-collections</artifactId>
<version>3.2.2</version>
</dependency>
I see apache common-collections jar in Maven Dependencies and i am able to use apache's MultiMap in my code.

I had the same issue. Here is how I fixed it:
Open Edit Configuration dialog and go to Classpath tab, remove project-name (default classpath), click the button "Add Projects..." to add your project.
Then it works.
Or you can try using previous version instead of v5.1. In hibernate perspective, "your configuration" / Edit configuration, Change hibernate version to previous version like v4.3.

Just to chime in: Eclipse Mars. Hibernate 5.1.0. JDK 8. As Gordon and Kevin mentioned above, changing the version of Hibernate to 4.3 in in Edit Configuration worked for me.

I changed the hibernate version of 5.1 to 4.3 in Console Configuration file.
Set hibernate perspective
Open Hibernate configuration tab
Click right on your configuration
Select Edit configuration
Change Hibernate Version of 5.1 to 4.3

Fix for me: Mars worked with Hibernate Tools plugin v. 5.1.4. I just needed to click "update" after "search for updates"

Related

Can't resolve the error: java.lang.NoClassDefFoundError: org/json/simple/parser/ParseException

Trying to use Maven to organize my project and I keep running into the following error. I know that this error means the file is present at compile time but for some reason it can't be found at runtime.
Error: A JNI error has occurred, please check your installation and try again
Exception in thread "main" java.lang.NoClassDefFoundError: org/json/simple/parser/ParseException
So I'm working on a project in Java that will take a user query, search Google Images and then download some of the results onto my computer. To that end I've had to use some third party libraries like JSoup, Json-Simple, and Gson.
I initially added Jsoup to my classpath manually and it worked, but then I heard about Maven and started using it instead. My issue is that when I try to run my code I get the error above.
I'm just not sure how to resolve this. I've seen a bunch of other posts about similar errors and I've tried to modify my pom.xml accordingly but
I just can't get it to work. I've tried removing the ~/.m2 file, ran mvn clean, mvn install, mvn package, mvn compile, and it all works fine. But when it comes time to run, I keep getting that error.
Here's most of my pom.xml file.
<repositories>
<repository>
<id>central</id>
<name>Maven repository</name>
<url>http://repo1.maven.org/maven2</url>
</repository>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
<dependency>
<!-- jsoup HTML parser library # https://jsoup.org/ -->
<groupId>org.jsoup</groupId>
<artifactId>jsoup</artifactId>
<version>1.11.3</version>
<scope>provided</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/com.googlecode.json-simple/json-simple -->
<dependency>
<groupId>com.googlecode.json-simple</groupId>
<artifactId>json-simple</artifactId>
<version>1.1.1</version>
</dependency>
<!-- https://mvnrepository.com/artifact/com.google.code.gson/gson -->
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.8.5</version>
</dependency>
<build>
<plugins>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<archive>
<manifest>
<mainClass>fully.qualified.MainClass</mainClass>
</manifest>
</archive>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
</plugin>
</plugins>
</build>
FOUND SOLUTION: So I left out some parts of the pom.xml file to make it easier to read, and because all the other parts were generated by Maven itself so I figured there couldn't be an issue with anything there. But it adds a tag called "pluginManagement" that encloses all other plugins and apparently this does not allow the Shade plugin to run.
Between ngueno's guidance and this post Maven shade plugin is not called automatically for goal "package"
I was able to figure out my issue, though I'm still not entirely sure why it is an issue. Anyways, I figured I'd update this post in case someone else with a similar problem stumbles across it. This was on Mac OS btw, in case it makes a difference. Thanks for your help everyone.
Usually NoClassDefFound errors are related to missing libraries at runtime.
Since you are running using the terminal I supose you are building your project using Maven, and running the generated JAR,
I would recommend to you to use the maven-shade-plugin and generate an uber-jar as I explained on this question.
The purpose generating a uber-jar is to carry all the needed dependencies inside of it (available on the application classpath).
Implement the plugin and try to run using the new JAR.
PS: Remember to check this section related to Executable Jars
UPDATE: Remove the <scope>provided</scope> of your jsoup dependency, to enforce Maven to package it along your app, with the provided scope you are saying that this dependency will be provided by the JDK at runtime.
The jars that you identify in your dependencies must be present in the Runtime classpath.
This is not the classpath that is available when you compile the code;
it is the classpath on the host where you run the application.
You must install these jars on the target host.
Edit: More details
You must do the following:
Identify the runtime host.
Create a directory on the runtime host into which you will install the dependent jar files.
Include every jar in the classpath.
Consider abandoning the "roll-your-own" path.
If you use Spring Boot
(I like it,
I don't work for them).
One feature of spring boot is a reinvented "Fat Jar" that will include the dependencies inside one deliverable artifact (the fat jar) and will add them to the classpath at startup.
Edit:
The Spring boot executable jar file is not a "Fat Jar",
instead it includes the dependencies in a directory in the
executable jar and adds said jars to the classpath on startup.

Re-run Spring Boot Configuration Annotation Processor to update generated metadata

I've added:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-configuration-processor</artifactId>
<optional>true</optional>
</dependency>
to my pom.xml per intellij's request/warning.
Now I'm seeing "Re-run Spring Boot Configuration Annotation Processor to update generated metadata".
How do I do what intellij is asking me to do?
This link, B.2 Generating your own meta-data using the annotation processor, does not have instructions.
Following these instructions worked for me: http://www.mdoninger.de/2015/05/16/completion-for-custom-properties-in-spring-boot.html
That message about having to Re-run the Annotation Processor is a bit confusing as it appears it stays there all the time even if nothing has changed.
The key seems to be rebuilding the project after adding the required dependency, or after making any property changes. After doing that and going back to the YAML file, all my properties were now linked to the configuration classes.
You may need to click the 'Reimport All Maven Projects' button in the Maven pane as well to get the .yaml file view to recognise the links back to the corresponding Java class.
None of these options worked for me. I've found that the auto detection of annotation processors to be pretty flaky. I ended up creating a plugin section in the pom.xml file that explicitly sets the annotation processors that are used for the project. The advantage of this is that you don't need to rely on any IDE settings.
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.7.0</version>
<configuration>
<compilerVersion>1.8</compilerVersion>
<source>1.8</source>
<target>1.8</target>
<annotationProcessors>
<annotationProcessor>org.springframework.boot.configurationprocessor.ConfigurationMetadataAnnotationProcessor</annotationProcessor>
<annotationProcessor>lombok.launch.AnnotationProcessorHider$AnnotationProcessor</annotationProcessor>
<annotationProcessor>org.hibernate.jpamodelgen.JPAMetaModelEntityProcessor</annotationProcessor>
</annotationProcessors>
</configuration>
</plugin>
You can enable annotation processors in IntelliJ via the following:
Click on File
Click on Settings
In the little search box in the upper-left hand corner, search for "Annotation Processors"
Check "Enable annotation processing"
Click OK
None of the answers worked for me. If you just want to disable the message, go to Intellij Preferences -> Editor -> General -> Appearance, uncheck "Show Spring Boot metadata panel".
However, you can also live with that message, if it does not bother you too much, so to make sure you don't miss any other Spring Boot metadata messages you may be interested in.
I had the same issue. The problem is that the Spring Boot annotation processor generates the spring-configuration-metadata.json file inside your /target/classes/META-INF folder.
If you happen to have ignored this folder in IntelliJ like me (because what the heck, who cares about classes files?), the file won't be indexed by your IDE. Therefore, no completion, and the annoying message.
Just remove target from the ignore files/folders list, located in Settings > Editor > File Types > Ignore files and folders.
For me, other answers didn't work. I had to go to open Files and do Invalidate caches and restart on Intellij. After that, everything worked fine again.
Include a dependency on spring-boot-configuration-processor
Click "Reimport All Maven Projects" in the Maven pane of IDEA
Rebuild project
Having included a dependency on spring-boot-configuration-processor in build.gradle:
annotationProcessor "org.springframework.boot:spring-boot-configuration-processor:2.4.1"
the only thing that worked for me, besides invalidating caches of IntelliJ and restarting, is
Refresh button in side panel Reload All Gradle Projects
Gradle task Clean
Gradle task Build
I just needed
#EnableConfigurationProperties({MY_PROPS_CLASS.class})
in Main Application class and it helped me to resolve this issue
I had a similar issue using Gradle and Kotlin.
You should modify the build.gradle.kts file to include the following:
//build.gradle.kts
plugins {
// ...
kotlin("kapt") version "1.5.31"
}
dependencies {
// ...
kapt("org.springframework.boot:spring-boot-configuration-processor")
}
Then, to generate the annotations:
./gradlew kaptKotlin
References: https://spring.io/guides/tutorials/spring-boot-kotlin/#_configuration_properties
I had the same problem. In my case I was missing the spring-boot-maven-plugin.
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
as well as the #Data Lombok annotation
#Configuration
#ConfigurationProperties("logging.web")
#Data
public class LoggingWebConfiguration {
// ...
}
Obviously you can also just create the getter/setters yourself.
Then you must also remember to re-import and re-compile your project.
None of the above worked in my case, but brought me close. In the end explicitly defining all required annotationProcessors in the maven-compiler-plugin solved it for me. In my case this was: Spring-Boot + Lombok + MapStruct
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<annotationProcessorPaths>
<annotationProcessorPath>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-configuration-processor</artifactId>
<version>${spring-boot-configuration-processor.version}</version>
</annotationProcessorPath>
<annotationProcessorPath>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>${lombok.version}</version>
</annotationProcessorPath>
<annotationProcessorPath>
<groupId>org.mapstruct</groupId>
<artifactId>mapstruct-processor</artifactId>
<version>${mapstruct.version}</version>
</annotationProcessorPath>
</annotationProcessorPaths>
</configuration>
</plugin>
Before that I always got some warnings in the Class + in the application.properties some properties were marked as "unusued", even when they were defined in a class with #ConfigurationProperties
In the maven panel of Idea, clean and compile in the maven lifecycle worked for me.

multiple issues with spring tool suite 3.6.3 release

I have wanted to learn Spring MVC and I took look at javavids - YouTube, I wanted to follow along with this series but I have multiple problems/issues
First I rebuild the Global repo in Maven Repositories
Solved
then I created Maven project but structure in videos was
but I have this instead
Solved
OK now I want to add plugins to pom.xml but getting this dialog
in videos it shows :
UPDATE
I don't get any plug-in to select from
Solved
I also have compiler compliance
when I set compiler to java 1.7 then I get
Solved
and at last when I tried to update STS 3.6.3 It freezes and shows
OK
I have proxy settings as
Update
I make changes and add dependency according to this Answer
I get this error:
Now I don't see resources which can help me to get these remaining issues resolved!
any help is highly appreciated.
First maven default compiler level is set to 1.5.
In order to set it to 1.7 either configure maven-compiler-plugin
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.3</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
or add the following properties.
<properties>
<maven.compiler.source>1.7</maven.compiler.source>
<maven.compiler.target>1.7</maven.compiler.target>
</properties>
After setting java version press Alt+F5 to update maven project.
In order to search for dependency or plugins go to Window -> Preferences -> Maven and check Download repository index update on startup
Restart STS, wait for index updates to complete.
Regarding your project structure check do have <packaging>war</packaging> in your pom.xml. By default it will be jar type.
then I created Maven project but structure in videos was
You be able to switch the perspective in the ide (eclipse). In the video that is the Java EE-Perspective.
That what you got is the Spring-Perspective, don't worry about that.
Window -> Open Perspective
OK now I want to add plugins to pom.xml but getting this dialog
Ok, what is wrong with that?
If you searching for a dependency on MVN Repository there you got all informationen to fill out the informations you see in the dialog. Otherwise you can open the pom-file and paste the dependency directly.
I also have compiler compliance
Assuming that you are using the m2e plugin in Eclipse, you'll need to specify the source and target versions as 1.7 for maven-compiler-plugin.
specify it with this:
<properties>
<maven.compiler.target>1.7</maven.compiler.target>
<maven.compiler.source>1.7</maven.compiler.source>
</properties>
And update your project Right click on project -> maven -> update project (Alt F5)
The network seems to be ok. Are you on a privat or office network?
I would also like to recommend to get started with Spring using the Spring Tool Suite by using Spring Boot and the guides at http://spring.io/guides. You can import those guides directly into STS and start from there (assuming you have network connectivity).
I think the solution I am providing here will dam sure will work for you.
If you have downloaded Spring STS successfully then you have to follow these steps only.
After creation of project right click on project and Update Maven Project
For Integrating it with Google App Engine it is very Simple. You have to just declare the google app engine dependency in you pom.xml. I am providing you the structure of my Google App engine Spring project.
Please follow these steps
1. create appengine-wex.xml under WEB-INF Folder
2. Create logging.properties file under WEB-INF Folder
3. Insert Google App engine dependecies
Here is sample appengine-web.xml
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE xml>
<appengine-web-app xmlns="http://appengine.google.com/ns/1.0">
<application>make-me</application>
<version>2</version>
<!--
Allows App Engine to send multiple requests to one instance in parallel:
-->
<threadsafe>true</threadsafe>
<!-- Configure java.util.logging -->
<system-properties>
<property name="java.util.logging.config.file" value="WEB-INF/logging.properties"/>
</system-properties>
<!--
HTTP Sessions are disabled by default. To enable HTTP sessions specify:
<sessions-enabled>true</sessions-enabled>
It's possible to reduce request latency by configuring your application to
asynchronously write HTTP session data to the datastore:
<async-session-persistence enabled="true" />
With this feature enabled, there is a very small chance your app will see
stale session data. For details, see
http://code.google.com/appengine/docs/java/config/appconfig.html#Enabling_Sessions
-->
</appengine-web-app>
Pom dependency
<dependency>
<groupId>com.google.appengine</groupId>
<artifactId>appengine-api-1.0-sdk</artifactId>
<version>1.9.1</version>
</dependency>
<!-- JUnit -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.10</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-all</artifactId>
<version>1.9.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.google.appengine</groupId>
<artifactId>appengine-testing</artifactId>
<version>1.9.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.google.appengine</groupId>
<artifactId>appengine-api-stubs</artifactId>
<version>1.9.1</version>
<scope>test</scope>
</dependency>
Final Structure

Native Library already loaded in another Maven plugin's classloader

I would like to run two third-party Maven plugins using the Xerial JDBC driver for SQLite. The plugin configuration roughly looks like this:
<plugins>
<!-- reset database with the SQL Maven plugin -->
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>sql-maven-plugin</artifactId>
<executions>...</executions>
<dependencies>
<dependency>
<groupId>org.xerial</groupId>
<artifactId>sqlite-jdbc</artifactId>
[...]
<!-- generate source code with the jOOQ Maven plugin -->
<plugin>
<groupId>org.jooq</groupId>
<artifactId>jooq-codegen-maven</artifactId>
<executions>...</executions>
<dependencies>
<dependency>
<groupId>org.xerial</groupId>
<artifactId>sqlite-jdbc</artifactId>
[...]
Now this SQLite JDBC driver loads a native library, internally, which causes the following error to appear in the second plugin's execution:
java.lang.UnsatisfiedLinkError: Native Library
C:\Users\Lukas\AppData\Local\Temp\sqlite-3.7.151-amd64-sqlitejdbc.dll
already loaded in another classloader
The workaround is to comment out one of the plugins.
Is there a proper way to circumvent this problem without making any assumptions about the system on which this runs? I'd like to create self-contained tests with the above, which should run on any system, i.e. putting stuff into system library paths is not a solution here. Can this be solved with Maven? Or do any of the above plugins or (more likely) the JDBC driver need to be fixed?

Eclipse + Maven + JavaServer Faces -> ClassNotFoundException: StartupServletContextListener

Summary
When I try to run a JSF 2.0 application from within Eclipse (on Tomcat 7.0) I get the following exception:
Problem: SEVERE: Error configuring application listener of class org.apache.myfaces.webapp.StartupServletContextListener
java.lang.ClassNotFoundException: org.apache.myfaces.webapp.StartupServletContextListener
Details
I'm learning to develop JSF applications, using Eclipse.
I started with a preconfigured Eclipse project: File->New->Dynamic Web Project->JavaServer Face v2.0 Project.
Using this method Eclipse provides all dependencies. But I want to really learn how everything works. I want to remove the "magic", so I converted my project to a Maven project: Configure->Convert to Maven project.
I then created my pom.xml (based on http://myfaces.apache.org/build-tools/archetypes/myfaces-archetype-helloworld20/index.html), it contains the following:
<build>
<finalName>jsf-facelets-tutorial</finalName>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<configuration>
<webXml>WebContent/WEB-INF/web.xml</webXml>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>javax.el</groupId>
<artifactId>el-api</artifactId>
<version>1.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.myfaces.core</groupId>
<artifactId>myfaces-api</artifactId>
<version>2.0.5</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.apache.myfaces.core</groupId>
<artifactId>myfaces-impl</artifactId>
<version>2.0.5</version>
<scope>runtime</scope>
</dependency>
</dependencies>
But because I'm unfamiliar with JSF, and because this is an Eclipse "Dynamic Web Project", the project structure is new to me and I'm having trouble understanding which dependencies are coming from Maven and which are provided by the Eclipse "magic".
In Eclipse, my project structure is as follows:
ProjectName
JAX-WS Web Services <-- CAN I REMOVE THIS???
Deployment Descriptor
Java Resources
src/main
Libraries
Apache Tomcat v7.0
el-api.jar
jsp-api.jar
[more...]
JSF 2.0 (Apache MyFaces JSF Core-2.0 API 2.0.2) <-- I REMOVED THIS!!!
EAR Libraries
JRE System Library
Maven Dependencies
el-api-1.0.jar
myfaces-api-2.0.5.jar
myfaces-impl-2.0.5.jar
[more...]
Web App Libraries
Problem
My (very basic) application (login page & welcome page) no longer runs.
When I do the following:
(1) Right click on WebContent/login.xhtml
(2) Run as -> Run on Server
(3) Apache Tomcat v7.0 - JDK6 at localhost
I get the exception:
Problem: SEVERE: Error configuring application listener of class org.apache.myfaces.webapp.StartupServletContextListener
java.lang.ClassNotFoundException: org.apache.myfaces.webapp.StartupServletContextListener
I have the feeling that this is very easy to fix, but I'm too unfamiliar with these frameworks to work it out.
If there are any additional details I should provide (web.xml, faces-config-xml, login.xhtml), let me know and I'll add them.
Thanks!
EDIT
WEB-INF/lib is always empty. From my understanding, it's necessary to copy all dependencies into this folder, that will be required at runtime, and that are not provided by the Web Container. The reasons mine is empty are: (1) I don't know what I need in there (2) I don't know how to automate the process of putting .jar files in there
Under your eclipse Project Properties, select Deployment Assembly from the navigation menu which defines "packaging structure for this Java EE Web Application project." Make sure you have all the project dependencies added here..
Or look into web server directory under workspace/.metadata/.plugins/org.eclipse.wst.server.core\tmp0 to check if the jars have been copied to catalina base.
Sounds like you don't have all the jars in your target folder ready to deploy to tomcat
Try running a maven package in eclipse, right click on project, run as maven package

Categories