5

是否有能力构建只包含资源但不包含源并且可以被其他项目重用的 Maven 工件?

动机如下。我有一个只包含 html/css/javascript 代码的库。这个库必须作为资源打包到战争项目中。至于现在,我通过单个 pom 使用资源构建 Web 存档。但是我是否能够将 html/css/javascript 代码分离成新的工件并在几个战争项目中重用它?

4

5 回答 5

9

使用 Maven覆盖。有关更多示例,请参阅操作 WAR 覆盖

于 2010-02-25T23:11:21.470 回答
1

您可以使用Maven 程序集插件来完成。

于 2010-02-25T20:23:22.557 回答
0

我不认为 maven 会阻止您将一些资源混在一起,并将其作为依赖项添加到您的 Web 项目中。

但是,您需要引用资源的方式会有点奇怪。我不习惯将 css 样式表作为 java 资源加载到 WEB-INF/lib 中的 jar 文件中。

我想将它们称为普通 Web 资源,相对于 WAR 文件的根目录,而不是通过类加载器。

于 2010-02-25T20:28:12.660 回答
0

这是一个非常简单的测试:

$ ls -R
.:
pom.xml  src

./src:
main

./src/main:
resources

./src/main/resources:
README.txt  content-is-here.txt

$ mvn package
... Maven doing it's thing...

$ unzip -l target/test-1.0-SNAPSHOT.jar
Archive:  target/test-1.0-SNAPSHOT.jar
  Length      Date    Time    Name
---------  ---------- -----   ----
        0  02-25-2010 16:18   META-INF/
      123  02-25-2010 16:18   META-INF/MANIFEST.MF
       10  02-25-2010 16:18   content-is-here.txt
        0  02-25-2010 16:18   README.txt
        0  02-25-2010 16:18   META-INF/maven/
        0  02-25-2010 16:18   META-INF/maven/group/
        0  02-25-2010 16:18   META-INF/maven/group/test/
      626  02-25-2010 16:15   META-INF/maven/group/test/pom.xml
      106  02-25-2010 16:18   META-INF/maven/group/test/pom.properties
---------                     -------
      865                     9 files
于 2010-02-25T21:24:27.787 回答
0

例如,这可以通过 jarring 资源工件并将其解压缩到 war 项目中的 src/main/resources 中validate来完成。资源 pom 是微不足道的,但战争 pom 将包含以下内容:

 <plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-dependency-plugin</artifactId>
    <executions>
       <execution>
          <id>unpack</id>
          <phase>validate</phase>
          <goals>
             <goal>unpack</goal>
          </goals>
          <configuration>
             <artifactItems>
                <artifactItem>
                   <groupId>my.company</groupId>
                   <artifactId>resource-artifact</artifactId>
                   <version>1.0</version>
                   <overWrite>true</overWrite>
                   <outputDirectory>src/main/resources</outputDirectory>
                </artifactItem>
             </artifactItems>
          </configuration>
       </execution>
    </executions>
 </plugin>
于 2010-02-25T23:10:27.880 回答