开发者

How to build project from maven pom file

开发者 https://www.devze.com 2023-01-25 10:58 出处:网络
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

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 should get you going


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:

  • http://www.eclipse.org/m2e/

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

  • http://books.sonatype.com/m2eclipse-book/reference/creating-sect-importing-projects.html


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

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

0

精彩评论

暂无评论...
验证码 换一张
取 消