我有一些示例RESTful客户端项目以及我正在研究的RESTful Java Web服务。基本上,不应构建这些项目,而应将其压缩并包含在war文件中,以便在部署war文件时将它们用作静态资源。这样可以轻松地将示例客户端与实际的Java Web服务一起更新,并确保将它们一起部署。
我已经能够使用maven程序集插件来创建一个zip文件,但是该阶段在war阶段之后执行。我无法弄清楚创建zip文件所需的Maven要求,然后将其添加到war文件中。
这是我到目前为止所拥有的,但是仅完成了一半的工作。另外,我需要移动ExampleProject目录,以便解压缩的文件不会进入最终的war文件。
pom.xml
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<descriptor>src/assembly/AssembleExamples.xml</descriptor>
<finalName>examples.zip</finalName>
</configuration>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
AssembleExamples.xml
<assembly xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0 http://maven.apache.org/xsd/assembly-1.1.0.xsd">
<id>bin</id>
<formats>
<format>zip</format>
</formats>
<includeBaseDirectory>false</includeBaseDirectory>
<fileSets>
<fileSet>
<directory>${project.basedir}/WebContent/docs/</directory>
<outputDirectory/>
<includes>
<include>ExampleProject/pom.xml</include>
<include>ExampleProject/src/**</include>
</includes>
</fileSet>
</fileSets>
</assembly>
这是我最终完成此操作的方式。
多亏了Mithun,我才意识到有两种配置war插件的方法,而我这样做的方式不适合我的情况。
这是我添加到pom文件中的内容:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<executions>
<execution>
<configuration>
<descriptor>src/assembly/AssembleJavaExample.xml</descriptor>
<finalName>myexample</finalName>
<appendAssemblyId>false</appendAssemblyId>
<outputDirectory>${project.build.directory}/${project.build.finalName}/docs</outputDirectory>
</configuration>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-war-plugin</artifactId>
<version>2.4</version>
<configuration>
<warSourceDirectory>WebContent</warSourceDirectory>
<failOnMissingWebXml>true</failOnMissingWebXml>
<warName>mywar</warName>
<warSourceExcludes>docs/myexample/**</warSourceExcludes>
</configuration>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>war</goal>
</goals>
</execution>
</executions>
</plugin>
Assembly插件必须先运行,以便在war插件之前执行。Assembly插件将创建zip文件,并将其放置在war插件用于创建war文件的目录中(outputDirectory配置)。然后,我不得不将示例源排除在war文件中(warSourceExcludes配置)。我不确定这是否是最好的方法,但似乎效果很好。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句