开发者

In Maven, can I specify a relative path above my current project?

开发者 https://www.devze.com 2022-12-18 07:57 出处:网络
I\'m learning maven on the fly while doing work on a project with a large set of projects to build. Currently a line in the main build uses an absolute path to specify a directory that is part of the

I'm learning maven on the fly while doing work on a project with a large set of projects to build.

Currently a line in the main build uses an absolute path to specify a directory that is part of the subversion repository but "above" it's directory.

as in: "C:/work/project/eclipse" where "project" is the checked-in directory, and the pom.xml is in "C:/work/project/src/subproject/pom.xml"

I'd like to m开发者_JAVA技巧ake that line a relative address instead.

I tried specifying "../../Eclipse....", put that didn't seem to work.

It could also be because that same variable is being used by a sub-sub-project's pom file.

Any advice (aside from rewrite the whole mess, which I just don't know enough about maven to do yet)?


With Maven, things are relative to the directory containing the pom.xml (which is represented by the ${basedir} property and is called the base directory). There are however some situations where you could have to specify a relative path:

  • if a <parent> pom is not directly above a given module using a <relativePath> element (see this example)
  • if modules are not nested (i.e. if you use a flat layout) using a relative path in the various <module> elements (like in this example).

Having all that said, I'm not sure to understand what your situation exactly is or what you are describing.

Maybe you should show the relevant parts of your POM if this is possible.


Ideally the pom.xml should be in the same directory as your src directory. For eg suppose you have checked out your project from svn into a folder C:/work/project, then keep the main pom.xml in C:/work/project. src should also be in C:/work/project.

Your other subprojects should be in C:/work/subproject1, C:/work/subproject2 and so on each having their own pom.xml. Then in the main pom.xml you can refer to the other projects in the

<modules>      
    <module>../subproject1<module>
    <module>../subproject2<module>
</modules>
0

精彩评论

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