I am trying to run a Java application, but getting this error:
java.lang.ClassNotFoundException:
After the colon comes the location of the cla
If you have moved your project to new machine or importing it from git, then try this.
It worked for me.
Basic Generic Question - Simplest Generic Answer ;)
Given the information I will make the assumption that you might be trying a basic approach to coding, building/compiling and running a simple console app like "Hello World", using some simple text editor and some Command Shell.
This error occurs in the fallowing scenario:
..\SomePath>javac HelloWorld.java
..\SomePath>java HelloWorld.class
In other words, use:
..\SomePath>java HelloWorld
P.S. The adding the file extension .class produces the same mistake. Also be sure to have the Java's (JDK/JRE) bin folder in the operating system's Environment Variables's PATH.(Lookup for more details other posts on this) P.P.S Was I correct in my assumption/s?
If you know the path of the class or the jar containing the class then add it to your classpath while running it. You can use the classpath as mentioned here:
on Windows
java -classpath .;yourjar.jar YourMainClass
on UNIX/Linux
java -classpath .:yourjar.jar YourMainClass
I just did
1.Invalidate caches and restart
2.Rebuilt my project which solved the problem
If you use maven, check that you have this plugin in your pom.xml
:
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>3.2.0</version>
<executions>
<!-- Attach the shade goal into the package phase -->
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
It will put your dependency (the exception reason) to your jar.
FYI: this will include all dependencies inflated in the final jar
If you have added multiple (Third-Party)**libraries and Extends **Application class
Then it might occur.
For that, you have to set multiDexEnabled true
and replace your extended Application
class with MultiDexApplication
.
It will be solved.