intellij Could not find or load main class error java - intellij-idea

Error: Could not find or load main class
Caused by: java.lang.ClassNotFoundException:
this is happening in intellij for spring boot project.
i have tried to change project settings too.
using java 11

Related

Why can't I run a JApplet in IntelliJ?

I am learning Java from the Oracle documentation page: https://docs.oracle.com/javase/tutorial/reallybigindex.html
I am using Intellij on Linux Mint and I had no problems until I got to JApplets. Whenever I am trying to run my code now I get the following error:
Error: Could not find or load main class sun.applet.AppletViewer
Caused by: java.lang.ClassNotFoundException: sun.applet.AppletViewer
Can someone point me in the right direction?

Error while using JUnit5 with spring boot 2

I am getting following error while running JUnit5 with SpringBoot.
Here is the stack trace that I get when I run
./gradlew clean test
:junitPlatformTest
Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/logging/log4j/util/ReflectionUtil
at org.apache.logging.log4j.jul.AbstractLoggerAdapter.getContext(AbstractLoggerAdapter.java:34)
at org.apache.logging.log4j.spi.AbstractLoggerAdapter.getLogger(AbstractLoggerAdapter.java:46)
at org.apache.logging.log4j.jul.LogManager.getLogger(LogManager.java:89)
at java.util.logging.LogManager.demandLogger(LogManager.java:551)
at java.util.logging.Logger.demandLogger(Logger.java:455)
at java.util.logging.Logger.getLogger(Logger.java:502)
at org.junit.platform.commons.logging.LoggerFactory$DelegatingLogger.<init>(LoggerFactory.java:62)
at org.junit.platform.commons.logging.LoggerFactory.getLogger(LoggerFactory.java:49)
at org.junit.platform.launcher.core.DefaultLauncher.<clinit>(DefaultLauncher.java:44)
at org.junit.platform.launcher.core.LauncherFactory.create(LauncherFactory.java:59)
at org.junit.platform.console.tasks.ConsoleTestExecutor.executeTests(ConsoleTestExecutor.java:61)
at org.junit.platform.console.tasks.ConsoleTestExecutor.lambda$execute$0(ConsoleTestExecutor.java:57)
at org.junit.platform.console.tasks.CustomContextClassLoaderExecutor.invoke(CustomContextClassLoaderExecutor.java:33)
at org.junit.platform.console.tasks.ConsoleTestExecutor.execute(ConsoleTestExecutor.java:57)
at org.junit.platform.console.ConsoleLauncher.executeTests(ConsoleLauncher.java:85)
at org.junit.platform.console.ConsoleLauncher.execute(ConsoleLauncher.java:75)
at org.junit.platform.console.ConsoleLauncher.execute(ConsoleLauncher.java:48)
at org.junit.platform.console.ConsoleLauncher.main(ConsoleLauncher.java:40)
Caused by: java.lang.ClassNotFoundException: org.apache.logging.log4j.util.ReflectionUtil
at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:335)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
... 18 more
The github url for above code is github link
This is caused by mixing different versions of Log4J on the test runtime classpath. Spring Boot pulls in 2.10.0, your build.gradle declares 2.6.2.
If you remove the version from your dependency definition, Spring Boot will define the version and it will work.
So, please replace these two lines
testRuntime("org.apache.logging.log4j:log4j-core:${log4jVersion}")
testRuntime("org.apache.logging.log4j:log4j-jul:${log4jVersion}")
with these:
testRuntime("org.apache.logging.log4j:log4j-core")
testRuntime("org.apache.logging.log4j:log4j-jul")
Alternatively, you can delete the logManager property from the junitPlatform extension and remove both dependencies.

Spring boot will not run in InteliJ [duplicate]

Recently I created a new project using IntelliJ IDEA and Gradle for dependency management. After resolving all the dependencies needed by the project and running it I get the following error:
java.lang.NoClassDefFoundError: org/springframework/boot/SpringApplication
at com.some.fancy.name.Application.main(Application.java:13)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:147)
Caused by: java.lang.ClassNotFoundException: org.springframework.boot.SpringApplication
at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
... 6 more
The problem occurs only with the classes from the resolved dependencies (I tried it also with a simple main program using Cache from Guava). The class causing the error is the following:
#SpringBootApplication
public class Application {
public static void main(String... args) {
SpringApplication.run(Application.class, args);
}
}
All the fields are shown correct colour (annotations are yellow, nothing is red), IntelliJ has all the resolved dependencies in the External Libraries directory. I'm using the green "run" arrow to start the project.
When using gradle from the command line, creating a fat jar then everything works fine. I already tried "Invalidate Caches/Restart", pulled the project several times from the repository, cleared the gradle caches, removed all the dependencies by hand, tried to run it using the Community Edition, the Ultimate Edition, running older projects which already worked some time ago (and don't work now).
Could it be somehow related to updating IntelliJ IDEA to 2016.3.4, build 163.12024.16?
It's a known issue in IntelliJ IDEA that is specific to Gradle 3.4 and later versions:
IDEA-167412 Gradle 3.4-rc-1 changes compile dependencies to provided
original bug report in the Gradle project with more details
comment from the responsible developer regarding "Create Module per source set" option and how Gradle integration works in IntelliJ IDEA
It's already fixed in IntelliJ IDEA 2017.1 and 2016.3.6.
You can also use Gradle 3.3 or older as a workaround if you can't or don't want to update IntelliJ IDEA.
I had the same problem, getting the error below from a spring boot application which was working fine a day before. I am using IntelliJ 2020.3, Gradle 6.5.1. I suspect my repository might have been corrupted.
Caused by: java.lang.ClassNotFoundException: org.springframework.boot.SpringApplication
After lot of tries from my IntelliJ I tried bootRun (in the gradle tree you can find this under Tasks > application > bootRun) and it worked.
Setting gradle version to 3.3 corrected this issue.

NoClassDefFoundError after IntelliJ IDEA upgrade

Recently I created a new project using IntelliJ IDEA and Gradle for dependency management. After resolving all the dependencies needed by the project and running it I get the following error:
java.lang.NoClassDefFoundError: org/springframework/boot/SpringApplication
at com.some.fancy.name.Application.main(Application.java:13)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:147)
Caused by: java.lang.ClassNotFoundException: org.springframework.boot.SpringApplication
at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
... 6 more
The problem occurs only with the classes from the resolved dependencies (I tried it also with a simple main program using Cache from Guava). The class causing the error is the following:
#SpringBootApplication
public class Application {
public static void main(String... args) {
SpringApplication.run(Application.class, args);
}
}
All the fields are shown correct colour (annotations are yellow, nothing is red), IntelliJ has all the resolved dependencies in the External Libraries directory. I'm using the green "run" arrow to start the project.
When using gradle from the command line, creating a fat jar then everything works fine. I already tried "Invalidate Caches/Restart", pulled the project several times from the repository, cleared the gradle caches, removed all the dependencies by hand, tried to run it using the Community Edition, the Ultimate Edition, running older projects which already worked some time ago (and don't work now).
Could it be somehow related to updating IntelliJ IDEA to 2016.3.4, build 163.12024.16?
It's a known issue in IntelliJ IDEA that is specific to Gradle 3.4 and later versions:
IDEA-167412 Gradle 3.4-rc-1 changes compile dependencies to provided
original bug report in the Gradle project with more details
comment from the responsible developer regarding "Create Module per source set" option and how Gradle integration works in IntelliJ IDEA
It's already fixed in IntelliJ IDEA 2017.1 and 2016.3.6.
You can also use Gradle 3.3 or older as a workaround if you can't or don't want to update IntelliJ IDEA.
I had the same problem, getting the error below from a spring boot application which was working fine a day before. I am using IntelliJ 2020.3, Gradle 6.5.1. I suspect my repository might have been corrupted.
Caused by: java.lang.ClassNotFoundException: org.springframework.boot.SpringApplication
After lot of tries from my IntelliJ I tried bootRun (in the gradle tree you can find this under Tasks > application > bootRun) and it worked.
Setting gradle version to 3.3 corrected this issue.

How to Deploy OSGI bundle of smooks in servicemix?

When i create simple maven project and run inside eclipse for smooks then it works fine but when i create osgi bundle for that and deploy it in servicemix then it shows following error...
I put my smook configuration file in servicemix_home/ConfigurationFiles/smook/......
Ex : org.milyn.SmooksException: Failed to apply processing unit [org.milyn.javabean.ext.PropertyChecker] to [org:milyn:smooks:unknowndoc:/smooks-resource-list/jb:bean/jb:wiring].
org.milyn.SmooksException: Failed to apply processing unit [org.milyn.javabean.ext.PropertyChecker] to [org:milyn:smooks:unknowndoc:/smooks-resource-list/jb:bean/jb:wiring].
at org.milyn.delivery.dom.SmooksDOMFilter.processVisitorException(SmooksDOMFilter.java:823)
at org.milyn.delivery.dom.SmooksDOMFilter.access$700(SmooksDOMFilter.java:134)
...
Caused by: org.milyn.cdr.SmooksConfigurationException: Bean class 'com.test.pojo.Order' not avilable on classpath.
at org.milyn.javabean.ext.PropertyChecker.getBeanClass(PropertyChecker.java:97)
at org.milyn.javabean.ext.PropertyChecker.getBeanType(PropertyChecker.java:78)
at org.milyn.javabean.ext.PropertyChecker.visitBefore(PropertyChecker.java:47)
Change Classloader
Get current class loader from getClass().getClassLoader() and set in
Thread.currentThread().setContextClassLoader(classLoader);
and
smooks.setClassLoader(classLoader);