在Maven模块之间共享静态资源 [英] Sharing static resources between maven modules

查看:148
本文介绍了在Maven模块之间共享静态资源的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Maven项目,其中有一个parent-pom项目和3个maven-module项目.其中两个模块是可编译为WAR文件的Java-EE Web应用程序.其中的1个模块包含通用的JAVA代码,该代码在其他2个项目之间共享.共享JAVA代码很容易.

I have a Maven project with a parent-pom project and 3 maven-module projects in it. 2 of the modules are Java-EE web apps that compile into WAR files. 1 of the modules contains common JAVA code which is shared between the 2 other projects. Sharing the JAVA code was easy.

我的问题是如何共享常见的静态资源(例如JavaScript,CSS和图像文件),而不必在每个Web模块中复制它们?我还希望通过这种方式来继续从Eclipse运行Web应用程序,并对自动运行的Eclipse服务器自动使用的静态文件进行更改.

The question I have is how to a share common static resources such as JavaScript, CSS, and image files without duplicating them in each web module? I would also like to do it in such a way that I can continue running the web app from Eclipse and have changes I make to the static-files automatically available to the Eclipse's running server.

推荐答案

尝试一下:

1.

 |-- pom.xml
    |-- appsweb1 (war)
    |-- appsweb2 (war)
    |-- common (jar)
        |-- src/main/java
        |-- src/static_files
        |-- pom.xml

  1. 添加pom appsweb1,appsweb2,或将其添加到pom父级,然后在子级中添加groupId,artifactId:

<plugins>
    <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-resources-plugin</artifactId>
        <version>2.4.2</version>
        <executions>
            <execution>
                <id>default-copy-resources</id>
                <phase>process-resources</phase>
                <goals>
                    <goal>copy-resources</goal>
                </goals>
                <configuration>
                    <overwrite>false</overwrite>
                    <outputDirectory>${project.build.directory}/${project.artifactId}-${project.version}/WEB-INF/static_files</outputDirectory>
                    <resources>
                        <resource>
                            <directory>../common/src/main/static_files</directory>
                        </resource>
                    </resources>
                </configuration>
            </execution>
        </executions>
    </plugin>
</plugins>

有关Maven资源插件的文档: https://maven.apache.org/plugins/maven-resources-plugin/

Documentation on the Maven Resources Plugin: https://maven.apache.org/plugins/maven-resources-plugin/

这篇关于在Maven模块之间共享静态资源的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆