Eclipse+maven多环境,每个环境多配置打包

    公司现在项目都是用的ant脚本打的war包,不过经理觉得现在都是用的maven,或者是gradle会更好,ant那个东西太古董了,
    让我考虑下业余时间给项目搞成maven打包的,于是我在完成后就写了这篇博客。

    环境:Eclipse+maven+jdk1.6
    状态:项目各个环境的配置文件有多个不同,而且还在不同的路径下。

    思路:profile建立环境分支,exclude删除不需要的配置,plugin将指定profile环境的配置文件copy至各个路径下
<profiles>
        <profile> 
            <id>testid>
            <properties>
                <profiles.active>testprofiles.active>
            properties>
        profile>
        <profile> 
            <id>proid>
            <properties>
                <profiles.active>proprofiles.active>
            properties>
        profile>
    profiles>

    <build>
        <resources>
            <resource>
                <directory>src/main/resourcesdirectory>
                <filtering>truefiltering>
                <excludes>
                
                    <exclude>test/**/*.*exclude>
                    <exclude>pro/**/*.*exclude>
                    <exclude>META-INF/*.propertiesexclude>
                    <exclude>appcontext-dubbo-provider.xmlexclude>
                    <exclude>freemarker.propertiesexclude>
                    <exclude>log4j.propertiesexclude>
                excludes>
            resource>

        resources>
        <testResources>
            <testResource>
                <directory>src/test/javadirectory>
                <excludes>
                    <exclude>**/*.javaexclude>
                excludes>
            testResource>
        testResources>

        <plugins>

                        
            <plugin>
                <artifactId>maven-resources-pluginartifactId>
                <version>2.5version>
                <executions>
                    <execution>
                        <id>copy-resourcesid>
                        <phase>validatephase>
                        <goals>
                            <goal>copy-resourcesgoal>
                        goals>
                        <configuration>
                            <outputDirectory>target/classesoutputDirectory>
                            <resources>
                                <resource>
                                    <directory>src/main/resources/${profiles.active}/classesdirectory>
                                    <includes>
                                        <include>*.propertiesinclude>
                                        <include>*.xmlinclude>
                                        <include>META-INF/*.*include>
                                    includes>
                                    <filtering>truefiltering>
                                resource>
                            resources>
                        configuration>
                    execution>
                executions>
            plugin>

            <plugin>
                <artifactId>maven-war-pluginartifactId>
                <version>2.6version>
                <configuration>
                    <warSourceDirectory>WebContentwarSourceDirectory>
                configuration>
            plugin>
            <plugin>
                <artifactId>maven-compiler-pluginartifactId>
                
                <configuration>
                    <source>1.6source>
                    <target>1.6target>
                configuration>
            plugin>
        plugins>
    build>
    上面是pom详细配置,然后是具体的文件夹目录结构

Eclipse+maven多环境,每个环境多配置打包_第1张图片

    截图中环境有test和pro两个,如果打test环境,则要将test/classes文件下的*.xml和*.properties复制到
    src/main/resources下, test/classes/META-INF下的*.properties复制到src/main/resources/META-INF下,还要将这两个文件夹及其子文件全部删除

你可能感兴趣的:(项目设计)