Fei's profile精诚所至,金石为开。PhotosBlogListsMore ![]() | Help |
|
January 22 Ant学习笔记--基础篇一 Ant的安装(在此之前请安装JDK,不懂的请看我的另一篇,Java学习笔记) 1. 登录到http://ant.apache.org/ 下载最新版本的binary文件 当前的是apache-ant-1.7.0-bin.tar.gz 2. 解压到本机 $ tar -xvzf apache-ant-1.7.0-bin.tar.gz 解压到你想要的目录,我的是/opt/apache-ant-1.7.0 3. 导入环境变量 export ANT_HOME=/opt/apache-ant-1.7.0 4. 把ant的bin加到Path里面 export PATH=${PATH}:${ANT_HOME}/bin 你可以把这两句话加到~/.bashrc里面 5. 测试 $ ant -version 二 快速浏览(给出一个基本的Ant使用的Sample) A. 首先先向大家展示一下不用Ant是如何编译和打包的, 这样就知道Ant是多么的方便 1. 创建基本的目录结构 |-- build | `-- classes `-- src `-- imi `-- HelloWorld.java 2. 编写HelloWorld.java文件 package imi; public class HelloWorld { public static void main(String[] args) { System.out.println("Hello World"); } } 3. 编译 $ javac -sourcepath src -d build/classes src/imi/HelloWorld.java 编译后的目录结构 |-- build | `-- classes | `-- imi | `-- HelloWorld.class `-- src `-- imi `-- HelloWorld.java 4. 测试 $ java -cp build/classes imi.HelloWorld 看到的结果:Hello World 5. 创建jar包 新的目录结构 |-- build | |-- classes | | `-- imi | | `-- HelloWorld.class | `-- jar `-- src `-- imi `-- HelloWorld.java 6. 创建Mainfest文件 $ echo Main-class: imi.HelloWorld>myMainfes 7. 打jar包 $ jar cfm build/jar/HelloWorld.jar myMainfest -C build/classes . 最新的目录结构 |-- build | |-- classes | | `-- imi | | `-- HelloWorld.class | `-- jar | `-- HelloWorld.jar |-- myMainfest `-- src `-- imi `-- HelloWorld.java 创建jar包并不难,只需要两步,第一创建manifest文件,第二创建文件夹 8. 测试 $ java -jar build/jar/HelloWorld.jar 看到的结果:Hello World B. 使用Ant 1. 目录结构 |-- build.xml |-- myMainfest `-- src `-- imi `-- HelloWorld.java 2. 编写build.xml <project> <target name="clean"> <delete dir="build"/> </target> <target name="compile"> <mkdir dir="build/classes"/> <javac srcdir="src" destdir="build/classes"/> </target> <target name="jar"> <mkdir dir="build/jar"/> <jar destfile="build/jar/HelloWorld.jar" basedir="build/classes"> <manifest> <attribute name="Main-Class" value="imi.HelloWorld"/> </manifest> </jar> </target> <target name="run"> <java jar="build/jar/HelloWorld.jar" fork="true"/> </target> </project> 3. 现在可以编译,打包了 $ ant compile $ ant jar $ ant run 或者 $ant compile jar run 现在是机会比较一下这两种方式的不同 好了,我们已经完成了一个基本的Ant程序,但是还有点问题需要我们解决。 a. 我们经常引用相同的目录 b. jar,main-class的内容是硬编码的 c. 你需要知道这几个命令的顺序 4. 所以我们有了改进的build.xml <project name="HelloWorld" basedir="." default="main"> <property name="src.dir" value="src"/> <property name="build.dir" value="build"/> <property name="classes.dir" value="build/classes"/> <property name="jar.dir" value="build/jar"/> <property name="main-class" value="imi.HelloWorld"/> <target name="clean"> <delete dir="build"/> </target> <target name="compile"> <mkdir dir="${classes.dir}"/> <javac srcdir="src" destdir="${classes.dir}"/> </target> <target name="jar" depends="compile"> <mkdir dir="${jar.dir}"/> <jar destfile="${jar.dir}/imi.jar" basedir="${classes.dir}"> <manifest> <attribute name="Main-Class" value="${main-class}"/> </manifest> </jar> </target> <target name="run" depends="jar"> <java jar="${jar.dir}/imi.jar" fork="true"/> </target> <target name="clean-build" depends="clean,jar"/> <target name="main" depends="clean,run"/> </project> 新的目录结构 |-- build.xml `-- src `-- imi `-- HelloWorld.java 5. 现在运行 $ ant run 三 引用额外的库文件,由于log4j的普遍使用,我们这次就加入log4j这个库(不懂的log4j的,请看我的另一篇,log4j学习笔记) 1. 登录到http://logging.apache.org/log4j/index.html下载最新版本的binary文件 当前的是 apache-log4j-1.2.15.tar.gz 2. 解压到本机 $ tar -xvzf apache-log4j-1.2.15.tar.gz 3. 找到log4j的jar包,放到lib目录 新的目录结构 |-- build.xml |-- lib | `-- log4j-1.2.15.jar `-- src `-- imi `-- HelloWorld.java 4. 现在我们修改HelloWorld.java package imi; import org.apache.log4j.Logger; import org.apache.log4j.BasicConfigurator; public class HelloWorld { static Logger logger = Logger.getLogger(HelloWorld.class); public static void main(String[] args) { BasicConfigurator.configure(); logger.info("Hello World"); // 向控制台输出 } } 5. 修改build.xml,增加classpath目录 <project name="HelloWorld" basedir="." default="main"> <property name="src.dir" value="src"/> <property name="lib.dir" value="lib"/> <property name="build.dir" value="build"/> <property name="classes.dir" value="build/classes"/> <property name="jar.dir" value="build/jar"/> <property name="main-class" value="imi.HelloWorld"/> <path id="classpath"> <fileset dir="lib" includes="**/*.jar"/> </path> <target name="clean"> <delete dir="build"/> </target> <target name="compile"> <mkdir dir="${classes.dir}"/> <javac srcdir="src" destdir="${classes.dir}" classpathref="classpath"/> </target> <target name="jar" depends="compile"> <mkdir dir="${jar.dir}"/> <jar destfile="${jar.dir}/imi.jar" basedir="${classes.dir}"> <manifest> <attribute name="Main-Class" value="${main-class}"/> </manifest> </jar> </target> <target name="run" depends="jar"> <java fork="true" classname="${main-class}"> <classpath> <path refid="classpath"/> <path location="${jar.dir}/imi.jar"/> </classpath> </java> </target> <target name="clean-build" depends="clean,jar"/> <target name="main" depends="clean,run"/> </project> 6. 运行ant,得到结果 但是这样并不是建议的用法,因为我们有了硬编码BasicConfigurator.configure(),虽然简单,但是很难更改。所以我们创建log4j.properties 新的目录结构 |-- build.xml |-- lib | `-- log4j-1.2.15.jar `-- src |-- imi | `-- HelloWorld.java `-- log4j.properties 修改log4j.properties log4j.rootLogger=DEBUG, stdout log4j.appender.stdout=org.apache.log4j.ConsoleAppender log4j.appender.stdout.layout=org.apache.log4j.PatternLayout log4j.appender.stdout.layout.ConversionPattern=%m%n 这个配置文件创建了一个Appender到控制台,大印了消息(%m)和线行数(%n),跟早期的System.out.println()一样 修改HelloWorld.java文件 package imi; import org.apache.log4j.Logger; public class HelloWorld { static Logger logger = Logger.getLogger(HelloWorld.class); public static void main(String[] args) { logger.info("Hello World"); // 向控制台输出 } } 修改build.xml <project name="HelloWorld" basedir="." default="main"> <property name="src.dir" value="src"/> <property name="lib.dir" value="lib"/> <property name="build.dir" value="build"/> <property name="classes.dir" value="build/classes"/> <property name="jar.dir" value="build/jar"/> <property name="main-class" value="imi.HelloWorld"/> <path id="classpath"> <fileset dir="lib" includes="**/*.jar"/> </path> <target name="clean"> <delete dir="build"/> </target> <target name="compile"> <mkdir dir="${classes.dir}"/> <javac srcdir="src" destdir="${classes.dir}" classpathref="classpath"/> <copy todir="${classes.dir}"> <fileset dir="src" excludes="**/*.java"/> </copy> </target> <target name="jar" depends="compile"> <mkdir dir="${jar.dir}"/> <jar destfile="${jar.dir}/imi.jar" basedir="${classes.dir}"> <manifest> <attribute name="Main-Class" value="${main-class}"/> </manifest> </jar> </target> <target name="run" depends="jar"> <java fork="true" classname="${main-class}"> <classpath> <path refid="classpath"/> <path location="${jar.dir}/imi.jar"/> </classpath> </java> </target> <target name="clean-build" depends="clean,jar"/> <target name="main" depends="clean,run"/> </project> 这回多增加了复制所有的源文件(除了.java文件)到build文件夹,这些文件将会被包含到jar包中 四 Ant和Junit的联合使用 1. 登录到http://www.junit.org/下载最新版本的jar包 当前的是 junit-4.4.jar 2. 把junit的jar包,放到lib目录 新的目录结构 |-- build.xml |-- lib | |-- junit-4.4.jar | `-- log4j-1.2.15.jar `-- src |-- HelloWorldTest.java |-- imi | `-- HelloWorld.java `-- log4j.properties 3. 编写HelloWorldTest.java文件 public class HelloWorldTest extends junit.framework.TestCase { public void testNothing() { } public void testWillAlwaysFail() { fail("An error message"); } } 因为我们没有真正的逻辑去测试,所以这个类非常的小,仅仅是展示功能 4. 修改build.xml <project name="HelloWorld" basedir="." default="main"> <property name="src.dir" value="src"/> <property name="lib.dir" value="lib"/> <property name="build.dir" value="build"/> <property name="classes.dir" value="build/classes"/> <property name="jar.dir" value="build/jar"/> <property name="main-class" value="imi.HelloWorld"/> <path id="classpath"> <fileset dir="lib" includes="**/*.jar"/> </path> <target name="clean"> <delete dir="build"/> </target> <target name="compile"> <mkdir dir="${classes.dir}"/> <javac srcdir="src" destdir="${classes.dir}" classpathref="classpath"/> <copy todir="${classes.dir}"> <fileset dir="src" excludes="**/*.java"/> </copy> </target> <target name="jar" depends="compile"> <mkdir dir="${jar.dir}"/> <jar destfile="${jar.dir}/imi.jar" basedir="${classes.dir}"> <manifest> <attribute name="Main-Class" value="${main-class}"/> </manifest> </jar> </target> <target name="run" depends="jar"> <java fork="true" classname="${main-class}"> <classpath> <path refid="classpath"/> <path id="application" location="${jar.dir}/imi.jar"/> </classpath> </java> </target> <target name="junit" depends="jar"> <junit printsummary="yes"> <classpath> <path refid="classpath"/> <path refid="application"/> </classpath> <batchtest fork="yes"> <fileset dir="src" includes="*Test.java"/> </batchtest> </junit> </target> <target name="clean-build" depends="clean,jar"/> <target name="main" depends="clean,run"/> </project> 我们通过id重复使用了我们自己的jar包,junit printsummary="yes"让Ant给我们更多的信息,而不仅仅是FAILED或者PASSED。你也可以以后在batchtest里面加入更多的测试类 5. 运行ant junit 6. 你还可以通过junit产生报告 修改build.xml <project name="HelloWorld" basedir="." default="main"> <property name="src.dir" value="src"/> <property name="lib.dir" value="lib"/> <property name="build.dir" value="build"/> <property name="classes.dir" value="build/classes"/> <property name="jar.dir" value="build/jar"/> <property name="main-class" value="imi.HelloWorld"/> <property name="report.dir" value="build/junitreport"/> <path id="classpath"> <fileset dir="lib" includes="**/*.jar"/> </path> <target name="clean"> <delete dir="build"/> </target> <target name="compile"> <mkdir dir="${classes.dir}"/> <javac srcdir="src" destdir="${classes.dir}" classpathref="classpath"/> <copy todir="${classes.dir}"> <fileset dir="src" excludes="**/*.java"/> </copy> </target> <target name="jar" depends="compile"> <mkdir dir="${jar.dir}"/> <jar destfile="${jar.dir}/imi.jar" basedir="${classes.dir}"> <manifest> <attribute name="Main-Class" value="${main-class}"/> </manifest> </jar> </target> <target name="run" depends="jar"> <java fork="true" classname="${main-class}"> <classpath> <path refid="classpath"/> <path id="application" location="${jar.dir}/imi.jar"/> </classpath> </java> </target> <target name="junit" depends="jar"> <mkdir dir="${report.dir}"/> <junit printsummary="yes"> <classpath> <path refid="classpath"/> <path refid="application"/> </classpath> <formatter type="xml"/> <batchtest fork="yes" todir="${report.dir}"> <fileset dir="src" includes="*Test.java"/> </batchtest> </junit> </target> <target name="junitreport"> <junitreport todir="${report.dir}"> <fileset dir="${report.dir}" includes="TEST-*.xml"/> <report todir="${report.dir}"/> </junitreport> </target> <target name="clean-build" depends="clean,jar"/> <target name="main" depends="clean,run"/> </project> 因为我们会产生很多文件,这些文件会被存放到当前的目录,所以在执行junit之前,创建并指向junitreport文件夹,文件的格式是XML,因此junitreport可以解析。junitreport的第二个任务是基于XML文件创建HTML形式的报告,现在你可以打开${report.dir}\index.html看看结果 January 12 Simple tutorialCreating an Application from Scratch (without Eclipse)applicationCreator com.mycompany.client.MyApplication The applicationCreator script will generate a number of files in src/com/mycompany/, including some basic "Hello, world" functionality in the class src/com/mycompany/client/MyApplication.java. The script also generates a hosted mode launch script called MyApplication-shell and a compilation script called MyApplication-compile, just like the sample application above.To run your newly created application in hosted mode, run the MyApplication-shell script:Creating an Application from Scratch (with Eclipse)projectCreator -eclipse MyProjectapplicationCreator -eclipse MyProject com.mycompany.client.MyApplication December 18 fcitxubuntu 7.10 beta
English locale sudo apt-get install language-pack-zh sudo apt-get install fcitx sudo apt-get install im-switch im-switch -s fcitx sudo gedit /usr/lib/gtk-2.0/2.10.0/immodule-files.d/libgtk2.0-0.immodules # "xim" "X Input Method" "gtk20" "/usr/share/locale" "ko:ja:th:zh" "xim" "X Input Method" "gtk20" "/usr/share/locale" "en:ko:ja:th:zh" fonts字体安装:
这些字体里面包含如下字体
这些字体安装在"/usr/share/fonts/truetype/msttcorefonts"目录之下。 其它中文字体为"simsun.ttc,mingliu.ttc"(附:我这里使用的
mingliu.ttc是5.03版的),还可以把如下字体一并拷贝过来"tahoma.ttf tahomab.ttf arialuni.ttf
simfang.ttf simhei.ttf simkai.ttf simli.ttf
simyou.ttf",还有一个字体"stxihei.ttf",在处理中文小字时可以得到比较好的效果,可以到这里下载。
再执行如下命令创建字体安装目录:
sudo fc-cache -f -v December 13 tar如果是tar.gz文件 % sh /home/cs9416/install_protege.bin alienAlien is a program that converts between the rpm, dpkg, stampede slp, and slackware tgz file formats. If you want to use a package from another distribution than the one you have installed on your system, you can use alien to convert it to your preferred package format and install it. Despite the large version number, alien is still (and will probably always be) rather experimental software. It has been used by many people for many years, but there are still many bugs and limitations. Alien should not be used to replace important system packages, like sysvinit, shared libraries, or other things that are essential for the functioning of your system. Many of these packages are set up differently by Debian and Red Hat, and packages from the different distributions cannot be used interchangably. In general, if you can’t uninstall the package without breaking your system, don’t try to replace it with an alien version. Install alien in debian #apt-get install alien This will install all the required packages.Now you can start converting your .rpm files to .deb packages. Available Options for alien Convert the package.rpm into a package.deb #alien -d package-name.rpm Convert the package.rpm into a package.deb, and install the generated package. #alien -i package-name.rpm If you want to keeps alien from changing the version number use the following command #alien -k rpm-package-file.rpm Example Suppose we have a avg antivirus avg71lms-r30-a0782.i386.rpm file To convert .rpm to debian #alien -k avg71lms-r30-a0782.i386.rpm Now you should be having avg71lms-r30-a0782.i386.deb file To install .deb file #dpkg -i avg71lms-r30-a0782.i386.deb If you don’t use -k option you should see avg71lms_r30-1_i386.deb file the difference is it will add 1 Install alien in Ubuntu $sudo apt-get install alien You can check the above section for available options Example Suppose we have a avg antivirus avg71lms-r30-a0782.i386.rpm file To convert .rpm to debian $sudo alien -k avg71lms-r30-a0782.i386.rpm Now you should be having avg71lms-r30-a0782.i386.deb file To install .deb file $sudo dpkg -i avg71lms-r30-a0782.i386.deb If you don’t use -k option you should see avg71lms_r30-1_i386.deb file the difference is it will add 1 December 02 set environment varialble in ubuntu 7.10系统环境变量: /etc/bashrc:为每一个运行bash shell的用户执行此文件.当bash shell被打开时,该文件被读取. 当前用户变量: ======================================================================= 在ununtu linux的配置文件中一劳永逸的设置环境变量 1.环境变量配置中,要先删除.bash_profile中的三行关于.bashrc的定义,然后把环境变量配置在.bashrc中 Useful linux commandls: -a list all files and folders -l use a long listing format examples: ls -a ls -l ln: target link_name -s make symbolic links instead of hard links examples: ln -s jdk1.6.0_03 jdk env: see environment variable env December 01 Basic knowledge of tomcat
How to install jdk in ubuntuThere are two version of the JDK is available: Installation of Self-Extracting Binary1. Download and check the download file size to ensure that you have downloaded the full, uncorrupted software bundle.You can download to any directory you choose; it does not have to be the directory where you want to install the JDK.2. Make sure that execute permissions are set on the self-extracting binary. Run this command: 3. Change directory to the location where you would like the files to be installed. The next step installs the JDK into the current directory. 4. Run the self-extracting binary. Execute the downloaded file, prepended by the path to it. For example, if the file is in the current directory, prepend it with "./" (necessary if "." is not in the PATH environment variable): Installation of RPM File1. Download and check the file size.
You can download to any directory you choose. 2. Become root by running the su command and entering the super-user password. 3. Extract and install the contents of the downloaded file. Change directory to where the downloaded file is located and run these commands to first set the executable permissions and then run the binary to extract and run the RPM file: 4. Delete the bin and rpm file if you want to save disk space.
5.
Exit the root shell.
A new service script, named jexec, is added to /etc/init.d. This script allows users to directly execute any standalone JAR file that has an execution permission set. This can be demonstrated using an example from the JDK: cd /usr/java/jdk1.6.0/demo/jfc/SwingSet2 chmod +x SwingSet2.jar SwingSet2.jar Set environment variable in ubuntu |
|
|