score:51
Main class is configurable in pom.xml
<properties>
<start-class>com.bt.collab.alu.api.webapp.Application</start-class>
</properties>
score:0
I am new in spring boot and using STS with maven build. I did all the things mentioned above but won't work for me. I noticed two problems in problem window of STS. There was a missing jar file on the path (C:\Users\UserName.m2\repository\com\jayway\jsonpath\json-path\2.2.0). I did following, the way is not strongly suggested but worked for me.
1) I deleted .m2 folder from the path location
2) Restarted STS
3) Right Click on project folder -> maven -> update project -> checked "Force update of snapshots/releases" -> Click Ok.
Maven updated its dependencies and the problem is solved.
score:0
I had this same issue and tried a couple of the solutions and they didn't work. The way I solved it was easy and straight forward.
Right click on the spring boot app, select "Maven" > Update Project,
check the spring boot app you want to fix and press the OK button.
After it finishes running I was able to start the app successfully.
score:1
If you came across the
error:could not find or load main class in maven project
do this it worked for me:
Reason for the error: The reason for this error is the jar file or dependency to run a maven project is not installed correctly.
Solution for the error: Go to the project folder (eg: D:\office\OIA-service-app
)
in the address bar of computer type command cmd
and press enter.
In the command prompt type command mvn clean install
make sure you have the internet connection.
score:1
If your project packaging type war you could not start. I was using maven assembly plugin with this configuration;
<build>
<plugins>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<version>3.0.0</version><!--$NO-MVN-MAN-VER$ -->
<configuration>
<descriptors>
<descriptor>assembly.xml</descriptor>
</descriptors>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
<archive>
<manifest>
<mainClass>com.ttech.VideoUploaderApplication</mainClass>
</manifest>
</archive>
</configuration>
<executions>
<execution>
<id>make-assembly</id> <!-- this is used for inheritance merges -->
<phase>package</phase> <!-- bind to the packaging phase -->
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
and my packaging tpe was war i got cannot find main class exception bu i changed packaging to jar it worked;
<groupId>com.ttect</groupId>
<artifactId>VideoUploadListener</artifactId>
<version>1.0.0</version>
<packaging>**jar**</packaging>
score:1
In my case the following helped:
Added the following section in pom
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<executable>true</executable>
</configuration>
</plugin>
</plugins>
Ran it using maven3 and it worked
score:1
I also got this error, was not having any clue. I could see the class and jars in Target folder. I later installed Maven 3.5, switched my local repo from C drive to other drive through conf/settings.xml of Maven. It worked perfectly fine after that. I think having local repo in C drive was main issue. Even though repo was having full access.
score:1
I was facing the same problem. I have deleted the target folder and run maven install, it worked.
score:1
I had similar kind of problem while I was adding spring security dependency to my project , then I deleted my target folder and used maven update again . It's worked for me.
score:1
Even I faced the same issue, later I found that it happened because the maven build operation was not happening properly in my environment. Please check it in your case also.
score:1
score:1
I got the same error in the "Spring Tool Suite" software.
In my case, I have Java 8 installed and I created a project of Java 11. And when I run the project I got the same error, like " can not find main class ".
Then I created a project in Java 8 and the problem resolved.
score:1
(Eclipse) Updating maven project was not working for me. What I had to do was to go in Run configurations, and in "Main" tab, in "Project" field, write the whole package name com.bla.blabla.MyMainClass (instead of just the Main class name). The error happened because I have several projects with the same name, but in different packages.
score:1
if none of above solutions work, try to replace build tag with this inside pom file :
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins></pluginManagement>
</build>
score:2
I have used spring 1.5.3.RELEASE version and given pom dependencies like
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.3.RELEASE</version>
</parent>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
</dependencies>
And my main class was
@SpringBootApplication
public class SpringAppStarter {
public static void main(String[] args) {
SpringApplication.run(SpringAppStarter.class, args);
}
}
But still while execution of main class I was getting:
Could not find or load main class ... with my class name.
I could see that class was available in the class path and I was using STS IDE.
I was not getting reason for the issue then I tried manual build through maven with
mvn clean install
Still problem was there then i realize that my project has two libraries
- Reference Library
- Maven Library
What I did:
I have created another mavenRepo folder and build it again and refresh my project. After that it worked and I saw that Maven Library was deleted from project class path.
Issues was while execution it was getting multiple version so it was not able to find proper class to execute my application. Other Solution listed in this page also resolves the issue but if you are doing mistake in
- Annotating class
- pom entry
- jar version etc.
Hope this may resolve problem if somebody get this issue
score:2
deleting old jars from .m2 and updating maven project should be primary step. In most of the cases it resolves the issue.The reason for this issue is mostly corrupted old jars
score:2
Encountered the same issue and was able to fix it by the following the steps listed below:
- File -> Invalidate Cache and Restart
- File -> New -> Project from existing source
- Select the pom.xml file just (not the whole project directory) to load the project. Project will be setup automatically.
score:2
Error:Could not load or find main class
Project:Spring Boot Tool:STS
Resolve Steps:
- Run the project
- See in problems tab, it will show the corrupted error
- Delete that particular jar(corrupted jar) in .m2 folder
- Update project
- Run successfully
score:2
I was having the same problem just delete .m2 folder folder from your local repositry Hope it will work.
score:2
start-class
doesn't work for me, I fixed it by adding build plugins
to pom.xml
, and executions
is necessary.
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
score:2
There are good answers here, but maybe this one will also help somebody.
For me it happened just after i deleted .idea (with IntelliJ), and reimported the project.
then this issue started, i tried to run mvn compile (just via IDE Maven toolbar), once i fixed few compilation errors, issue disappeared
score:3
I know this is pretty late answer. But it might still help some new learners. The Following example is only for springboot with NETBEANS. I had to do the following steps:
Step 1. Follow @Mariuszs answer .
Step 2. Right click on project -> Properties -> RUN. Make sure the Main Class field is has the correct starter class else Click browse and select from the available classes .
Step 3. Click OK-> OK. Thant is all. Thank you.
score:3
The solution for me was:
- Boot Dashboard, right click on your Instance.
- Open Config
- Tab Spring Boot
- Main Type, there was the path to the application file missing...
score:5
Use spring-boot:run command to start spring boot application:
Precondition: 1. Add following property to pom.xml
<property>
<start-class>com.package.name.YourApplicationMainClass</start-class>
</property>
2. Build your project
Then configure maven command with spring-boot:run.
Navigation:
Right Click Project | Run As | Run Configuration... | Add new Maven Configuration with command spring-boot:run
score:5
In case if someone is using Gradle for the build then fix will be by adding the following lines in build.gradle file
apply plugin: 'application'
mainClassName = "com.example.demo.DemoApplication"
score:5
Intellij
- close Intellij
- remove all files related to Intellij (.idea folder and *.iml files)
- open the project in Intellij as if it was the first time (using open recent won't work, id needs to be done via file -> open)
score:11
This happened to me after i updated the pom (Added some dependencies).
The following step helped me to avoid this error
right click on the project > maven > update project
score:12
I tried all the above solution, but didn't worked for me. Finally was able to resolve it with a simple fix.
on STS, Run Configuration > open your Spring Boot App > Open your configuration, Follow the steps,
- In Spring boot Tab, check your Main class and profile.
- Then go to classpath tab, In the bottom you will see two checkboxes,one is "Exclude Test Code"(Check this if you do not want to run test classes) and other, "Use Temporary Jar file to specify classpath" (this is necessary).
score:17
If you're using Spring Boot and the above suggestions don't work, you might want to look at the Eclipse Problems view (available at Window -> Show View -> Problems).
For example, you can get the same error (Error: Could not find or load main class groupId.Application) if one of your jar files is corrupted. Eclipse will complain that it can't find the Applications class, even though the bad jar is the root cause.
The Problems view, however, will identify the bad jar for you.
At any rate, I had to manually go to my local mvn repo (in .m2) and manually delete the corrupted jar, and update it (right click on the project in the Package Explorer), Maven --> Update Project... -> OK (assuming that the correct project is check-marked).
score:22
Have a look under "Run -> Run Configurations..." in Eclipse. You should delete the new one which you created by mistake, you should still have the existing one.
I suspect it has created a new run configuration for the "Run as Maven Test" and you are now always starting this one.
score:138
I had the same problem. Try this :
Right Click the project -> Maven -> Update Project
Then Re-run the project. Hope it work for you too.
Source: stackoverflow.com
Related Query
- Spring Boot Program cannot find main class
- Spring Boot can't find main class
- Why this error "Could not find or load main class" appears when I execute the main class in a spring boot project in eclipse
- Could not find or load main class in Eclipse Spring boot project
- Error: Could not find or load main class in Spring STS for Spring BOOT project
- Cannot find the main class after converting java project to maven
- Why won't my program find the main class correctly?
- Spring cannot find class, although the class exists
- Cannot find Main Class in File Compiled With Ant
- Could not find main class : Program will exit
- Could not find the main class x. Program will Exit
- Maven - error cannot find or load main class
- Gradle (wrapper) + STS + Spring Boot: Error: Could not find or load main class 1.1,
- Eclipse cannot find main class
- Trying to run a java program in console will give a could not find or load main class error
- Eclipse Java Error: Cannot find or load main class
- Cannot find main method in class Super
- Cannot find or load main class from .jar file
- Error: Cannot find or load main class only when running outside of eclipse
- Java: Eclipse: Cannot Find Main Class
- Eclipse cannot find the main class in JFace?
- Eclipse cannot find main class of maven project
- Fixing Error: cannot find main class with jar
- Spring Web App - CannotLoadBeanClassException Cannot find class [package] for bean with name 'somename'
- Eclipse Error: Could not find or load main class
- Eclipse can't find / load main class
- Could not find or load main class org.apache.catalina.startup.Bootstrap
- Cannot find the class file for java.lang.Object
- Error: Cannot run program "jar": CreateProcess error=2, The system cannot find the file specified
- Scala Error: Could not find or load main class in both Scala IDE and Eclipse
More Query from same tag
- Best way to open phonegap project created with CLI in eclipse
- Android app calculator exits on start
- Java - NoClassDefFoundError, Android lib project
- Eclipse Juno- Suddenly “cannot run program 'make' : unknow reason”
- Checkstyle working differently for same condition
- Linux Lubuntu Eclipse Checkstyle SWT Error
- use org.eclipse.core.resources method in my java app
- Error in nodeJS application
- Using clang++ for code analysis in an Autotools project in Eclipse
- What code should I write in my Welcome.java servlet to redirect to another servlet based on my html file?
- Maven dependency - Maven Install / update project
- Error on Eclipse ADT while creating an Android Application
- How can I access WebSphere authentication alias info from a Java client running outside of the server?
- Start an activity from a listview
- A resource exists with a different case
- Android Font Change
- How do I make an Image appear for a specified amount of time when a button is Clicked? In eclipse
- Eclipse PyDev is throwing false errors
- Maven not adding jars to classpath
- Why does Maven not compile the Guava Table code when Eclipse compiler does? (inferred type does not conform to upper bound(s))
- Failed to load bean class; nested exception is java.io.FileNotFoundException: class path resource cannot be opened because it does not exist
- Program Responding Really Slow [Google Api]
- is there a way to toggle search window results in eclipse
- Why running Cucumber test with Maven return result "Tests run: 0"?
- Lombok not working in intellij idea 18.1 version after importing eclipse gradle spring boot project
- The selected wizard could not be started in eclipse for Anltr 4 .How to solve?
- Google-play-services_lib Unable to resolve target 'android-9
- SharedPreferences variable not working properly
- How to set up the Servlet Path make HTML correctly invoke servlet file?
- JFrame shows up empty on Java Swing GUI