Errors after building project using maven - java

I followed the following tutorial (https://github.com/kolorobot/spring-mvc-quickstart-archetype) and imported the project to eclipse.
However, i am getting the following errors in my pom.xml file, and also in all the java classes.
I have attached the screenshot.
POM.xml
Java classes
I have updated my Post
PROBEM VIEW

In the eclipse buildpath, make sure you have the maven dependency jars downloaded under "Maven Dependencies"
If you dont see, run the below command to download the same.
mvn clean dependency:copy-dependencies package
This may sound silly, but in my experience I have seen this working. Do a Project Clean in eclipse and do a maven build

There is no Maven dependencies classfolder in your screenshot. Have you tried right-clicking the project name -> Maven -> Update Project?
Update Unbound classpath var.M2_REPO
You need to fix your Maven installation. Go to Window -> Preferences -> Maven and have a look at: Installations and UserSettings

Related

Maven dependencies not visible under Build path in Eclipse Luna

I'm using Eclipse Luna for my project. I've imported a Maven project into it. Right click->import->import existing maven projects. I made mvn clean package install under run configurations. It ran successfully till mid of project, and in the sub modules, it got failed due to some issue in Java file. But whatever the JAR's that have been fetched should be displayed under Maven dependencies under Build path right?
Here is the screenshot
Do I require to make any steps here?
Right click the project and Configure as Maven project

Eclipse maven build does not install dependencies

I'm working in eclipse on a java / javascript project, we're using maven to manage our project dependencies, I ran into a issue with maven build (clean install) does not install the dependencies that I specified in the POM.xml file, I tried everything I can find on the internet the whole day today, still no luck, I'll be really appreciate if anyone could kindly take a look at, thank you :)
I got a reuse lib project (lib) and a working project (project), the project should be installing the lib during the maven build, So, here's more detail information on what exactly I did:
I ran maven clean on the lib, then ran maven package, the lib-1.0.0-SNAPSHOT.jar file was generated successfully.
then in the working project POM.xml file, I added the dependency declaration.
I right clicked the working project, maven -> update maven project, where I checked the 'force update of snapshots / releases' checkbox, then -> ok
I right clicked the working project, run as -> maven build (with clean install, and also I checked on the 'Update Snapshots' checkbox) -> apply -> run
In the console, I saw the reuse lib was downloading and then downloaded, but it's never got installed (there should be a line says installing reuse lib...), as the result of it, the reuse lib will not be loaded after I ran my working project, it drives me insane -_-!..
Only your maven projects build output can be installed (in the local repository with mvn install, resp. mvn clean install). During the build it will resolve the dependencies (and the transitive dependencies) to be downloaded and packed to your delivery. Those dependencies of your project will implicitly also be "installed" in your local repository since you will see them in your local repository after the download happened - Maven will however not see that as a install in the meaning of install of the default lifecycle.
To install your "reuse lib"-Maven project you will have to run mvn install or mvn clean install on that project's pom rather than on a project which "just uses it as dependency".

Maven missing classes

I created a basic maven project in eclipse and I'm getting errors in my pom.xml that classes are missing, I checked the folder that it was looking in and the file paths don't match what I have and the classes don't exist.. My path goes up to: C:\Users\user.m2\repository\org\apache\maven\shared and it is stating there is a /filtering/ folder which I don't have. I have the latest maven and m2eclipse installed.
Most probably a bad installations (incomplete download or missing jars). I suggest you delete the
C:\Users\user.m2\
folder completely and run mvn clean install again. Maven will fetch the jars for you. Also try to refresh the maven project from within eclipse. Right click on project -> maven -> update project. Sometimes eclipse has this issue.

How to use Maven dependencies in eclipse auto import

I have a new maven project in eclipse and all maven stages work fine.
Problem comes when I write code.
I want classes in my dependencies to be available when I use organize imports.
On pressing Ctrl+Shift+O, eclipse does not use maven dependencies and I need to
manually type imports: this shows errors due to java builder
wait for maven build to compile
Can I not use eclipse java editor like I Used to with a simple java project which has some jars on classpath?
If so, how?
I hope there is a simple solution.
I don't want to spend more spend time mavenizing then writing code.
Use the Maven Eclipse plugin and tell it to download sources and javadocs for you or you can use M2eclipse(which automagically recognizes maven projects.)
use mvn eclipse:eclipse thanks to #Abdullah Shaikh
else
Window -> Preferences -> Java -> Code Style -> Organize Imports.(check
what your ctrl + shift +O do.?)
To convert a maven java project to support Eclipse, you can use below command to generate configuration files
mvn eclipse:eclipse
Run this command from the directory containing the pom.xml
In your case it will build classpath having all the dependencies mentioned in your pom
More details here maven eclipse plugin
mvn eclipse:eclipse
But don't forget to change the directory to your maven project first (command cd)
Then reboot Eclipse
Than go to Eclipse Explorer - right click on your file with import errors - Source -
organize imports (or Ctrl-Shift-O)

What do I do with the pom.xml file?

I have just downloaded a project from github, it has a pom.xml and is missing many dependencies.
I installed m2e Maven integration in Eclipse plugin but now what do I do? It's installed and seems to be working but how do I download the dependencies now?
You checkout the git files to a location different from your Eclipse workspace.
Start Eclipse on a clean workspace and install m2e. (I usually install m2e-wtp to get web projects)
Use File -> Import -> Existing Maven projects.
Point to the pom.xml you want to use in the files checked out above.
Wait while Eclipse downloads half the Internet.
Ready.
Right click on your project, run as -> maven install.
If you can't see these, you either incorrectly installed m2e, or you need to import the project as a maven project.
In that case, delete the project from your workspace (do not check the "delete contents on disk"). Right click in the project explorer and click on import... From that dialog, you can select existing maven projects, where you need to navigate to the highest directory containing a pom.xml file.
Also, if you have maven installed on your computer (not m2e in eclipse), you can open the directory that contains the pom.xml and just type mvn clean install. This will build your project.
If you get a "Build success" message, you'll know that the dependencies have been fetched correctly.
In eclipse, You have to convert your project to a maven project. right click on your project -> maven (or configure) -> convert to maven project (or enable dependencies management).
This should update your dependencies automatically, if it is not the case then right click your project -> maven -> update project (or update dependencies, it depends on the verion of m2e you are using).
It should be enough to build the project. The dependencies should be downloaded during the build.
Pom.xml files are used for Maven projects.
Depending on your Eclipse version, maybe it's not compatible with Maven out of the box. If not, you can install a Maven plugin (like m2e) so that the project can be viewed as a Maven project.
Maven will do the dependency management (if pom.xml file is configured properly)
When you right click on your project->Run As-> Maven install it will download all the dependencies that it does not have already in your local repository.

Categories

Resources