I have a problem with adding maven dependencies to eclipse.
What should be OK:
pom.xml already contains all the dependencies and compilation and running tests using maven finished with success
all the source folders were recognized by eclipse
eclipse has Maven plugin and project is managed as maven project (see figure below)
pom.xml has maven-compiler-plugin, so the eclipse should know it is a maven project
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.1</version><!--$NO-MVN-MAN-VER$ -->
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
Issue:
eclipse does not resolve dependencies defined in pom.xml (guava, juint and other libraries are in pom.xml but not in eclipse class path)
any right click > Maven > Update project has no any effect (see figure below)
I noticed that libraries does not contain any Maven Managed Dependencies - by adding as described below has no any effect
My attempt to add Maven Managed Dependencies to Eclipse manually
1) Add library
1)
This attempt has no any effect and "Java Library Path" remains the same even after this action.
2)
Command
mvn eclipse:eclipse
Fails with
[ERROR] Failed to execute goal on project pmml-model: Could not resolve dependencies for project org.jpmml:pmml-model:jar:1.3-SNAPSHOT: The following artifacts could not be resolved: org.jpmml:pmml-agent:jar:1.3-SNAPSHOT, org.jpmml:pmml-schema:jar:1.3-SNAPSHOT: Could not find artifact org.jpmml:pmml-agent:jar:1.3-SNAPSHOT in sonatype-nexus-snapshots (https://oss.sonatype.org/content/repositories/snapshots) -> [Help 1]
The jar does not exist in the desired version on the server your maven script is referencing. The most recent version is 1.2.9. The snapshot version is not present. You should reference
<dependency>
<groupId>org.jpmml</groupId>
<artifactId>pmml-model</artifactId>
<version>1.2.9</version>
</dependency>
in your pom.xml.
The below jars are not present in your remote repo.
org.jpmml:pmml-agent:jar:1.3-SNAPSHOT,
org.jpmml:pmml-schema:jar:1.3-SNAPSHOT
Open the url https://oss.sonatype.org/content/repositories/snapshots in your browser to see the available snapshots/
Apparently, you are trying to set up a project that makes use of the JPMML-Evaluator library. In that case, you should only depend on the latest stable org.jpmml:pmml-evaluator dependency (which is version 1.2.13 at the moment). In other words, don't try to manage the associated org.jpmml:pmml-model, org.jpmml:pmml-schema dependencies manually.
You could base your work on the JPMML-Evaluator-Bootstrap project instead.
I'm trying to work around a maven bug MDEP-187 ( https://issues.apache.org/jira/browse/MDEP-187 ) by not using workspace resolution.
This forces me to do a mvn install for all my dependencies, I'm doing this by creating a launch configuration in eclipse with goal install.
The problem is that i have to create a launch config for every project in my multiproject workspace, in addition to install i have to manually call every launch config and run it. Which just doesn't work.
Is it possible to automatically install a project in the local repository? (whenever i update my code)
If you don't need to run dependency:copy in Eclipse, you can use following work-around:
Add a profile to your pom.xml, something like this:
<profiles>
<profile>
<id>copy</id>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>2.10</version>
<executions>
[...]
</executions>
</plugin>
</plugins>
<build>
<profile>
</profiles>
Enable workspace resolution in Eclipse.
Then Eclipse will not use dependency:copy, but you can use dependency:copy with command line: mvn install -P copy.
I did go with #khmarbaise solution:
But than you need to can handle the whole thing via
maven-assembly-plugin which can create archives / folders with all the
dependencies. Apart from that a swing ui must be started somehow which
will need some kind of shell script / batch file which you can create
by using appassembler-maven-plugin...And it sounds like you need to go
for a multi module project in maven..cause you might have parts like
core, ui, etc. which are needed to be combined in the end.
#khmarbaise i was in the understanding that the assembly-plugin didn't
support putting dependencies in a lib/ folder (just putting everything
in 1 big jar), but after a little bit of trying i just go myself a zip
with a runnable jar and my dependencies in a lib/ folder. Tomorrow i'm
going to read a bit more about the assembly-plugin. I'm happy ;-
I have a program which runs as a Spring boot App in eclipse. The program was running fine. Then i did the following:
Right click on project -> Run As -> Maven Test .
This was accidental. When i then tried to run the program as a spring boot app again, it threw the following error below.
Error: Could not find or load main class com.bt.collab.alu.api.webapp.Application
How do i point the application back to my main class?
Thanks
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.
Main class is configurable in pom.xml
<properties>
<start-class>com.bt.collab.alu.api.webapp.Application</start-class>
</properties>
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.
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).
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).
Save your configuration and run.
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
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)
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
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"
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...
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.
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
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
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.
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
I was having the same problem just delete .m2 folder folder from your local repositry
Hope it will work.
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>
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
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.
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>
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
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.
I was facing the same problem. I have deleted the target folder and run maven install, it worked.
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.
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.
I ran into same error, although i was using gradle build. Delegating IDE build/run actions to Gradle is solved my problem.
Intellij:
Settings -> Build, Execution, Deployment -> Build Tools -> Gradle -> Runner
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.
(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.
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>
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.
I have created a Maven project and I want to add all Maven dependencies in build path of the project in Eclipse. When I go to Java Build Path > Add Library > Maven Managed Dependency > Next in property dialog of the project, it asks me to Use "Maven Project Setting" to configure Maven dependency resolution.
My question is how to add maven dependencies in current build path?
from the command line type:
mvn eclipse:eclipse
this will add all the dependencies you have in your pom.xml into eclipse...
however, if you haven't done any of this before you may need to do one other, one time only step.
Close eclipse, then run the following command from the shell:
mvn -Declipse.workspace=<eclipse workspace> eclipse:add-maven-repo
sample:
mvn -Declipse.workspace=/home/ft/workspaces/wksp1/ eclipse:add-maven-repo
If you have m2e installed and the project already is a maven project but the maven dependencies are still missing, the easiest way that worked for me was
right click the project,
Maven,
Update Project...
Make sure your packaging strategy defined in your pom.xml is not "pom". It should be "jar" or anything else. Once you do that, update your project right clicking on it and go to Maven -> Update Project...
I have the same issue using SpringSource Tool Suite. I was importing an existing Maven project which ran fine from the command line. However, when I imported the project using import -> Maven -> existing Maven project, the project did not import correctly import and I could not add the maven managed dependencies library to the build path.
If I ran mvn install from the command line the project built successfully. If I ran mvn eclipse:eclipse and then imported into STS, then everything worked as expected, except of course I'd have to re-run this every time I updated the pom, which was undesirable.
I worked around it by running mvn eclipse:eclipse and then manually updating .classpath to eliminate the M2_REPO dependencies added by eclipse:eclipse and adding the m2eclipse dependency entry:
<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
<attributes>
<attribute name="org.eclipse.jst.component.dependency" value="/WEB-INF/lib"/>
</attributes>
</classpathentry>
Then I imported existing Maven project and it worked as expected.
This is a hack and I'm not sure what other consequences running eclipse:ecplise has when working with m2eclipse. But it did at least allow me to get my project compiling so I could get to coding.
EDIT 1/4/2013
The workaround I posted above will work temporarily, and I never discovered any negative side effects. However, I've had this issue a few times now and each time the problem is that there is some section of the pom that maven accepts but m2eclipse barfs on.
So I recommend removing parts of the pom 1 by 1 until you can mavenize the project successfully. Just keep running maven -> update configuration after each pom edit until it works as it should. I usually start by removing the plugin configuration tag blocks one at a time, starting with the most suspicious (i.e. most complicated).
Once it mavenizes properly, you can revert the pom and it should still work as expected.
After I get running, I'd research the offending configuration(s) to try to figure out what the 'proper' fix is (according to m2eclipse, anyway).
Hopefully this approach leads to the permanent solution instead of settling for a hacky workaround!
Install M2E plugin.
Right click your project and select Configure -> Convert to Maven project.
Then a pom.xml file will show up in your project. Double click the pom.xml, select Dependency tab to add the jars your project depends on.
You can install M2Eclipse and open the project as maven project in Eclipse. It will create the necessary configuration and entries.
This is also useful for subsequent updates to the pom. With maven eclipse plugin, you will need to manually regenerate the eclipse configuration for each changes.
I could figure out the problem. I was getting following warning on startup of eclipse.
The Maven Integration requires that Eclipse be running in a JDK, because a number of Maven core plugins are using jars from the JDk.
Please make sure the -vm option in eclipse.ini is pointing to a JDK and verify that
Installed JRE's are also using JDK installs
I changed eclipse.ini file and added following and restarted eclipse
-vm
C:/Program Files/java/jdk1.6.0_21/bin/javaw.exe
Now I can see "Maven Dependency" library included automatically in java build path.
If Maven->Update Project doesn't work for you?
These are the steps I religiously follow.
Remove the project from eclipse (do not delete it from workspace)
Close Eclipse
go to command line and run these commands.
mvn eclipse:clean
mvn eclipse:eclipse -Dwtpversion=2.0
Open Eclipse
import existing Maven project.
You will see the maven dependency in our project.
Hope this works.
If you imported an existing maven project and Maven dependencies are not showing in the build path in eclipse then right click on project--> Maven--> 'update Project' will resolve the issue.
If you have removed Maven dependency from Library accidentally. Add below in pom.xml
<build>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.3</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
</plugins>
</build>
If you use an eclipse plugin to do your maven tasks (there are 2 of them : M2ecipse from sonatype the 'official' one and q4e on Google Code) then, there are options in the contextual menus (right click on the project) to do that painlessly.
You can have both plugins running at the same time in your eclipse workbench and use them indifferently on a per project basis.
Try:Right Click your project->Maven->Disable Dependency Management.
And re-enable dependency management.
You could also consider to maven-dependency-plugin to your pom:
<plugins>
...
<plugin>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<phase>process-resources</phase>
<goals>
<goal>copy-dependencies</goal>
</goals>
<configuration>
<outputDirectory>${project.build.directory}/lib</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>
...
</plugins>
Than you can run "mvn package" and maven will copy all needed dependencies to your_project_path/target/your_project_name/WEB-INF/lib/ directory. From there you can copy them to your project/lib dir and add as external jars (configuring your project settings buildpath)
Follow these steps
1) Go in projects class path
2) Go in library tab
3) click on Add Library
4) In opened dialogue select Maven Managed Dependencies
5) Click on Next
6) In the new dialogue click on Manage Project Settings
7) In opened dialogue select the check box Resolve dependencies from workspace
8) Click on Restore defaults
9) It will do some process and you will have all your dependencies in your library now.
Likely quite simple but best way is to edit manually the file .classpath at the root of your project folder with something like
<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
<attributes>
<attribute name="maven.pomderived" value="true"/>
<attribute name="org.eclipse.jst.component.dependency" value="/WEB-INF/lib"/>
</attributes>
</classpathentry>
when you want to have jar in your WEB-IN/lib folder (case for a web app)
If this has not been created as a Maven project but you need to add maven dependencies then Right-click on Project -> Configure -> Convert to Maven Project.
This will add a pom.xml file to your project.
If the pom.xml file already exists, it is already a Maven project so that you can add your dependencies directly in pom.xml
Now to do any other actions related to Maven, you can Right Click on project and click Maven
I have a multi-module maven project. The parent pom.xml is simply a way to reference common information for the 4 subprojects. I have quite a few JUnit tests that run and I also have the Parent Project set up for Project WebSite using the maven-info-reports-plugin.
I have the maven-surefire-report-plugin configured in the parent and it generates the target/site/surefire-report.html file in each of the subprojects with the correct information.
My problem is when I run my project website via site:run I do not see any of the surefire-report.html files in the Project website. The one that shows is in the target directory of the parent and it has no unit tests defined.
Is there a way I can configure maven-surefire-report-plugin or maven-info-reports-plugin to aggregate the subprojects generated surefire reports?
To elaborate on Seph's answer. You can set many of the Maven reports to aggregate results. To do this with the surefire-report plugin you'd do something like this:
<reporting>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-report-plugin</artifactId>
<version>2.4.2</version>
<configuration>
<aggregate>true</aggregate>
<!--also set this to link to generated source reports-->
<linkXRef>true</linkXRef>
</configuration>
</plugin>
</plugins>
</reporting>
Note the additional linkXRef property, this allows you to add cross-references to the generated html version of the source produced by the jxr plugin. The jxr plugin can also be set to aggregate, so the two combined allow you to browse your entire project structure.
As far as I know, the maven-info-reports-plugin doesn't do aggregation.
You can add
<aggregate>true</aggregate>
to the surefire plugin in the parent pom.xml.
For command line
mvn surefire-report:report -Daggregate=true
It could be -
mvn clean test -fn surefire-report:report -Daggregate=true
OR
mvn clean install -fn surefire-report:report -Daggregate=true
Note :
fn -> NEVER fail the build, regardless of project result
To add in pom
<aggregate>true</aggregate>