简体   繁体   中英

How to build project from maven pom file

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?

mvn install应该让你去

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!)

If you want to open this within Eclipse, you need to install m2eclipse:

and then import the project as a Maven project as described here:

Try out their getting started guide. It has a lot of good examples:

http://maven.apache.org/guides/getting-started/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM