创建不同的 "distributions" 个项目
Creating different "distributions" of an project
我正在(或至少尝试)从 Ant 切换到 Maven。
我正在构建一个复杂的项目,生成一个 WAR 文件,扩展到一个文件夹中。
然后,在 Ant 中我创建了 10 个不同的 "distributions",这意味着我将一些属性文件 CSS 和 HTML 文件从 "config/" 目录复制到文件夹,创建一个并在下一个 "config/" 文件夹中重复该步骤。
最后,我有 10 个 ZIP 文件,其中包含为每个客户定制的资源。
and 代码看起来像这样(可能不是最好的 ant 代码,但工作完美):
<!-- Distributionen -->
<target name="distribution-customer1" depends="jar-with-dependencies">
<property name="dirname" value="customer1" />
<antcall target="distribution">
<param name="dirname" value="${dirname}" />
</antcall>
</target>
<target name="distribution-customer2" depends="jar-with-dependencies">
<property name="dirname" value="customer2" />
<antcall target="distribution">
<param name="dirname" value="${dirname}" />
</antcall>
</target>
<target name="distribution-customer3">
<property name="dirname" value="customer3" />
<antcall target="distribution">
<param name="dirname" value="${dirname}" />
</antcall>
<!-- Startdateien mit Port 8080 statt Port 80 -->
<copy todir="${root.dir}/distribution/${dirname}/" overwrite="yes">
<fileset dir="${root.dir}/configs/${dirname}/" includes="myproject_starten**" />
</copy>
<!-- Nachdem wir Dateien geändert haben, nochmals WAR und ZIP generieren -->
<antcall target="create_war_and_zip">
<param name="dirname" value="${dirname}" />
</antcall>
</target>
<!-- /Distributionen -->
<!-- Über Antcall aufrufen, nicht direkt! -->
<target name="distribution" depends="jar-with-dependencies">
<!-- Altes Verzeichnis löschen -->
<delete dir="${root.dir}/distribution/${dirname}/" />
<!-- Neu anlegen -->
<mkdir dir="${root.dir}/distribution/${dirname}/" />
<!-- Alles vom Template rüber kopieren -->
<copy todir="${root.dir}/distribution/${dirname}/" overwrite="yes">
<fileset dir="${root.dir}/distribution/myproject_template/">
</fileset>
</copy>
<!-- Service.ini mit der Version aus dem individuellen Config-Verzeichnis
überschreiben -->
<copy todir="${root.dir}/distribution/${dirname}" overwrite="yes">
<fileset dir="${root.dir}/configs/${dirname}/">
<include name="*.ini" />
</fileset>
</copy>
<!-- Alte Propertydateien löschen -->
<copy todir="${root.dir}/distribution/${dirname}/myproject/WEB-INF/classes" overwrite="yes">
<fileset dir="${root.dir}/configs/${dirname}/">
<include name="*.properties" />
</fileset>
</copy>
<!-- ggf. Log4J Config überschreiben -->
<copy todir="${root.dir}/distribution/${dirname}/myproject/WEB-INF/classes" overwrite="yes">
<fileset dir="${root.dir}/configs/${dirname}/">
<include name="*.xml" />
</fileset>
</copy>
<!-- Custom CSS kopieren -->
<copy todir="${root.dir}/distribution/${dirname}/myproject/assets/css" overwrite="yes">
<fileset dir="${root.dir}/configs/${dirname}/assets/css/">
<include name="*.css" />
</fileset>
</copy>
<!-- Custom Images kopieren -->
<copy todir="${root.dir}/distribution/${dirname}/myproject/assets/images" overwrite="yes">
<fileset dir="${root.dir}/configs/${dirname}/assets/images/">
<include name="*.png" />
</fileset>
</copy>
<!-- Daten kopieren (Falls vorhanden, für Demo)-->
<copy todir="${root.dir}/distribution/${dirname}/data" overwrite="yes" failonerror="false">
<fileset dir="${root.dir}/configs/${dirname}/data/"></fileset>
</copy>
<copy todir="${root.dir}/distribution/${dirname}/myproject/bilder" overwrite="yes" failonerror="false">
<fileset dir="${root.dir}/configs/${dirname}/bilder/"></fileset>
</copy>
<delete file="${root.dir}/distribution/${dirname}/readme.internal.md" />
<antcall target="create_war_and_zip">
<param name="dirname" value="${dirname}" />
</antcall>
</target>
<target name="copy-to-distribution" depends="jar-with-dependencies">
<delete dir="${root.dir}/distribution/myproject_template/myproject/" />
<mkdir dir="${root.dir}/distribution/myproject_template/myproject/" />
<mkdir dir="${root.dir}/distribution/myproject_template/myproject/bilder" />
<mkdir
dir="${root.dir}/distribution/myproject_template/myproject/bilder/details" />
<mkdir
dir="${root.dir}/distribution/myproject_template/myproject/bilder/originals" />
<mkdir
dir="${root.dir}/distribution/myproject_template/myproject/bilder/thumbnails" />
<copy todir="${root.dir}/distribution/myproject_template/myproject/">
<fileset
dir="${build.dir}/dist/${ant.project.name}-with-dependencies-jar/" />
</copy>
</target>
我怎样才能用 maven 做这样的事情?
我应该使用配置文件吗?
我是否应该使用 Maven 来完成该任务?
欢迎任何帮助!
谢谢,
舒贝
你需要使用war-overlays这里是一个例子:
一个父 pom,将所有子项目放在一起:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.greg</groupId>
<artifactId>war-overlay-example</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>pom</packaging>
<modules>
<module>base-war</module>
<module>dist1-war</module>
</modules>
</project>
该项目的基础war,对于任何常见的东西:
<?xml version="1.0"?>
<project
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.greg</groupId>
<artifactId>war-overlay-example</artifactId>
<version>1.0-SNAPSHOT</version>
</parent>
<artifactId>base-war</artifactId>
<packaging>war</packaging>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<finalName>base-war</finalName>
</build>
</project>
和尽可能多的分布 wars 来改变 base-war 中的任何东西。该项目中包含的任何内容都将替换 base-war 中的任何内容。您可以一无所有并获得完整的基础-war 或插入单个文件。
<?xml version="1.0"?>
<project
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.greg</groupId>
<artifactId>war-overlay-example</artifactId>
<version>1.0-SNAPSHOT</version>
</parent>
<artifactId>dist1-war</artifactId>
<packaging>war</packaging>
<dependencies>
<dependency>
<groupId>com.greg</groupId>
<artifactId>base-war</artifactId>
<version>${project.version}</version>
<type>war</type>
<scope>runtime</scope>
</dependency>
</dependencies>
<build>
<finalName>dist1-war</finalName>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.1.1</version>
<configuration>
<failOnMissingWebXml>false</failOnMissingWebXml>
<overlays>
<overlay>
<groupId>com.greg</groupId>
<artifactId>base-war</artifactId>
</overlay>
</overlays>
</configuration>
</plugin>
</plugins>
</build>
</project>
工作示例here
我正在(或至少尝试)从 Ant 切换到 Maven。 我正在构建一个复杂的项目,生成一个 WAR 文件,扩展到一个文件夹中。
然后,在 Ant 中我创建了 10 个不同的 "distributions",这意味着我将一些属性文件 CSS 和 HTML 文件从 "config/" 目录复制到文件夹,创建一个并在下一个 "config/" 文件夹中重复该步骤。
最后,我有 10 个 ZIP 文件,其中包含为每个客户定制的资源。
and 代码看起来像这样(可能不是最好的 ant 代码,但工作完美):
<!-- Distributionen -->
<target name="distribution-customer1" depends="jar-with-dependencies">
<property name="dirname" value="customer1" />
<antcall target="distribution">
<param name="dirname" value="${dirname}" />
</antcall>
</target>
<target name="distribution-customer2" depends="jar-with-dependencies">
<property name="dirname" value="customer2" />
<antcall target="distribution">
<param name="dirname" value="${dirname}" />
</antcall>
</target>
<target name="distribution-customer3">
<property name="dirname" value="customer3" />
<antcall target="distribution">
<param name="dirname" value="${dirname}" />
</antcall>
<!-- Startdateien mit Port 8080 statt Port 80 -->
<copy todir="${root.dir}/distribution/${dirname}/" overwrite="yes">
<fileset dir="${root.dir}/configs/${dirname}/" includes="myproject_starten**" />
</copy>
<!-- Nachdem wir Dateien geändert haben, nochmals WAR und ZIP generieren -->
<antcall target="create_war_and_zip">
<param name="dirname" value="${dirname}" />
</antcall>
</target>
<!-- /Distributionen -->
<!-- Über Antcall aufrufen, nicht direkt! -->
<target name="distribution" depends="jar-with-dependencies">
<!-- Altes Verzeichnis löschen -->
<delete dir="${root.dir}/distribution/${dirname}/" />
<!-- Neu anlegen -->
<mkdir dir="${root.dir}/distribution/${dirname}/" />
<!-- Alles vom Template rüber kopieren -->
<copy todir="${root.dir}/distribution/${dirname}/" overwrite="yes">
<fileset dir="${root.dir}/distribution/myproject_template/">
</fileset>
</copy>
<!-- Service.ini mit der Version aus dem individuellen Config-Verzeichnis
überschreiben -->
<copy todir="${root.dir}/distribution/${dirname}" overwrite="yes">
<fileset dir="${root.dir}/configs/${dirname}/">
<include name="*.ini" />
</fileset>
</copy>
<!-- Alte Propertydateien löschen -->
<copy todir="${root.dir}/distribution/${dirname}/myproject/WEB-INF/classes" overwrite="yes">
<fileset dir="${root.dir}/configs/${dirname}/">
<include name="*.properties" />
</fileset>
</copy>
<!-- ggf. Log4J Config überschreiben -->
<copy todir="${root.dir}/distribution/${dirname}/myproject/WEB-INF/classes" overwrite="yes">
<fileset dir="${root.dir}/configs/${dirname}/">
<include name="*.xml" />
</fileset>
</copy>
<!-- Custom CSS kopieren -->
<copy todir="${root.dir}/distribution/${dirname}/myproject/assets/css" overwrite="yes">
<fileset dir="${root.dir}/configs/${dirname}/assets/css/">
<include name="*.css" />
</fileset>
</copy>
<!-- Custom Images kopieren -->
<copy todir="${root.dir}/distribution/${dirname}/myproject/assets/images" overwrite="yes">
<fileset dir="${root.dir}/configs/${dirname}/assets/images/">
<include name="*.png" />
</fileset>
</copy>
<!-- Daten kopieren (Falls vorhanden, für Demo)-->
<copy todir="${root.dir}/distribution/${dirname}/data" overwrite="yes" failonerror="false">
<fileset dir="${root.dir}/configs/${dirname}/data/"></fileset>
</copy>
<copy todir="${root.dir}/distribution/${dirname}/myproject/bilder" overwrite="yes" failonerror="false">
<fileset dir="${root.dir}/configs/${dirname}/bilder/"></fileset>
</copy>
<delete file="${root.dir}/distribution/${dirname}/readme.internal.md" />
<antcall target="create_war_and_zip">
<param name="dirname" value="${dirname}" />
</antcall>
</target>
<target name="copy-to-distribution" depends="jar-with-dependencies">
<delete dir="${root.dir}/distribution/myproject_template/myproject/" />
<mkdir dir="${root.dir}/distribution/myproject_template/myproject/" />
<mkdir dir="${root.dir}/distribution/myproject_template/myproject/bilder" />
<mkdir
dir="${root.dir}/distribution/myproject_template/myproject/bilder/details" />
<mkdir
dir="${root.dir}/distribution/myproject_template/myproject/bilder/originals" />
<mkdir
dir="${root.dir}/distribution/myproject_template/myproject/bilder/thumbnails" />
<copy todir="${root.dir}/distribution/myproject_template/myproject/">
<fileset
dir="${build.dir}/dist/${ant.project.name}-with-dependencies-jar/" />
</copy>
</target>
我怎样才能用 maven 做这样的事情? 我应该使用配置文件吗? 我是否应该使用 Maven 来完成该任务?
欢迎任何帮助!
谢谢, 舒贝
你需要使用war-overlays这里是一个例子:
一个父 pom,将所有子项目放在一起:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.greg</groupId>
<artifactId>war-overlay-example</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>pom</packaging>
<modules>
<module>base-war</module>
<module>dist1-war</module>
</modules>
</project>
该项目的基础war,对于任何常见的东西:
<?xml version="1.0"?>
<project
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.greg</groupId>
<artifactId>war-overlay-example</artifactId>
<version>1.0-SNAPSHOT</version>
</parent>
<artifactId>base-war</artifactId>
<packaging>war</packaging>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<finalName>base-war</finalName>
</build>
</project>
和尽可能多的分布 wars 来改变 base-war 中的任何东西。该项目中包含的任何内容都将替换 base-war 中的任何内容。您可以一无所有并获得完整的基础-war 或插入单个文件。
<?xml version="1.0"?>
<project
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.greg</groupId>
<artifactId>war-overlay-example</artifactId>
<version>1.0-SNAPSHOT</version>
</parent>
<artifactId>dist1-war</artifactId>
<packaging>war</packaging>
<dependencies>
<dependency>
<groupId>com.greg</groupId>
<artifactId>base-war</artifactId>
<version>${project.version}</version>
<type>war</type>
<scope>runtime</scope>
</dependency>
</dependencies>
<build>
<finalName>dist1-war</finalName>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.1.1</version>
<configuration>
<failOnMissingWebXml>false</failOnMissingWebXml>
<overlays>
<overlay>
<groupId>com.greg</groupId>
<artifactId>base-war</artifactId>
</overlay>
</overlays>
</configuration>
</plugin>
</plugins>
</build>
</project>
工作示例here