Java Class cast Exception - Spring boot - java

Exception in thread "main" java.lang.ClassCastException: java.base/jdk.internal.loader.ClassLoaders$AppClassLoader cannot be cast to java.base/java.net.URLClassLoader
at org.springframework.boot.devtools.restart.DefaultRestartInitializer.getUrls(DefaultRestartInitializer.java:93)
at org.springframework.boot.devtools.restart.DefaultRestartInitializer.getInitialUrls(DefaultRestartInitializer.java:56)
at org.springframework.boot.devtools.restart.Restarter.<init(Restarter.java:138)
at org.springframework.boot.devtools.restart.Restarter.initialize(Restarter.java:537)
at org.springframework.boot.devtools.restart.RestartApplicationListener.onApplicationStartedEvent(RestartApplicationListener.java:68)
at org.springframework.boot.devtools.restart.RestartApplicationListener.onApplicationEvent(RestartApplicationListener.java:45)
at org.springframework.context.event.SimpleApplicationEventMulticaster.invokeListener(SimpleApplicationEventMulticaster.java:166)
at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:138)
at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:121)
at org.springframework.boot.context.event.EventPublishingRunListener.started(EventPublishingRunListener.java:63)
at org.springframework.boot.SpringApplicationRunListeners.started(SpringApplicationRunListeners.java:48)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:304)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1186)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1175)
at com.rme.hub.RmeApplication.main(RmeApplication.java:24)

Judging by the presence of java.base/jdk.internal.loader.ClassLoaders in the stack trace, you are using Java 9 or later. Spring Boot's DefaultRestartInitializer is trying to cast the app class loader to a URLClassLoader. This works in Java 8 and earlier but does not work with Java 9 or later. Spring Boot had been updated in 2.0 to cope with this change in Java 9.
If you want to use Spring Boot with Java 9 or later, you should upgrade to Spring Boot 2. At the time of writing, the latest release is 2.0.5 which supports Java 8, 9, and 10. Spring Boot 2.1, which will be released later this year, will add support for Java 11.

I had this problema on eclipse and had solved by doing these step:
First download java 8 (If you don't have) then install it
Second, I am not sure if you have to do it or not but just do it. I create JAVA_HOME path by right click to my desktop -> properties -> Advanced System Setting -> Advanced Tab -> Environment Variables -> Add JAVA_HOME in both User Variables and System Variables -> Click new -> Variable Home is "JAVA_HOME", Variable Value can be left empty -> Browse Directory -> point to your jdk folder (Exmaple: mine is C:\Program Files\Java\jdk1.8.0_291)
Third, go to eclipse -> go to window tab -> choose java on the menu on the left side -> Installed JREs -> in default eclipse already had jre directory -> click to it and then click duplicate -> change the directory to your own jre directory (example: C:\Program Files\Java\jre1.8.0_291)
Forth: back to java menu, choose compiler option -> then on the right side -> change compiler compliance level to 1.8.
That is all!
Hope it will be useful for you.

solution: change JDK version 8 in your IDE
I got the same issue in the spring boot application in IntelliJ idea and sts but I found one solution in that issue :
if you are using AD integration in your project with it belongs to Microsoft, then you need to use java 8 version JDK because currently Microsoft AD plugins are not supported to java 9 or higher version it will support only the java 8 or lower version

Check your JAVA_HOME in hadoop-env.sh. Changing my JAVA_HOME value in $HADOOP_HOME/etc/hadoop with java 8 (export JAVA_HOME=/usr/lib/jvm/java-8-openjdk-amd64) value in the hadoop-env.sh solved this issue for me.
I had a higher java version defined in my hadoop-env.sh value when I had defined java 8 in my .bashrc file. So keeping both the same java 8 version fixed the issue for me.

Related

Java Spring Boot : KeyCloak Server : java.lang.NoClassDefFoundError: java/security/acl/Group

2 weeks ago my Spring Boot code was ok. But last week I upgrade my Linux version. Now using Linux 20.04.
Now Always java.lang.NoClassDefFoundError: java/security/acl/Group.
Spring boot: 2.3.4.RELEASE
Keycloak : 11.0.3
JDK : OPENJDK 8,11,14.
I use JDK 11 but not working.
I use JDK 8 but not working.
I use JDK 14 but not working.
I use windows os and JDK 11 but not working.
I change the project build path JRE to 8/11/14 but not working.
I also try keycloak version 11.0.2 and 11.0.3. But not working.
I search here and there. Read many articles but didn't find any solution.
I download the previous version of the Spring Tool Suite and use it.
Now the problem is gone.
But still don't know why this problem I face.
if you use Spring Tool Suite 4.9, change the installed JREs to your local JRE 8 or 11.
Window -> Preferences -> Java -> Installed JREs

Differenet java version than the one i set in environment variable

I'm new to all the Java stuff so sorry in advance if i ever mislead.
I have Eclipse Java EE IDE for Web Developers. Version: Juno Service Release 2 and i installed JBoss Hibernate tools extension. And while i was trying to add a configuration as in http://furqanlabs.blogspot.com/2013/01/hibernate-and-oracle-configuration.html this tutorial, i got such an error:
"Project DmisService has higher compiler option than running Eclipse. Hibernate plugins unable to load its classes. Please decrease the compiler option or run the Eclipse with higher JDK level."
So to know which JDK level my eclipse is using i did the followings:
i typed java -version on the comman line and i came up with the following result:
java version "1.8.0_11"
and when i checked my environment variable for JAVA_HOME it is C:\Program Files\Java\jdk1.6.0_30. and the Java Compiler setting is also 1.6 (as jre of the project as i understood) for my project.
So i came up with another questions -> Why command line gives me different java version than environment variable?
and my original question:
what exactly (i am also new the java terms) should i do to fix this problem?
Thank you very much for any suggestion.
edit: i also checked with eclipse: System.out.println(System.getProperty("java.version")); and it gives me 1.6.0_30
Adding Eclipse Java 8 Support helped me to resolve the issue!
Ref : Eclipse + Java 8 support?

Cannot set Java 8 on Windows 7

I just downloaded and installed Java 8 on Windows 8 (64 bit). I have updated the classpath, java home environment variables to point to the new version. But when I try to use the lambda expression on a code from Intellij (13.0.2) , it says Lambda not supported at this language level.
Also when I run this from command prompt: java -version
it says the version is 7.
Can someone please help me setting the Java 8 as default on my system?
Thanks!
To be able to use java -version in a command prompt and have Java 8 as the result, the Java 8's bin directory must be in the PATH environment variable, before the other directories where java.exe exists (so, for example, at the very beginning of the PATH.
In IntelliJ IDEA, you have to open File - Project structure and
under SDKs, make sure the 1.8 SDK is selected and not 1.7. If 1.8 isn't listed, then click the + icon at the top and add it
under Project, make sure the project SDK is 1.8, and the project language level is 8.0.
You can also change it in the Project structure menu under :
File > Project structure > Modules
and then source tab

Upgrade Java version for Web Application

I have a web Application and i need to upgrade java jre version from 6 to 7 .I am using Eclipse as IDE.I tried to update the Jre from eclipse .I have even updated the JAVA_HOME environment variable but i am getting following error
C:\Program Files\Java\jdk1.7.0_55\jre..\lib\tools.jar
Please ensure you are using JDK 1.4 or above and
not a JRE (the com.sun.tools.javac.Main class is required).
In most cases you can change the location of your Java
installation by setting the JAVA_HOME environment variable.
Thanks
Download java hereand install it as a common application.
Then in Eclipse use Window->Prefrences->Java->Installed JREs
#Roman Bondar I guesss OP wanted to know more than just the setting.
Basically, JREs are meant to be downwards compatible, so that you are able to execute java classes compiled with version 6 with a runtime from java 7.
But as always, there may be special cases when things have to be changed, e.g. container or libraries. I remember a case back when I migrated to java 6 that it required a special version of JBoss.
Check out this Oracle blog as a starting point.

can't create new AWS java web project

I'm using Eclipse 4.2.1
under OSX 10.8.2.
In Eclipse > Preferences > Java > Installed JREs,
I have Java SE 6 installed.
I installed Amazon AWS SDK from the Eclipse Marketplace.
I'm trying to start a new AWS Java Web Project
and I get the following errors:
Unable to create new AWS Java web project.
One or more constraints have not been satisfied.
Dynamic Web Module 2.5 require Java 1.5 or newer.
but I have Java SE 1.6! Why?
Any ideas?
I installed Eclipse for Java EE instead of Eclipse generic and it solved the issue.
I had a similar problem with Windows 8.1 Pro. I tried a bunch of things, but I wasn't able to successfully deploy anything to AWS ElasticBeanstalk until I removed all existing versions of Java and then installed Java EE 7u45 win32 (previously was JEE 8, both 32 & 64 bit).
But here is what I did entirely:
Deleted existing workspace and created a new one.
Make sure that your AWS Toolkit Preferences are setup correctly: Window -> Preferences -> AWS Toolkit
Removed all existing versions of java.
Downloaded and installed Java EE 7u45 win32.
Made sure that my System Path and JAVA_HOME variables were set properly: Control Panel -> System and Security -> System -> Advanced System Settings -> Advanced -> Environmental Variables
Hope this helps :)
I installed Eclipse 4.3.2, then added AWS on top and I get the same error. Same with running Eclipse on Java 1.7.0_51 or Java 8 (b132).
I also get an error dialog saying "X does not exist" where X is my new project name. X was created but there is only a .project file and one file in .settings.
My error log contains:
Java Model Exception: Java Model Status [X does not exist]
at org.eclipse.jdt.internal.core.JavaElement.newNotPresentException(JavaElement.java:498)
at org.eclipse.jdt.internal.core.JavaModelManager.getPerProjectInfoCheckExistence(JavaModelManager.java:2309)
at org.eclipse.jdt.internal.core.JavaProject.getPerProjectInfo(JavaProject.java:1908)
at org.eclipse.jdt.internal.core.JavaProject.getRawClasspath(JavaProject.java:1930)
at com.amazonaws.eclipse.elasticbeanstalk.webproject.CreateNewAwsJavaWebProjectRunnable.findSdkClasspathEntry(CreateNewAwsJavaWebProjectRunnable.java:219)
at com.amazonaws.eclipse.elasticbeanstalk.webproject.CreateNewAwsJavaWebProjectRunnable.run(CreateNewAwsJavaWebProjectRunnable.java:191)
at org.eclipse.jface.operation.ModalContext$ModalContextThread.run(ModalContext.java:121)
org.eclipse.core.commands.ExecutionException: One or more constraints have not been satisfied.
at org.eclipse.wst.common.componentcore.internal.operation.FacetProjectCreationOperation.execute(FacetProjectCreationOperation.java:110)
at org.eclipse.wst.common.frameworks.internal.datamodel.DataModelPausibleOperationImpl$1.run(DataModelPausibleOperationImpl.java:385)
at org.eclipse.core.internal.resources.Workspace.run(Workspace.java:2345)
at org.eclipse.wst.common.frameworks.internal.datamodel.DataModelPausibleOperationImpl.runOperation(DataModelPausibleOperationImpl.java:410)
at org.eclipse.wst.common.frameworks.internal.datamodel.DataModelPausibleOperationImpl.runOperation(DataModelPausibleOperationImpl.java:360)
at org.eclipse.wst.common.frameworks.internal.datamodel.DataModelPausibleOperationImpl.doExecute(DataModelPausibleOperationImpl.java:247)
at org.eclipse.wst.common.frameworks.internal.datamodel.DataModelPausibleOperationImpl.executeImpl(DataModelPausibleOperationImpl.java:219)
at org.eclipse.wst.common.frameworks.internal.datamodel.DataModelPausibleOperationImpl.cacheThreadAndContinue(DataModelPausibleOperationImpl.java:89)
at org.eclipse.wst.common.frameworks.internal.datamodel.DataModelPausibleOperationImpl.execute(DataModelPausibleOperationImpl.java:207)
at com.amazonaws.eclipse.elasticbeanstalk.webproject.CreateNewAwsJavaWebProjectRunnable.run(CreateNewAwsJavaWebProjectRunnable.java:150)
at org.eclipse.jface.operation.ModalContext$ModalContextThread.run(ModalContext.java:121)
Caused by: org.eclipse.core.runtime.CoreException: One or more constraints have not been satisfied.
at org.eclipse.wst.common.project.facet.core.internal.FacetedProject.modifyInternal(FacetedProject.java:363)
at org.eclipse.wst.common.project.facet.core.internal.FacetedProject.mergeChangesInternal(FacetedProject.java:1181)
at org.eclipse.wst.common.project.facet.core.internal.FacetedProject.access$2(FacetedProject.java:1117)
at org.eclipse.wst.common.project.facet.core.internal.FacetedProject$1.run(FacetedProject.java:324)
at org.eclipse.core.internal.resources.Workspace.run(Workspace.java:2345)
at org.eclipse.wst.common.project.facet.core.internal.FacetedProject.modify(FacetedProject.java:339)
at org.eclipse.wst.common.componentcore.internal.operation.FacetProjectCreationOperation.execute(FacetProjectCreationOperation.java:83)
... 10 more
Dynamic Web Module 2.5 requires Java 1.5 or newer.
Arg,

Categories

Resources