简体   繁体   中英

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
|--Sub-Project
|----pom.xml
|----src/
|------main/
|--------java/
|---------- packages and classes
|--WebFolder/
|----front/
|------ html pages and JS files

From the Sub-Project's pom.xml, I'd like to include WebFolder as a resource. I want to create a JAR-file using the Sub-Project's pom.xml and I want it to include the WebFolder.

The Sub-Project has a http-server that needs to host the 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.

The problem I have is with 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:

<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?

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 files & directories are relative to the directory of your pom.xml.
In your example, pom.xml of the sub-project can reference its sibling WebFolder directory as: <directory>../WebFolder</directory>

On some cases relative references won't work. On such cases, you could access the project direcory via ${basedir}

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