![intellij jar could not find main class intellij jar could not find main class](https://user-images.githubusercontent.com/7351168/56617838-7cab5f00-65e6-11e9-9cdf-59ddc8426161.png)
So the reason it works fine now is in java World one we place a. classfile is present, hence we need to move to parent directory and execute the java class. īut we are already inside the directory where. We do not have any CLASSPATH variable due to which it is looking for path as frugalis/HelloFrugalis from current directory. So the problem here is my class is inside non-default package ex:- frugalis in this case. So again we are getting same Error: Could not find or load main class. Now once you have added the file under folder frugalis, it perhaps aligns with the package name and this should run successfully. We are going to create a folder named as frugalis inside MyProject like below. Sounds some issue rite ? Lets try and fix it.
#INTELLIJ JAR COULD NOT FIND MAIN CLASS CODE#
We have knowingly defined the package as frugalis in our java code and we are trying to execute it from myProject folder. mkdir myProject could not find or load main classīingo !! We have got the error “Error: Could not find or load main class”. We will now compile and try to run the code from command line. Now move the above java file in a folder named as myProject. So we will now Write a Simple HelloWorld program and replicate the issue, then we will try to fix it. I bet you this troubleshooting that we are doing here to resolve the issue related to loading main class is going to help you in your future, till you are Java developer. How do We fix the Error: Could not find or load main class HelloWorld Now lets come back to the problem where we get Could not find or load main class. So now java CLASSLOADERS scans through the classpath to load your classess.
#INTELLIJ JAR COULD NOT FIND MAIN CLASS WINDOWS#
Have a Look at few Best Spring Courses for Java Developers in 2021Īs IDE itself manages all the CLASSPATH related stuff internally, but while you start running the same code from your terminal in linux or windows command line you will actually face this issue due to CLASSPATH. In eclipse or IntelliJ if you get this error you will not be able to understand the reason quickly if you are new java developer. It is easier to run and debug java code in IDE than command line. So new Java developers uses lot of IDE like eclipse and intellij to run and debug Java code. class file is not found on CLASSPATH, java will throw this error : could not find or load class Main. So for Understanding CLASSPATH is basically a part of our environment variable, While running the Java file if the corresponding. For our understanding we won’t go deep into CLASSPATH and class loading. In order to fix this error you need to have clear understanding of How Java class loading Works and working of CLASSPATH. This issue is seen mostly when java is not able to find the class it is trying to execute in your CLASSPATH. We have a HelloWorld.java class and I am trying to run the code from command line. What does this error mean could not find or load main class in java code. It is one of the most common issue newbie developers face while starting with java programming.