NoClassDefFoundException while generating jhipster project - maven

I am facing the same problem as many people did in the past. Can't build the spring boot application because i am getting the Exception which is mentioned in the title. Precisely it looks like this:
Error:java: java.lang.NoClassDefFoundError: javax/xml/bind/JAXBException
I know that there was a topic about this before i have posted mine but none of the provided solutions helped me. Simply i am literally out of ideas. All i have wanted is to generate back-end and front-end with jhipster.I didnt even write one single line of code yet.
Let's mention that the project is Java 8 and that i tried to solve this by adding some dependencies as its mentioned in the similar topic which is here How to resolve java.lang.NoClassDefFoundError: javax/xml/bind/JAXBException in Java 9
I have added this in my pom file becasue i use maven but the exception still occurs
<dependency>
<groupId>javax.xml.bind</groupId>
<artifactId>jaxb-api</artifactId>
<version>2.3.0</version>
</dependency>
Then i try to solve by adding this becasue its labeled as proper long term solution for all jdk versions
<dependency>
<groupId>javax.xml.bind</groupId>
<artifactId>jaxb-api</artifactId>
<version>2.2.11</version>
</dependency>
<dependency>
<groupId>com.sun.xml.bind</groupId>
<artifactId>jaxb-core</artifactId>
<version>2.2.11</version>
</dependency>
<dependency>
<groupId>com.sun.xml.bind</groupId>
<artifactId>jaxb-impl</artifactId>
<version>2.2.11</version>
</dependency>
<dependency>
<groupId>javax.activation</groupId>
<artifactId>activation</artifactId>
<version>1.1.1</version>
</dependency>
Any help or advice would be appreciated. Thanks in advance

Probably there is some problem either in your project configuration or in IntelliJ's Java Compiler settings.
Make sure that Java Compiler is set to 'Same as language level' or set it manually to desired version.
Make sure that all of the following project settings are set to Java 8:
Make sure modules are set to correct version as well:

Related

Find all dependencies that include a given package

I excluded an artifact because it causes conflicts, namely the jsr311-api given below. Yet when I run the generated jar I'm still getting the java.lang.NoSuchMethodError error. I suspect that another dependency is also including this artifact. How can I find out which one? My dependency list is quite large. Which dependencies include the package javax.ws.rs.core?
<dependency>
<groupId>org.apache.axis2</groupId>
<artifactId>axis2-kernel</artifactId>
<version>1.7.3</version>
<exclusions>
<!-- Causes java.lang.NoSuchMethodError: javax.ws.rs.core.Response$Status$Family.familyOf(I)Ljavax/ws/rs/core/Response$Status$Family; -->
<exclusion>
<artifactId>jsr311-api</artifactId>
<groupId>javax.ws.rs</groupId>
</exclusion>
</exclusions>
</dependency>
Go to
http://search.maven.org/#advancedsearch%7Cgav
and use classname search to find
javax.ws.rs.core.Response
If you use a Nexus 2.x in your company, you can use classname search there as well.
If you want to find out where a given artifact (that you e.g. found by classnmae search) comes from, use dependency:tree in Maven.
In my case the mistake was that I had to manually add the javaee api and I set <scope>provided</scope> which was a mistake, fixing this solved the problem.
<dependency>
<groupId>javax</groupId>
<artifactId>javaee-api</artifactId>
<version>7.0</version>
<scope>provided</scope><!-- remove this -->
</dependency>

Maven Guava Dependency "Cannot resolve symbol 'google'" in IntelliJ IDEA

IntelliJ says Cannot resolve symbol 'google'. about this import:
import com.google.common.cache.LoadingCache;
Even though I have added the dependency correctly and it doesn't complain about it:
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>19.0</version>
</dependency>
I have updated my Maven repository. I have Maven auto-import enabled in IntelliJ IDEA. My project is using SDK version 1.8. Based on numerous examples on the web, this should work, but it doesn't.
I found this about a similar (although not the same issue, as my code doesn't compile). I tried invalidating the cache and restarting, but it didn't help. The top answer also suggests deleting the IDEA system directory. I don't know if this is a good idea and how much stuff breaks if I do that.
I had the same problem and was trying all solutions to import Guava cache manager.
But the mistake I made was, did not add dependencies properly. Please do check pom.xml before trying any solution.
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>25.0-jre</version>
</dependency>
<!-- these are the dependencies i missed -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-beans</artifactId>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context-support</artifactId>
<version>4.3.10.RELEASE</version>
</dependency>`
If anyone else has a similar issue, reading through pom.xml may be helpful. Turns out I had <properties> defined twice. For some reason it was not causing problems before adding the Guava dependency. After removing the duplicate definition, everything started working again.

ValidationException with Spring boot and Jetty

I set up a spring boot application(1.4.0.RELEASE) with the following configuration
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
As expected, this ran with embedded Tomcat. I then thought of trying the same with a Jetty server and followed the steps mentioned in the documentation here:
Using Jetty instead of Tomcat
Basically excluding Tomcat and adding dependency for Jetty.Running mvn clean install from the command line or running the main method resulted in the following exception:
Caused by: javax.validation.ValidationException: HV000183: Unable to
load 'javax.el.ExpressionFactory'. Check that you have the EL
dependencies on the classpath, or use ParameterMessageInterpolator
instead
I could solve this by adding the following dependency in the pom.xml:
<dependency>
<groupId>javax.el</groupId>
<artifactId>javax.el-api</artifactId>
<version>3.0.0</version>
</dependency>
I am not directly using any validation related code but I suspect this is getting pulled from the spring boot jpa starter which pulls in Hibernate. I have also seen a discussion around this here: Similar issue
Questions:
1) Is this the right fix?
2) If it is the right fix, should the documentation be updated to add this dependency as well?
You are correct in using the javax.el dependency. When the JPA pulls in Hibernate as you stated, it will use the Hibernate Validator. It's specified here. This is the right fix. As for the documentation, I personally would raise it but I suspect not everyone will have the same issue. I still can run my mvn clean install without errors however if I run mvn spring-boot:run it starts up and shuts-down straight after.

Spring Boot WAR jolokia integration

According to the Spring Boot 1.2.3 Reference Docs.
Enabling jolokia seems to be as simple as adding as adding the following Maven dependency:
<dependency>
<groupId>org.jolokia</groupId>
<artifactId>jolokia-core</artifactId>
</dependency>
While this does work for a Spring Boot application packaged as a fat jar, I am unable to get this to work when packaged as a WAR file.
The root cause appears to be:
Caused by: java.lang.ClassNotFoundException: org.json.simple.JSONAware
I'm using STS for development purposes and deploying to an embedded pivotal tc Server 3.1. The dependency(json-simple-1.1.1.jar) containing the org.json.simple.JSONAware does appear under the Maven Dependency node so I'm not sure what the issue is.
So as I was composing the question I stumbled onto a solution that at least seems to work for me:
I took a look at the effective POM and found this dependency declaration:
<dependency>
<groupId>com.googlecode.json-simple</groupId>
<artifactId>json-simple</artifactId>
<version>1.1.1</version>
<optional>true</optional>
</dependency>
So for lack of better option I declared the following dependency explicitly
<dependency>
<groupId>com.googlecode.json-simple</groupId>
<artifactId>json-simple</artifactId>
<optional>false</optional>
</dependency>
Adding false to the the <optional> element seemed necessary.
Now I can access jolokia via the following url:
http://<myurl>:<myport>/<appcontext>/jolokia
Looking at 1.4.4 this seems to have been fixed:
<dependency>
<!-- Make json-simple non-optional.
It is marked optional in boot-dependencies, but required by jolokia-core.
Without this fix it would be missing when used war-packaging. -->
<groupId>com.googlecode.json-simple</groupId>
<artifactId>json-simple</artifactId>
<optional>false</optional>
</dependency>
Yet I'm seeing similar issues running a war in JBoss.

java.lang.NoSuchMethodError: org.springframework.data.jpa.repository.config.JpaRepositoryConfigExtension.registerIfNotAlreadyRegistered

I am using CRUDRepository to perform crud operations using JPA , but I am getting this error:
java.lang.NoSuchMethodError:
org.springframework.data.jpa.repository.config.JpaRepositoryConfigExtension.registerIfNotAlreadyRegistered
Please help.
It comes from this commit:
https://github.com/spring-projects/spring-data-commons/commit/6677612f8eac7a7ab67206a5709b6e94cc51028b
So you'll need at least spring-data-commons 1.10.0.RELEASE:
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-commons</artifactId>
<version>1.10.0.RELEASE</version>
</dependency>
But: if this is happening is probably because you've a conflict between versions, so it's better if you find out why you are loading an older spring-data-commons
I was able to solve this error , earlier i was using spring-data-jpa.1.7.2.RELEASE.jar , now i switched on to spring-data-jpa.1.6.0.RELEASE.jar and it solved the problem
thanks for help.
Often this happens when you have 2 dependencies in your maven pom.xml file with the same "groupId" but different versions.
<!-- https://mvnrepository.com/artifact/org.springframework.data/spring-data-commons-core -->
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-commons-core</artifactId>
<version>1.4.1.RELEASE</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.springframework.data/spring-data-jpa -->
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-jpa</artifactId>
<version>1.11.1.RELEASE</version>
</dependency>
Common "groupId"'s should have the same version number.

Resources