Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to build project from maven pom file

Tags:

I have a maven pom file for an open source project. This pom file has all the info like what other jars it depends on etc. I installed maven. Created a dir samprj and copied the pom file into that dir. Cd into that dir and ran mvn command without any arguments but I got bunch of errors. I am absolutely new to maven so I think I am missing something. I tried also from Eclipse ( Import project -- exisitng maven project) but that also does not work except eclipse creates a project that has just that file pom.xml. I expect something that first it will download the jar for the project and then download all dependent jars and config files but nothing there. So given a pom file how do I build the project from it?

like image 737
Alan McCloud Avatar asked Nov 13 '10 14:11

Alan McCloud


People also ask

What is a POM file in a maven project?

A Project Object Model or POM is the fundamental unit of work in Maven. It is an XML file that contains information about the project and configuration details used by Maven to build the project. It contains default values for most projects.

What is a POM file in Maven?

POM stands for Project Object Model. It is fundamental unit of work in Maven. It is an XML file that resides in the base directory of the project as pom.xml. The POM contains information about the project and various configuration detail used by Maven to build the project (s).

How do I build a Java project in Maven?

By default, Maven adds a source file App.java and a test file AppTest.java in its default directory structure, as discussed in the previous chapter. Let's open the command console, go the C:MVNconsumerBanking directory and execute the following mvn command. Maven will start building the project.

Which directory contains the project's project's configuration in Maven?

The src/main/java directory contains the project source code, the src/test/java directory contains the test source, and the pom.xml file is the project's Project Object Model, or POM. The pom.xml file is the core of a project's configuration in Maven.

What is a pom?

Available Variables What is a POM? A Project Object Model or POM is the fundamental unit of work in Maven. It is an XML file that contains information about the project and configuration details used by Maven to build the project.


2 Answers

mvn install should get you going

like image 124
Raghuram Avatar answered Sep 21 '22 15:09

Raghuram


I have a maven pom file for an open source project. This pom file has all the info like what other jars it depends on etc. I installed maven. Created a dir samprj and copied the pom file into that dir ...

It sounds like you only have the project's POM file. This is not sufficient. You need to checkout the complete source tree for the project. Having done that, change directory to the directory containing the POM file and run mvn install.

Also, don't copy the POM to a different directory. Maven expects to find all of the source files relative to the POM file location.

FOLLOW UP

Thanks for advice. I was not able to use the command mvn install as it gave errors.

Probably because you hadn't checked out the source.

I don't know how to check the source tree of the project ...

Use a subversion client (the svn command for example), or one of the Eclipse subversion plugins.

If this was a properly documented project, there would be clear instructions on what version control and build tools you needed, how to checkout the source code and how to build it.

... as I thought POM itself should have this information to automatically checkout if the source is not check out.

It doesn't necessarily, though in this particular case it does.

Anyway I was able use Eclipse to build the project without errors.

(Other readers can read @icyrock.com's answer for links to the m2eclipse plugin and documentation.)

The only problem is the dependent jars were downloaded but hidden deep paths in .m2 repository folder on my linux box.

But I would like these dependent jars to be relative to dir where POM file is.

Sorry, but that is not the way Maven works.

The ~/.m2/repository directory is a fundamental part of Maven. It is not a problem. It is a feature. (Don't fight it!)

like image 43
Stephen C Avatar answered Sep 19 '22 15:09

Stephen C