How to add "Maven Managed Dependencies" library in build path eclipse? - java

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

Related

Maven 2.5.1 doesn't support JDK 7 [duplicate]

In Eclipse Juno, I installed the latest m2e plugin (1.2.20120903-1050). In preferences, I have added jdk1.7.0_11 in Java -> Installed JREs -> Add, and then specified the location (C:\Program Files\Java\jdk1.7.0_11). When I create a new Maven project and run it, I get a warning:
Build path specifies execution environment J2SE-1.5. There are no JREs installed in the workspace that are strictly compatible with this environment.
I am not sure how to resolve this.
I believe it is a Maven problem because I do not have this error when I run normal Java projects. I read here that I should change the "maven-compiler-plugin.pom" and change the source and target from 1.5 to something more appropriate. In my case, 1.7. I have done this, but I still get the warning.
All of the answers above may work for the time being but whenever you run maven on the command line or Maven &rightarrow; Update project… the JDK will be reset, this was also the question as I understand it.
To fix this for good add the following code to your pom file. Remember to do a Maven &rightarrow; Update project… afterwards or mvn clean compile at the command line.
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
</plugins>
</pluginManagement>
</build>
Right-click on your project
Click Properties
Click the "Java Compiler" option on the left menu
Under JDK compliance section on the right, change it to "1.7"
Run a Maven clean and then Maven build.
I know this is an old topic. I had the same problem. I tested all the answers about this topic. And nothing worked here... but i found another solution.
Go to pom->overview and add these to you properties:
Name: "maven.compiler.target" Value: "1.7"
and
Name: "maven.compiler.source" Value: "1.7"
Now do a maven update.
For imported maven project and JDK 1.7 do the following:
Delete project from Eclipse (keep files)
Delete .settings directory, .project and .classpath files inside your project directory.
Modify your pom.xml file, add following properties (make sure following settings are not overridden by explicit maven-compiler-plugin definition in your POM)
<properties>
<maven.compiler.source>1.7</maven.compiler.source>
<maven.compiler.target>1.7</maven.compiler.target>
</properties>
Import updated project into Eclipse.
I'm using Juno 4.2 with latest spring, maven plugin and JDK1.6.0_25.
I faced same issue and here is my fix that make default after each Eclipse restart:
List item
Right-click on the maven project
Java Build Path
Libraries tab
Select current wrong JRE item
Click Edit
Select the last option (Workspace default JRE (jdk1.6.0_25)
If you are getting following type of error
Then do the following steps-->>
Go to Windows. Then select Preferences, in Which select java(on the left corner).
In java select Installed JREs and check your JRE(if you have correctly installed jdk and defined environment variables correct then you will see the current version of the installed java here)as shown -
(I have Java 8 installed)
Check the check box if it is not checked. Click apply and close.
Now Press Alt+Enter to go into project properties,or go via right clicking
on project and select Properties.
In Properties select Java Build Path on left corner
Select Libraries
And click edit(after selecting The JRE System Library...)
In edit Click and select Workspace default JRE. Then click Finish
In Order and Export Check the JRE System Library.
Then Finally Apply and close
Clean the project and then build it.
Problem Solved..Cheers!!
In order to update your project to the latest version of java available in your environment, follow these steps:
Open your pom.xml file
Switch your view to Effective POM tab
Open Find Dialog (ctrl + F) to search for maven-compiler-plugin
Copy the the following lines
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
Click on pom.xml tab to open your project pom configuration
Inside your <build> ... </build> configuration section, paste the configuration copied and modify it as...
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
save your configuration
Right Click in your project Click on [Maven -> Update Project] and Click on OK in the displayed update dialog box.
Done!
I was facing the same issue. In pom.xml I have specified maven compiler plugin to pick 1.7 as source and target. Even then when I would import the git project in eclipse it would pick 1.5 as compile version for the project. To be noted that the eclipse has installed runtime set to JDK 1.8
I also checked that none of the .classpath .impl or .project file is checked in git repository.
Solution that worked for me: I simply deleted .classpath files and did a 'maven-update project'. .classpath file was regenerated and it picked up 1.7 as compile version from pom file.
I got an error in Eclipse Mars version as "Build path specifies execution environment J2SE-1.5. There are no JREs installed in the workspace that are strictly compatible with this environment.
To resolve this issue, please do the following steps,
"Right click on Project
Choose Build path
Choose Configure Build path
Choose Libraries tab
Select JRE System Library and click on Edit button
Choose workspace default JRE and Finish
Problem will be resolved.
When creating a maven project in eclipse, the build path is set to JDK 1.5 regardless of settings, which is probably a bug in new project or m2e.
I tested all the answers about this topic. And nothing worked here… but I found another solution.
Go to pom -> overview and add these to your properties:
Name: “maven.compiler.target” Value: “1.8”
and
Name: “maven.compiler.source” Value: “1.8”
Now do a maven update.

Spring Boot Program cannot find main class

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.

IntelliJ cannot load sources from local Maven repository

I'm doing some testing work that requires the use of features in JUnit which are unfamiliar to me. In order to better understand these features I'd like to be able to view the JUnit sources inside IntelliJ alongside my project.
This project uses Maven. I have the following dependency for jUnit listed in my pom.xml file:
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.10</version>
</dependency>
When I run "mvn clean install" on the command line the jUnit sources are downloaded from my company's Maven repository into my local Maven repository (.m2 directory). The project then compiles and runs without issue.
After right-clicking on the pom.xml file and selecting Maven->Reimport I can see that the classes, sources, and javadocs for jUnit are also present in the library settings in IntelliJ:
However, when I try to open a jUnit class file in IntelliJ and click on the "Download Sources" link I see this:
It seems to might like IntelliJ should be finding these sources just fine locally. Even if it did have to download them from my company's repository I also believe it should find them there since that's where the junit-4.10-sources.jar file in my local repository originally came from.
What might be keeping IntelliJ from loading the sources from the JAR file that it already knows about?
I was able to replicate this in IntelliJ 16 on Windows.
Here is how I resolved it:
Choose file -> Settings -> Build, Execution, Deployment -> Build Tools -> Maven -> Repositories
Select Your local repository from the list (or add it if it is not there)
Click the 'Update' button
Click ok
Right click your pom.xml file and select Maven -> Reimport
I had the same problem. In my case I have 2 projects developed locally (project A and B) where project B is a dependency of the project A. I solved it by:
First: On project B add the following plugin to your pom file:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
<version>3.2.0</version>
<executions>
<execution>
<id>attach-sources</id>
<phase>verify</phase>
<goals>
<goal>jar-no-fork</goal>
</goals>
</execution>
</executions>
</plugin>
More info about this plugin here: https://maven.apache.org/plugins/maven-source-plugin/usage.html
Second: On project B root folder run: mvn source:jar followed by mvn install.
The first command will generate the sources and the second will publish them in your local repo.
Then IntelliJ, on project A, automatically picked up the sources from project B. If it doesn't then you may need to reload your project dependencies on project A or run mvn clean install on the root folder

Maven "build path specifies execution environment J2SE-1.5", even though I changed it to 1.7

In Eclipse Juno, I installed the latest m2e plugin (1.2.20120903-1050). In preferences, I have added jdk1.7.0_11 in Java -> Installed JREs -> Add, and then specified the location (C:\Program Files\Java\jdk1.7.0_11). When I create a new Maven project and run it, I get a warning:
Build path specifies execution environment J2SE-1.5. There are no JREs installed in the workspace that are strictly compatible with this environment.
I am not sure how to resolve this.
I believe it is a Maven problem because I do not have this error when I run normal Java projects. I read here that I should change the "maven-compiler-plugin.pom" and change the source and target from 1.5 to something more appropriate. In my case, 1.7. I have done this, but I still get the warning.
All of the answers above may work for the time being but whenever you run maven on the command line or Maven &rightarrow; Update project… the JDK will be reset, this was also the question as I understand it.
To fix this for good add the following code to your pom file. Remember to do a Maven &rightarrow; Update project… afterwards or mvn clean compile at the command line.
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
</plugins>
</pluginManagement>
</build>
Right-click on your project
Click Properties
Click the "Java Compiler" option on the left menu
Under JDK compliance section on the right, change it to "1.7"
Run a Maven clean and then Maven build.
I know this is an old topic. I had the same problem. I tested all the answers about this topic. And nothing worked here... but i found another solution.
Go to pom->overview and add these to you properties:
Name: "maven.compiler.target" Value: "1.7"
and
Name: "maven.compiler.source" Value: "1.7"
Now do a maven update.
For imported maven project and JDK 1.7 do the following:
Delete project from Eclipse (keep files)
Delete .settings directory, .project and .classpath files inside your project directory.
Modify your pom.xml file, add following properties (make sure following settings are not overridden by explicit maven-compiler-plugin definition in your POM)
<properties>
<maven.compiler.source>1.7</maven.compiler.source>
<maven.compiler.target>1.7</maven.compiler.target>
</properties>
Import updated project into Eclipse.
I'm using Juno 4.2 with latest spring, maven plugin and JDK1.6.0_25.
I faced same issue and here is my fix that make default after each Eclipse restart:
List item
Right-click on the maven project
Java Build Path
Libraries tab
Select current wrong JRE item
Click Edit
Select the last option (Workspace default JRE (jdk1.6.0_25)
If you are getting following type of error
Then do the following steps-->>
Go to Windows. Then select Preferences, in Which select java(on the left corner).
In java select Installed JREs and check your JRE(if you have correctly installed jdk and defined environment variables correct then you will see the current version of the installed java here)as shown -
(I have Java 8 installed)
Check the check box if it is not checked. Click apply and close.
Now Press Alt+Enter to go into project properties,or go via right clicking
on project and select Properties.
In Properties select Java Build Path on left corner
Select Libraries
And click edit(after selecting The JRE System Library...)
In edit Click and select Workspace default JRE. Then click Finish
In Order and Export Check the JRE System Library.
Then Finally Apply and close
Clean the project and then build it.
Problem Solved..Cheers!!
In order to update your project to the latest version of java available in your environment, follow these steps:
Open your pom.xml file
Switch your view to Effective POM tab
Open Find Dialog (ctrl + F) to search for maven-compiler-plugin
Copy the the following lines
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
Click on pom.xml tab to open your project pom configuration
Inside your <build> ... </build> configuration section, paste the configuration copied and modify it as...
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
save your configuration
Right Click in your project Click on [Maven -> Update Project] and Click on OK in the displayed update dialog box.
Done!
I was facing the same issue. In pom.xml I have specified maven compiler plugin to pick 1.7 as source and target. Even then when I would import the git project in eclipse it would pick 1.5 as compile version for the project. To be noted that the eclipse has installed runtime set to JDK 1.8
I also checked that none of the .classpath .impl or .project file is checked in git repository.
Solution that worked for me: I simply deleted .classpath files and did a 'maven-update project'. .classpath file was regenerated and it picked up 1.7 as compile version from pom file.
I got an error in Eclipse Mars version as "Build path specifies execution environment J2SE-1.5. There are no JREs installed in the workspace that are strictly compatible with this environment.
To resolve this issue, please do the following steps,
"Right click on Project
Choose Build path
Choose Configure Build path
Choose Libraries tab
Select JRE System Library and click on Edit button
Choose workspace default JRE and Finish
Problem will be resolved.
When creating a maven project in eclipse, the build path is set to JDK 1.5 regardless of settings, which is probably a bug in new project or m2e.
I tested all the answers about this topic. And nothing worked here… but I found another solution.
Go to pom -> overview and add these to your properties:
Name: “maven.compiler.target” Value: “1.8”
and
Name: “maven.compiler.source” Value: “1.8”
Now do a maven update.

Successful build in Maven still showing errors in Eclipse

I'm having something quite peculiar here, my build is successful in maven when I type "mvn clean install" however once imported into Eclipse it's showing errors.
See for yourself:
I guess exluding quartz from the `pom.xml solved the problem but I'd like to know why.
PS: Here is the pom.xml in case you want to see it:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.nantes.mpclient</groupId>
<artifactId>MyClient</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>
<name>MyClient</name>
<url>http://maven.apache.org</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.nantes.mp</groupId>
<artifactId>MyEjb</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.jboss.jbossas</groupId>
<artifactId>jboss-as-client</artifactId>
<version>5.1.0.GA</version>
<type>pom</type>
</dependency>
</dependencies>
</project>
###EDIT
As you can see quartz is here:
Updating maven project after importing it has fixed this issue for me:
Right click on the project --> Maven --> Update project.
Sometimes I get these types of issues as well.
Generally, what worked best for me with Eclipse & Maven:
Use the latest m2e Eclipse plugin
Use Maven 3
Make sure m2e uses the same Maven version as the one you're using on the command line (not the internal one)
Import projects as Maven projects to generate the Eclipse project files
The other upvoted answers did not work for me using these versions:
Eclipse Neon
Maven 3
m2e 1.7
This is what I had to do:
Delete the Eclipse project from Eclipse interface (do not delete project contents on disk)
Go to the project's root directory in a file explorer or terminal
Delete these files: .classpath, .project, and .settings directory
Back to Eclipse, File -> Import... -> Maven -> Existing Maven projects
If you don't see any error in Eclipse project but it keeps showing the red icon on your project name. Try mvn eclipse:eclipse.
Then select all projects in Eclipse, Right click > Maven > Update projects
Hope it helps.
You should try mvn eclipse:eclipse
And then make sure the M2_REPO variable is point to your local repository.
sometimes maven update nor all above works.
so check which import statement gives you error, then go particular lib file which is usually in c:user/ur-PC-NAME/.m2 get into package delete that .jar file.
then in eclipse, right click on project > maven > update maven.
Sometimes the m2e "maintained" eclipse project is out-of-sync with the actual project in POM (There are lots of reason for that). Assume you have using m2e 0.8 or later, right click on the project, under Maven, there are two entries that are usually useful. They are Update Dependencies and Update Project Configuration
Have a try on them, wait a while after u clicked that for eclipse to update the project and build. Normally it solves similar problems.
That often happens when the m2eclipse hasn't updated the build path to correspond to what a modified POM file says. There's an entry in the Maven context menu to update the Configuration.
In my case,
I just deleted project from Eclipse (not ticked checkbox to delete
from project location).
Opened project as "Existing Maven Project" again.
and it solved my issue.
I found that my project was using a project specific Java Compiler setting set to Java 1.5. Furthermore, the project facets were still referencing Java 1.5 when Maven, m2e, Eclipse general Java Compiler settings were all set to Java 1.8.
In my case there were also problems with Java build path like the following:
"Build path specifies execution environment J2SE-1.5. There are no JREs installed in the workspace that are strictly compatible with this environment." Fixing this resolved compilation errors.
You've a library (quartz-1.5.2.jar) that's reference to your m2 local repository which doesn't exist if you just remove the quartz from your build path and update your dependencies internally(in eclipse) that would solve the problem
Try to use different/older version of JRE. In my case switching back to JRE7 from JRE8 eliminated the problem.
Delete and Re-Import the project in eclipse (without deleting files of course). Unlike other answers I have not looked into why this happens but it works. poof - compilations errors be-gone
It may help: After upgrading eclipse or changing it or something like, old eclipse specific files (.classpath, .project, and .settings) may not be compatible to the new version of eclipse. So you may have to re generate this eclipse specific files using Maven. So try this in your eclipse project root
mvn eclipse:eclipse
In my case, eclipse starts to show all errors after I changed some versions of dependencies in pom.xml, however the command line mvn clean install build successfully
I deleted folders of the dependencies I changed manually from the .m2 repositories (in my case everything under org.apache.beam), because I also has corrupted dependency issues.
mvn clean build the project, this downloaded the dependencies again
right click project: maven -> update project
delete the project from eclipse (but not from disk) and reimport (this actually left me with 1 error still, then i delete and reimported again)
Go to Eclipse> Project (Menu) > Clean... > Select project to clean
This also removes invalid errors from Eclipse.
For me Right click on the project --> Maven --> Update project with the "Force Update of Snapshots/Releases" checkmarked worked.
Some times, eclipse's validation causing these errors.
You can disable them by going to Menu>window>preferences>validation and uncheck suspend all validators or disable them one by one for builds.
E.G, every time You build the project eclipse does not validate your files and does not show up those errors.
This worked for me
Delete the Eclipse project from Eclipse interface (do not delete
project contents on disk)
Go to the project's root directory in a
file explorer or terminal
Delete these files: .classpath, .project,
and .settings directory
Back to Eclipse, File -> Import... -> Maven
-> Existing Maven projects
Got the same problem, I deleted the project from my workspace (not on disk), opened the project folder and deleted the files .project, .classpath and the folder named .settings.
Now goto eclipse again, import the same project again and viola my error is gone!

Categories