简体   繁体   English

从子Maven项目的pom.xml引用父Maven项目的文件

[英]Referencing parent Maven project's files from sub Maven project's pom.xml

I have this file structure in my project: 我的项目中有以下文件结构:

Parent-project 父项目
|--pom.xml | --pom.xml
|--Sub-Project |-子项目
|----pom.xml | ---- pom.xml
|----src/ | ---- src /
|------main/ | ------ main /
|--------java/ | -------- java /
|---------- packages and classes | ---------- 包和类
|--WebFolder/ | --WebFolder /
|----front/ | ---- front /
|------ html pages and JS files | ------ html页面和JS文件

From the Sub-Project's pom.xml, I'd like to include WebFolder as a resource. 在子项目的pom.xml中,我想将WebFolder包括在内。 I want to create a JAR-file using the Sub-Project's pom.xml and I want it to include the WebFolder. 我想使用子项目的pom.xml创建一个JAR文件,并希望它包含WebFolder。

The Sub-Project has a http-server that needs to host the WebFolder. 子项目有一个http服务器,需要托管WebFolder。 From Sub-Project, I can easily reference the path as WebFolder/front to make it point at the web page I want to display, but it needs to be included in the JAR-file as well. 在Sub-Project中,我可以轻松地将路径引用为WebFolder / front ,使其指向要显示的网页,但是它也必须包含在JAR文件中。

The problem I have is with Maven. 我遇到的问题是Maven。 From what I've seen, I should be able to create what I want with resources from Sub-Project's pom.xml like so: 从我所看到的,我应该能够使用Sub-Project的pom.xml中的资源创建想要的内容,如下所示:

<resources>
  <resource>
    <directory>???/WebFolder/</directory>
  </resource>
</resources>

The problem is, I don't know how reference something outside the Sub-Project. 问题是,我不知道如何引用子项目之外的内容。 The directory-tag only seems to reference files inside the Sub-Project. 目录标记似乎仅引用子项目中的文件。 Is there a way to make the directory point at WebFolder? 有没有办法将目录指向WebFolder?

I'm already using maven-assembly-plugin to include all dependencies in a single JAR-file, but since the WebFolder is not related to Maven per-se, I need to include it with other means. 我已经在使用maven-assembly-plugin将所有依赖项包含在单个JAR文件中,但是由于WebFolder与Maven本身无关,因此我需要通过其他方式将其包含在内。

Maven files & directories are relative to the directory of your pom.xml. Maven文件和目录是相对于pom.xml目录的。
In your example, pom.xml of the sub-project can reference its sibling WebFolder directory as: <directory>../WebFolder</directory> 在您的示例中,子项目的pom.xml可以将其同级WebFolder目录引用为: <directory>../WebFolder</directory>

On some cases relative references won't work. 在某些情况下,相对引用将不起作用。 On such cases, you could access the project direcory via ${basedir} 在这种情况下,您可以通过${basedir}访问项目目录

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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