<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    MAVEN:如何為開發和生產環境建立不同的配置文件 --我的簡潔方案

    其實也是最近才看Maven, 以前都是用ant+ivy, 對于輕量級的項目來說足夠了, 而且非常靈活.

    看了看Maven, 約定.... 現在編程都說約定, 約定是挺好, 問題是超出約定的事情太多了, 到頭來還要依賴其他東西, 真不想用maven啊.

    以前我們開發環境和生產環境的配置文件都是單獨分開目錄存放的, ant腳本搞個變量就自動打包不同的文件了. 我覺得管理起來也很容易, 所以看到很多maven為解決開發/生產環境的方案真是不太理解啊:
      1. 什么 ${your.configuration}, 和spring的東西都差不多了, 配置寫到腳本里去了,....這叫啥配置...
      2. 調用ant....

    還是根據我以前的思路:

     src/main目錄下原來有 java, resources, 我新建幾個目錄: resources-dev, resources-test, resources-prod.

    resources --- 一些共享的配置文件, 一般不需要修改的
    resources-dev --- 開發環境下用的配置文件, 和resources目錄下文件沒有重合.
    resources-prod --- 生產環境下用的配置文件, 和resources目錄下文件沒有重合.


    本機開發的時候設置源碼目錄為 java, resources, resources-dev, 可以直接開發調試.

    編譯的時候希望maven根據不同環境, 打包不同的目錄下的文件, 我們利用maven的profile和build-helper-maven-plugin插件就可以實現.

        <profiles>
            
    <profile>
                
    <id>dev</id>
                
    <build>
                    
    <plugins>
                        
    <plugin>
                            
    <groupId>org.codehaus.mojo</groupId>
                            
    <artifactId>build-helper-maven-plugin</artifactId>
                            
    <version>1.5</version>
                            
    <executions>
                                
    <execution>
                                    
    <id>add-resource</id>
                                    
    <phase>generate-resources</phase>
                                    
    <goals>
                                        
    <goal>add-resource</goal>
                                    
    </goals>
                                    
    <configuration>
                                        
    <resources>
                                            
    <resource>
                                                
    <directory>src/main/resources_dev</directory>
                                            
    </resource>
                                        
    </resources>
                                    
    </configuration>
                                
    </execution>
                            
    </executions>
                        
    </plugin>
                        
    <plugin>
                            
    <artifactId>maven-war-plugin</artifactId>
                            
    <executions>
                                
    <execution>
                                    
    <phase>package</phase>
                                    
    <goals>
                                        
    <goal>war</goal>
                                    
    </goals>
                                    
    <configuration>
                                        
    <classifier>dev</classifier>
                                    
    </configuration>
                                
    </execution>
                            
    </executions>
                        
    </plugin>

                    
    </plugins>
                
    </build>
            
    </profile>
            
    <profile>
                
    <id>test</id>
                
    <build>
                    
    <plugins>
                        
    <plugin>
                            
    <groupId>org.codehaus.mojo</groupId>
                            
    <artifactId>build-helper-maven-plugin</artifactId>
                            
    <version>1.5</version>
                            
    <executions>
                                
    <execution>
                                    
    <id>add-resource</id>
                                    
    <phase>generate-resources</phase>
                                    
    <goals>
                                        
    <goal>add-resource</goal>
                                    
    </goals>
                                    
    <configuration>
                                        
    <resources>
                                            
    <resource>
                                                
    <directory>src/main/resources_test</directory>
                                            
    </resource>
                                        
    </resources>
                                    
    </configuration>
                                
    </execution>
                            
    </executions>
                        
    </plugin>
                        
    <plugin>
                            
    <groupId>org.apache.maven.plugins</groupId>
                            
    <artifactId>maven-war-plugin</artifactId>
                            
    <executions>
                                
    <execution>
                                    
    <phase>package</phase>
                                    
    <goals>
                                        
    <goal>war</goal>
                                    
    </goals>
                                    
    <configuration>
                                        
    <classifier>test</classifier>
                                    
    </configuration>
                                
    </execution>
                            
    </executions>
                        
    </plugin>
                    
    </plugins>
                
    </build>
            
    </profile>
        
    </profiles>

    (文章后面有簡化版本)

    自己根據實際的部署環境修改吧, 運行 mvn package -P test 就可以打包了.


    反正很簡單啦. 一大堆xml, 有用的沒幾句....太羅嗦了


    另:目前開發用resin, intellij idea 9, 調試時webapp在開發目錄webapp下就地開發, 所以我的maven腳本還有如下部分:

        <build>
            
    <plugins>
                
    <plugin>
                    
    <groupId>org.apache.maven.plugins</groupId>
                    
    <artifactId>maven-war-plugin</artifactId>
                    
    <version>2.1</version>
                    
    <configuration>
                        
    <warSourceExcludes>WEB-INF/lib/**,WEB-INF/classes/**,WEB-INF/work/**,WEB-INF/tmp/**</warSourceExcludes>
                        
    <archive>
                          
    <addMavenDescriptor>false</addMavenDescriptor>
                        
    </archive>
                    
    </configuration>
                
    </plugin>
            
    </plugins>
        
    </build>


    這部分是公用的, 當然dev時候也不用打包.... 所以........ 可以用于本機開發, 打包到test, production等環境.



    總之部署上maven不如ant靈活, ant寫一套腳本一般來說也很少修改了.... 想改特容易. maven想復制個目錄都要想法....


    ______________________________________________
    簡化后的版本:

        <properties>
           
    <package.target>notexists</package.target>
        
    </properties>
        
        
    <profiles>
            
    <profile>
                
    <id>dev</id>
                
    <properties>
                     
    <package.target>dev</package.target>
                
    </properties>
            
    </profile>
            
    <profile>
                
    <id>test</id>
                
    <properties>
                     
    <package.target>test</package.target>
                
    </properties>
            
    </profile>
        
    </profiles>

        
    <build>
            
    <plugins>
                
    <plugin>
                    
    <groupId>org.codehaus.mojo</groupId>
                    
    <artifactId>build-helper-maven-plugin</artifactId>
                    
    <version>1.5</version>
                    
    <executions>
                        
    <execution>
                            
    <id>add-resource</id>
                            
    <phase>generate-resources</phase>
                            
    <goals>
                                
    <goal>add-resource</goal>
                            
    </goals>
                            
    <configuration>
                                
    <resources>
                                    
    <resource>
                                        
    <directory>src/main/resources_${package.target}</directory>
                                    
    </resource>
                                
    </resources>
                            
    </configuration>
                        
    </execution>
                    
    </executions>
                
    </plugin>
                
    <plugin>
                    
    <groupId>org.apache.maven.plugins</groupId>
                    
    <artifactId>maven-war-plugin</artifactId>
                    
    <version>2.1</version>
                    
    <configuration>
                        
    <warSourceExcludes>WEB-INF/lib/**,WEB-INF/classes/**,WEB-INF/work/**,WEB-INF/tmp/**</warSourceExcludes>
                        
    <archive>
                          
    <addMavenDescriptor>false</addMavenDescriptor>
                        
    </archive>
                    
    </configuration>
                    
    <executions>
                        
    <execution>
                            
    <phase>package</phase>
                            
    <goals>
                                
    <goal>war</goal>
                            
    </goals>
                            
    <configuration>
                                
    <classifier>${package.target}</classifier>
                            
    </configuration>
                        
    </execution>
                    
    </executions>
                
    </plugin>
            
    </plugins>
        
    </build>



    posted on 2010-10-27 22:31 Scud(飛云小俠) 閱讀(11788) 評論(3)  編輯  收藏 所屬分類: Java

    評論

    # re: MAVEN:如何為開發和生產環境建立不同的配置文件 --我的簡潔方案 2010-10-28 10:35 Scud(飛云小俠)

    http://jdkcn.com/entry/pack-different-package-by-environment-in-maven.html

    http://hi.baidu.com/guorabbit/blog/item/a908adeff31eec1dfdfa3cbb.html

    上面這2個也可以, 不過只能用于package了.

    看了上面2個方案, 發現我的方案也可以簡化, 就是profile里面只定義變量就可以了, 其他公用的提取出來用變量.  回復  更多評論   

    # re: MAVEN:如何為開發和生產環境建立不同的配置文件 --我的簡潔方案 2010-10-28 18:51 jacklondon

    如何為開發和生產環境建立不同的配置文件 --我用ANT+ bat批處理環境變量  回復  更多評論   

    # re: MAVEN:如何為開發和生產環境建立不同的配置文件 --我的簡潔方案[未登錄] 2013-09-18 16:20 過客

    謝謝!很不錯!已經用上了!  回復  更多評論   

    <2013年9月>
    25262728293031
    1234567
    891011121314
    15161718192021
    22232425262728
    293012345

    導航

    統計

    公告

    文章發布許可
    創造共用協議:署名,非商業,保持一致

    我的郵件
    cnscud # gmail


    常用鏈接

    留言簿(15)

    隨筆分類(113)

    隨筆檔案(103)

    相冊

    友情鏈接

    技術網站

    搜索

    積分與排名

    最新評論

    閱讀排行榜

    評論排行榜

    主站蜘蛛池模板: 99re热精品视频国产免费| 国产美女被遭强高潮免费网站| 亚洲精品国产电影午夜| 一个人看的www在线观看免费| 日韩国产精品亚洲а∨天堂免| 久久亚洲精品无码播放| 日本成年免费网站| 免费无毒a网站在线观看| 亚洲a在线视频视频| 国产成人精品高清免费| 免费av片在线观看网站| 怡红院亚洲红怡院在线观看| 亚洲av永久无码精品古装片| 日韩成人在线免费视频| 久久99精品视免费看| 看亚洲a级一级毛片| 亚洲综合国产精品| 亚洲高清偷拍一区二区三区| h视频在线免费看| 中文字幕a∨在线乱码免费看| 亚洲日韩精品无码专区加勒比| 亚洲人成网站在线播放vr| 免费的涩涩视频在线播放| 久久免费动漫品精老司机| 免费福利在线观看| 精品亚洲AV无码一区二区三区| a级亚洲片精品久久久久久久| 毛色毛片免费观看| 美丽姑娘免费观看在线观看中文版| 免费一级毛suv好看的国产网站 | 亚洲天堂电影在线观看| 亚洲综合国产精品第一页| 久久不见久久见中文字幕免费 | 色偷偷亚洲第一综合网| 亚洲国产精品人久久| 亚洲一区二区高清| 女人18一级毛片免费观看| 19禁啪啪无遮挡免费网站| a级成人毛片免费视频高清| 青青久久精品国产免费看 | 久草免费福利资源站|