本文仅供学习研究使用,不得用于任何非法及侵权用途。
转贴请注明原发位置: http://xuekaiyuan.com/forum.php?mod=viewthread&tid=6
讨论请加QQ群:306320259
iQQ 学习笔记3说明 :编写代码打包 Ant 脚本
基于iQQ进行二次开发后,为了在生产环境中运行,就需要将代码打包,代码打包包含三部分:
- 二次开发的程序
- iQQ的内核,WebQQ-Core
- 二次开发的程序及WebQQ-Core所需要的类库
iQQ 学习笔记3程序 :编写代码打包 Ant 脚本
这是代码打包脚本,其中的 webqq-core_path 请替换为 WebQQ-Core 项目的路径,build_path 请替换为保存打包目标的路径,accessTokenFile 请替换为保存有新浪微博开放平台的 Access Token 的文件
<?xml version="1.0" encoding="UTF-8" standalone="no"?> <project default="create_run_jar" name="Create Runnable Jar for Project test with libraries in sub-folder"> <tstamp> <format property="build_id" pattern="YYYY-MM-dd-HH-mm-ss" timezone="GMT+8"/> </tstamp> <property name="webqq-core_path" value="**********"/> <property name="build_path" value="**********/${build_id}"/> <property name="accessTokenFile" value="**********"/> <property name="lib_dir" value="lib"/> <target name="create_run_jar"> <jar destfile="${build_path}/webqq-test.jar"> <manifest> <attribute name="Main-Class" value="test_2.Test_2"/> <attribute name="Class-Path" value=". webqq-core.jar ${lib_dir}/log4j-1.2.15.jar ${lib_dir}/slf4j-api-1.6.6.jar ${lib_dir}/slf4j-log4j12-1.6.6.jar ${lib_dir}/json-20090211.jar ${lib_dir}/commons-codec-1.6.jar ${lib_dir}/commons-logging-1.1.1.jar ${lib_dir}/httpclient-4.2.1.jar ${lib_dir}/httpclient-cache-4.2.1.jar ${lib_dir}/httpcore-4.2.2.jar ${lib_dir}/httpcore-nio-4.2.2.jar ${lib_dir}/httpmime-4.2.3.jar ${lib_dir}/httpasyncclient-4.0-beta3.jar ${lib_dir}/httpasyncclient-cache-4.0-beta3.jar"/> </manifest> <fileset dir="${basedir}/bin"/> </jar> <jar destfile="${build_path}/webqq-core.jar"> <fileset dir="${webqq-core_path}/bin"/> </jar> <mkdir dir="${build_path}/${lib_dir}"/> <copy file="${webqq-core_path}/lib/log4j-1.2.15.jar" todir="${build_path}/${lib_dir}"/> <copy file="${webqq-core_path}/lib/slf4j-api-1.6.6.jar" todir="${build_path}/${lib_dir}"/> <copy file="${webqq-core_path}/lib/slf4j-log4j12-1.6.6.jar" todir="${build_path}/${lib_dir}"/> <copy file="${webqq-core_path}/lib/json-20090211.jar" todir="${build_path}/${lib_dir}"/> <copy file="${webqq-core_path}/lib/commons-codec-1.6.jar" todir="${build_path}/${lib_dir}"/> <copy file="${webqq-core_path}/lib/commons-logging-1.1.1.jar" todir="${build_path}/${lib_dir}"/> <copy file="${webqq-core_path}/lib/httpclient-4.2.1.jar" todir="${build_path}/${lib_dir}"/> <copy file="${webqq-core_path}/lib/httpclient-cache-4.2.1.jar" todir="${build_path}/${lib_dir}"/> <copy file="${webqq-core_path}/lib/httpcore-4.2.2.jar" todir="${build_path}/${lib_dir}"/> <copy file="${webqq-core_path}/lib/httpcore-nio-4.2.2.jar" todir="${build_path}/${lib_dir}"/> <copy file="${webqq-core_path}/lib/httpmime-4.2.3.jar" todir="${build_path}/${lib_dir}"/> <copy file="${webqq-core_path}/lib/httpasyncclient-4.0-beta3.jar" todir="${build_path}/${lib_dir}"/> <copy file="${webqq-core_path}/lib/httpasyncclient-cache-4.0-beta3.jar" todir="${build_path}/${lib_dir}"/> <copy file="${accessTokenFile}" todir="${build_path}"/> <copy file="run.bat" todir="${build_path}"/> </target> </project>
在 Eclipse 中运行 Ant 脚本,将自动在 build_path 中生成一个保存本次打包的文本件,其中包含下列文件:
- lib文件夹
- Access Token 文件
- run.bat
- webqq-core.jar
- webqq-test.jar
1. 查看版本
[root@localhost ~]# cat /etc/redhat-release
CentOS release 5.7 (Final)
2. 查看cpu
[root@localhost ~]# cat /proc/cpuinfo | grep name
model name : Intel(R) Xeon(R) CPU E5606 @ 2.13GHz
model name : Intel(R) Xeon(R) CPU E5606 @ 2.13GHz
model name : Intel(R) Xeon(R) CPU E5606 @ 2.13GHz
model name : Intel(R) Xeon(R) CPU E5606 @ 2.13GHz
显示为四核
3. 查看cpu动态利用率
top后按1
top - 09:29:37 up 9 days, 21:10, 3 users, load average: 0.27, 0.19, 0.17
Tasks: 103 total, 1 running, 101 sleeping, 1 stopped, 0 zombie
Cpu0 : 0.3%us, 0.0%sy, 0.0%ni, 99.7%id, 0.0%wa, 0.0%hi, 0.0%si, 0.0%st
Cpu1 : 0.7%us, 0.0%sy, 0.0%ni, 99.0%id, 0.0%wa, 0.0%hi, 0.3%si, 0.0%st
Cpu2 : 4.3%us, 0.3%sy, 0.0%ni, 94.7%id, 0.0%wa, 0.0%hi, 0.7%si, 0.0%st
Cpu3 : 8.0%us, 0.3%sy, 0.0%ni, 90.7%id, 0.0%wa, 0.3%hi, 0.7%si, 0.0%st
Mem: 8164364k total, 8118024k used, 46340k free, 247540k buffers
Swap: 2097208k total, 136k used, 2097072k free, 5024688k cached
PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
22709 www 18 0 7017m 2.4g 13m S 14.0 30.2 51:14.45 jsvc
27183 www 15 0 64872 22m 1048 S 0.3 0.3 0:58.92 nginx
27189 www 15 0 64712 22m 1048 S 0.3 0.3 0:48.71 nginx
4. 查看内存使用情况
[root@localhost ~]# free
total used free shared buffers cached
Mem: 8164364 8118344 46020 0 249664 5009032
-/+ buffers/cache: 2859648 5304716
Swap: 2097208 136 2097072
第1行 Mem:
total:物理总内存
used:总缓存(包含buffers 与cache ),其中可能部分缓存未实际使用。
buffers :总缓存中未被使用buffers
cached:总缓存中未被使用cache
total = used + free
第2行 -/+ buffers/cached:
used:实际使用内存。 第一行中的used – buffers-cached
free:实际可用内存。 第一行中的buffers +cache + free
5. 硬盘使用情况
[root@localhost ~]# df -hl
文件系统 容量 已用 可用 已用% 挂载点
/dev/sda2 208G 47G 151G 24% /
/dev/sda6 142G 415M 135G 1% /var
/dev/sda3 190G 53G 128G 30% /usr
/dev/sda1 184M 18M 157M 11% /boot
6. 查看网卡信息
[root@localhost ~]# cat /etc/sysconfig/network-scripts/ifcfg-eth0
# Broadcom Corporation NetXtreme II BCM5716 Gigabit Ethernet
DEVICE=eth0
BOOTPROTO=none
HWADDR=d4:ae:52:6e:80:3d
IPADDR=xxx.xxx.xx.xxx
NETMASK=255.255.255.0
ONBOOT=yes
GATEWAY=xxx.xxx.xx.xxx
TYPE=Ethernet
重启网卡
/etc/init.d/network stop
/etc/init.d/network start
/etc/init.d/network reload
/etc/init.d/network restart
service network stop
service network start
service network restart
service network status 查看网卡设备
[root@localhost ~]# service network status
配置设备:
lo eth0 eth1
当前的活跃设备:
lo eth0 eth1
7. 查看域名服务器设置
[root@localhost ~]# cat /etc/resolv.conf
search localdomain
nameserver xxx.xxx.x.xx
nameserver x.x.x.x
Given inorder and postorder traversal of a tree, construct the binary tree.
代码如下:
TreeNode *build(vector<int>&postorder,int m_beginp,int m_endp,vector<int> &inorder,int m_begini,int m_endi)
{
if(m_endp-m_beginp!=m_endi-m_begini)return NULL;
if(m_endp<m_beginp)return NULL;
TreeNode *root=new TreeNode(postorder[m_endp]);
root->left=NULL;
root->right=NULL;
int i;
for(i=m_begini;i<=m_endi;i++)
{
if(postorder[m_endp]==inorder[i])
{
break;
}
}
if(i>m_endi)return NULL;
if(i-m_begini>0)
root->left=build(postorder,m_beginp,m_beginp+i-m_begini-1,inorder,m_begini,i-1);
if(i<m_endi)
root->right=build(postorder,m_beginp+i-m_begini,m_endp-1,inorder,i+1,m_endi);
return root;
}
TreeNode *buildTree(vector<int> &inorder, vector<int> &postorder)
{
return build(postorder,0,postorder.size()-1,inorder,0,inorder.size()-1);
}