Fork me on GitHub
maven+svn+hudson+weblogic构建持续集成环境

maven+svn+hudson+weblogic构建持续集成环境

持续集成环境就是我们开发的时候,有一套环境自动编译、打包、测试、部署、发布的环境。

 

  1. 构建工具使用maven,在pom.xml中需要配置一个profile,内容如下:

    <profiles>

       <profile>

           <id>deploytoweblogic</id>

           <dependencies>

              <dependency>

                  <groupId>xml-apis</groupId>

                  <artifactId>xml-apis</artifactId>

                  <version>1.0.b2</version>

                  <scope>provided</scope>

              </dependency>

           </dependencies>         

           <build>

              <plugins>

                  <plugin>

                     <artifactId>maven-resources-plugin</artifactId>

                     <version>2.5</version>

                     <executions>

                         <execution>

                            <id>copy-resources</id>

                            <!-- here the phase you need -->

                            <phase>prepare-package</phase>

                            <goals>

                                <goal>copy-resources</goal>

                            </goals>

                            <configuration>

                                <outputDirectory>${basedir}/target/classes</outputDirectory>

                                <resources>

                                   <resource>

                                       <directory>src/main/resources/weblogic</directory>

                                       <filtering>true</filtering>

                                   </resource>

                                </resources>

                            </configuration>

                         </execution>

                     </executions>

                  </plugin>

                  <plugin>

                     <groupId>com.oracle.weblogic</groupId>

                     <artifactId>weblogic-maven-plugin</artifactId>

                     <version>10.3.4</version>

                     <configuration>

                         <adminurl>10.67.1.1:8080/webmis</adminurl>

                         <user>admin</user>

                         <password>admin123</password>

                         <upload>true</upload>

                         <action>redeploy</action>

                         <remote>false</remote>

                         <verbose>true</verbose>

                         <source>${project.build.directory}/${project.build.finalName}.${project.packaging}</source>

                         <name>ctrading2</name>

                         <delete_files>true</delete_files>

                     </configuration>

                     <executions>

                         <execution>

                            <id>DeployToRemoteContainer</id>

                            <phase>install</phase>

                            <goals>

                                <goal>redeploy</goal>

                             </goals>

                         </execution>

                     </executions>

                  </plugin>

              </plugins>

           </build>

       </profile>

    </profiles>

 

需要注意三个地方,
(1)红色配置部分是增加一个依赖,防止与weblogic的jar冲突。如果没有,会报异常java.lang.ClassCastException: weblogic.xml.jaxp.RegistryDocumentBuilderFactory cannot be cast to javax.xml.parsers.DocumentBuilderFactory

(2)灰色部分是hudson用来发送到weblogic需要执行的插件,执行阶段是install。

(3)中间蓝色部分是在安装时覆盖资源用的。因为开发环境和部署环境使用的数据源是不一样的,所以在发布时需要使用非开发的数据源。部署环境数据源文件如下:

<?xml version="1.0" encoding="GBK"?>

<beans xmlns="http://www.springframework.org/schema/beans"

    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

    xsi:schemaLocation="http://www.springframework.org/schema/beans

       http://www.springframework.org/schema/beans/spring-beans-3.0.xsd">

    <!-- dataSource -->

    <!-- WebLogic JNDI -->

    <bean id="dataSource" class="org.springframework.jndi.JndiObjectFactoryBean">

       <property name="jndiName" value="wls_ots_ds" />

    </bean>

    <!-- Query Data Source -->

    <!-- WebLogic JNDI -->

    <bean id="dataQuerySource" class="org.springframework.jndi.JndiObjectFactoryBean">

       <property name="jndiName" value="wls_ots_query_ds" />

    </bean>

</beans>

 

这样客户端maven的工作就完成了,开发时和平常没有任何区别。

 

下面介绍hudson配置。

在hudson上添加项目就不说了,只说几个在配置时需要注意的点:

  1. source code managemante节点选择subversion,填写项目的svn地址。
  2. build trigger时选择第三项,在schedule中填入周期,如“0 2 * * *”表示每天2点执行构建。
  3. build节点的Goals and options填入clean install -DskipTests=true –Pdeploytoweblogic 表示使用maven进行构建,忽略测试,使用deploytoweblogic执行部署。
  4. 在build节点点击advanced,在MAVEN_OPTS输入-Xms512m -Xmx2048m -XX:MaxPermSize=512m。这是因为hudson使用maven构建会占用大量内存,可能会造成内存不足。

 

剩下的就是weblogic的配置了,那就很简单了,指定数据源即可。

posted on 2012-04-01 10:45  HackerVirus  阅读(512)  评论(0编辑  收藏  举报