How to run a downloaded Java and Maven Project - java

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

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

Converting SVN project to maven project in Eclipse

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.

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.

importing a whole project into Maven (Eclipse Juno)

I have a folder that contains some Java code, written specifically for Linux.
There is a pom.xml file and two folders called: src and build
I have installed Eclipse Juno on my Mac (10.7.5) and I understand it already has Maven included. On the Linux machine, the code is executed by entering mvn package at the command line.
But after this stage, during the execution of the build artifact, it doesn't run on my Mac, because some of the commands are specific to Linux (I am told).
How do I import the whole project into Maven on my Mac? I mean where do I copy the folders and pom file?
Thank you,
H
You can leave the maven project where it is. Go to
File->import->Maven->Existing Maven Projects->Root directory
and select the maven project dir.
If you cannot see Maven in Import menu it means you need to add maven plugin (m2e) to your Juno. The fact that mvn runs from command line means only that maven is installed on your PC.
Complementing Evgeniy Dorofeev's answer:
If your project is in a GIT repository and you use eGit, you might want to import it like this:
File->Import->Git->Projects from Git
After the import you can convert your project to a Maven project and it will update the project settings.

Build Netbeans project using Maven commands

How can I build a Netbeans project by using pom.xml?
In Eclipse I have to use following commands to do that:
mvn install
then
mvn eclipse:eclipse
What are similar commands to build projects in Netbeans?
I think your question is: "How to import a Maven based project into NetBeans for development?"
If so, than see NetBeans wiki. You should just install the Maven plugin and import the project from pom.xml.
P.S. The mvn eclipse:eclipse is a bit deprecated. Check out the m2eclipse.
Import Maven project in Netbeans. Netbeans itself will build your web project.
Netbeans 7 can open Maven projects automatically. In Netbeans just File->Open Project and point to the dir with your pom.xml in it.

Categories

Resources