Converting SVN project to maven project in Eclipse - java

I have downloaded a project (Maven based structure) from our SVN repository using Eclipse SVN plugin. Initially, Eclipse wasn't recognizing it as java project so I had to follow the following steps:
http://www.javaexperience.com/how-to-convert-svn-project-to-regular-eclipse-java-project/
The above steps worked well and the project was converted to java project.
Next I right clicked on the project and selected maven->Convert to maven project. Eclipse downloaded some jars and added it to the class path but not all files seem to have been downloaded successfully as I see Junit jar file missing error (where as junit is mentioned in pom.xml)
When I right click on the pom.xml file, I don't see the option "mvn install" or "mvn clean". I am using Eclipse Kepler which comes with maven plugin out of the box.

You will find the Maven commands in 'Run As', not in 'Maven'

I would first create a maven project using create maven project menu then add the SVN based source code to it.

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

build error after importing maven projects

I cloned one of the open source git repositories and was trying to import it as maven project in eclipse. After I imported everything as a maven project, whole package is getting messed up. See the below error:
How can I fix this issue so that I can build it on my local box? I cloned the same git repository locally on my desktop.
I am using eclipse version:
Eclipse IDE for Java Developers
Version: Luna Service Release 1a (4.4.1)
Build id: 20150109-0600
Steps I have tried already:
I have already tried maven->update project.
I have also tried removing and adding it again.
I tried mvn clean install both on command line and eclipse, they are successful as well.
Can anyone help me with this? If needed, you can also clone it and try importing it to see whether it works for you or not.
The root of your problem is that the build section of the pom.xml for that project specifies:
<sourceDirectory>./src</sourceDirectory>
Eclipse uses the sourceDirectory tag to tell it where the root of the main sources are. If you change that to ./src/main/java, then right-click on the project > Maven > Update Project... and click Ok (I had to do this twice) it will fix the Eclipse classpath so Eclipse can build the project. You can then revert the pom back to the head revision and so long as you don't run Update Project again it should continue to build.
I'm unclear on why that project specifies a non-standard source directory but uses the standard Maven layout, but this should at least get you into a working state within Eclipse.

Errors after building project using maven

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

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.

How to run a downloaded Java and Maven Project

I'm new in Maven,Java and Eclipse. I just download a project that uses Maven. I want to know how can import and run this project by Eclipse. I install m2eclipse and work with it but i don't know how can I import a existing project.
You need a maven plugin for Eclipse. m2eclipse or Apache Maven Plugin
This links will help you to import the project. M2eclipse Guideline and Importing maven project into eclipse
Use the Maven Eclipse Plugin. It generates the necessary files for the Eclipse IDE.
For running maven project you will need to install maven plugin in eclipse and than right click on it and select run as maven install
Here is an alternate way without using m2Eclipse plugin.
Install Maven and add the bat file to the path. Once this is done open a command prompt and go to the directory where the pom.xml file of your project exists. At this directory level do a:
mvn eclipse:eclipse
This will make your project Eclipse friendly. Once this is completed, import the project by using File Menu in Eclipse. File->Import. In dialog select Existng Projects into Workspace. Click Next. Then select the root directory as the directory from which you ran the mvn command. Click Finish.
You project should now be in your Eclipse IDE

Categories

Resources