创建项目的不同“分布”

我正在(或至少尝试)从 Ant 切换到 Maven。我正在构建一个复杂的项目,生成一个 WAR 文件,并扩展到一个文件夹中。


然后,在 Ant 中,我创建了 10 个不同的“分布”,这意味着我将一些属性文件、CSS 和 HTML 文件从“config/”目录复制到该文件夹中,创建一个并在下一个“config/”文件夹中重复该步骤.


最后,我有 10 个 ZIP 文件,为每个客户定制了资源。


和代码看起来像这样(可能不是最好的蚂蚁代码,但效果很好):


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


我怎么能用 maven 做这样的事情?我应该使用配置文件吗?我什至应该使用 maven 来完成这项任务吗?


慕森卡
浏览 136回答 1
1回答

牧羊人nacy

您需要在此处使用战争叠加层,这是一个示例:父 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">&nbsp; <modelVersion>4.0.0</modelVersion>&nbsp; <groupId>com.greg</groupId>&nbsp; <artifactId>war-overlay-example</artifactId>&nbsp; <version>1.0-SNAPSHOT</version>&nbsp; <packaging>pom</packaging>&nbsp; <modules>&nbsp; &nbsp; <module>base-war</module>&nbsp; &nbsp; <module>dist1-war</module>&nbsp; </modules></project>对于任何常见的东西,该项目的基础战争:<?xml version="1.0"?><project&nbsp; &nbsp; xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"&nbsp; &nbsp; xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">&nbsp; &nbsp; <modelVersion>4.0.0</modelVersion>&nbsp; &nbsp; <parent>&nbsp; &nbsp; &nbsp; &nbsp; <groupId>com.greg</groupId>&nbsp; &nbsp; &nbsp; &nbsp; <artifactId>war-overlay-example</artifactId>&nbsp; &nbsp; &nbsp; &nbsp; <version>1.0-SNAPSHOT</version>&nbsp; &nbsp; </parent>&nbsp; &nbsp; <artifactId>base-war</artifactId>&nbsp; &nbsp; <packaging>war</packaging>&nbsp; &nbsp; <dependencies>&nbsp; &nbsp; &nbsp; &nbsp; <dependency>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <groupId>junit</groupId>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <artifactId>junit</artifactId>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <version>3.8.1</version>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <scope>test</scope>&nbsp; &nbsp; &nbsp; &nbsp; </dependency>&nbsp; &nbsp; </dependencies>&nbsp; &nbsp; <build>&nbsp; &nbsp; &nbsp; &nbsp; <finalName>base-war</finalName>&nbsp; &nbsp; </build></project>和许多分销战争改变基地战争中的任何事情。此项目中包含的任何内容都将替换基础战争中的任何内容。您可以一无所有并获得完整的基础战争或插入单个文件。<?xml version="1.0"?><project&nbsp; &nbsp; xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"&nbsp; &nbsp; xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">&nbsp; &nbsp; <modelVersion>4.0.0</modelVersion>&nbsp; &nbsp; <parent>&nbsp; &nbsp; &nbsp; &nbsp; <groupId>com.greg</groupId>&nbsp; &nbsp; &nbsp; &nbsp; <artifactId>war-overlay-example</artifactId>&nbsp; &nbsp; &nbsp; &nbsp; <version>1.0-SNAPSHOT</version>&nbsp; &nbsp; </parent>&nbsp; &nbsp; <artifactId>dist1-war</artifactId>&nbsp; &nbsp; <packaging>war</packaging>&nbsp; &nbsp; <dependencies>&nbsp; &nbsp; &nbsp; &nbsp; <dependency>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <groupId>com.greg</groupId>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <artifactId>base-war</artifactId>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <version>${project.version}</version>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <type>war</type>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <scope>runtime</scope>&nbsp; &nbsp; &nbsp; &nbsp; </dependency>&nbsp; &nbsp; </dependencies>&nbsp; &nbsp; <build>&nbsp; &nbsp; &nbsp; &nbsp; <finalName>dist1-war</finalName>&nbsp; &nbsp; &nbsp; &nbsp; <plugins>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <plugin>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <groupId>org.apache.maven.plugins</groupId>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <artifactId>maven-war-plugin</artifactId>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <version>2.1.1</version>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <configuration>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <failOnMissingWebXml>false</failOnMissingWebXml>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <overlays>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <overlay>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <groupId>com.greg</groupId>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <artifactId>base-war</artifactId>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </overlay>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </overlays>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </configuration>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </plugin>&nbsp; &nbsp; &nbsp; &nbsp; </plugins>&nbsp; &nbsp; </build></project>这里的工作示例
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Java