J2EE容器分为Servlet容器和EJB容器,例如Tomcat就是一个Servlet容器,WebLogic,WebSphere Application Server,JBoss就是EJB容器。他们都提供JNDI的支持,你可以把任何资源(如DataSource、JMS、Queue、Mail甚至是URL资源)都绑定到JNDI上下文中,这样可以降低组件间的耦合性。
通常的Servlet容器(如Tomcat、Resin)中的JNDI资源只能被容器中的程序查到、使用,而不能在容器外引用,也就是只能被容器所以进程所用;而EJB容器中的JNDI资源却可以在容器外,或者是另一台机器上的程序查找到并透明使用,因为EJB本来就是要为分布式服务的。EJB容器中的JNDI资源可以通过JNP、RMI、IIOP、T3或文件引用的方式发布出去。 Read More
网上找了好些个关于CheckStyle的文章都是抄抄抄一大通,却没有一个build.xml着实可运行,
在这里我也是参考着一编,改改成能成功运行并能生成正确报告,发送 Email 的build.xml文件1<?xml version="1.0" encoding="gb2312"?> 2 3<!-- ANT make file checkstype --> 4 5<!-- See <a href="http://jakarta.apache.org/ant" data-mce-href="http://jakarta.apache.org/ant">http://jakarta.apache.org/ant</a> for info about ANT --> 6<!-- 网上下来的CheckStyle解压在d:/javalib/CheckStyle/checkstyle-4.1中 --> 7<project name="checkstyle" default="checkstyle" basedir="d:/javalib/CheckStyle/checkstyle-4.1"> 8 9 <!-- CheckStyle配置,这里你替换成你实际的环境 --> 10 <property name="project.docs.dir" value="${basedir}/contrib"/> 11 12 <!-- 源代码的目录是e:/eclipseworkspace/talupdate/src --> 13 <property name="project.src.dir" value="e:/eclipseworkspace/talupdate/src"/> 14 15 <!-- 建立了build目录在其中生成报告 --> 16 <property name="project.checkstyleReport.dir" value="${basedir}/build"/> 17 <property name="checkstyle.jar" value="${basedir}/checkstyle-all-4.1.jar"/> 18 19 <!-- 使用SUN的代码规范,可替换成公司自己的规范 --> 20 <property name="checkstyle.config" value="${basedir}/sun_checks.xml"/> 21 <property name="checkstyle.report.style" value="${project.docs.dir}/checkstyle-noframes.xsl"/> 22 <property name="checkstyle.result" value="${project.checkstyleReport.dir}/checkstyle_result.xml"/> 23 <property name="checkstyle.report" value="${project.checkstyleReport.dir}/checkstyle_report.html"/> 24 25 <!-- 定义发送邮件列表 --> 26 <property name="mail.list" value="(User1)user1@xxx.com,(User2)user2@xxx.com"/> 27 28 <target name="init"> 29 <tstamp/> 30 </target> 31 32 <!--CheckStyle脚步--> 33 <taskdef resource="checkstyletask.properties" classpath="${checkstyle.jar}"/> 34 35 <target name="checkstyle" depends="init" description="对java源代码进行检查并产生检查报告. "> 36 <checkstyle config="${checkstyle.config}" failOnViolation="false" failureProperty="checkstyle.failure"> 37 <formatter type="xml" tofile="${checkstyle.result}"/> 38 <fileset dir="${project.src.dir}" includes="**/*.java"/> 39 </checkstyle> 40 41 <!-- 生成报告,其格式取决于${checkstyle.report.style} --> 42 <style in="${checkstyle.result}" out="${checkstyle.report}" style="${checkstyle.report.style}"/> 43 </target> 44 45 <!-- 当有不规范的情况发生时将检查结果发送到 --> 46 <target name="checkstyle-nightly" depends="checkstyle" if="checkstyle.failure" 47 description="Sends email if checkstyle detected code conventions violations."> 48 49 <!-- 如果邮件服务器需要验证,则加上 user 和 password 属性 --> 50 <mail from="(Admin)admin@xxx.com" tolist="${mail.list}" mailhost="mail.xxx.com" 51 subject=" checkstyle result from project reports" files="${checkstyle.report}"/> 52 </target> 53</project>
<继续补充内容>
Java测试代码覆盖率工具有Clover, Jcoverage和Emma等,其中只有Emma才算是彻底免费开源的,用起来也比较方便。
而Jcoverage使用起来就有些繁琐,必须一步步按照规定的方式走,步骤为 debug方式compile->instrument->test->coverage。
下面将简单介绍emma的使用,以下方法告诉你如以以命令的方式来生成代码测试覆盖率,当然你也可以写成 Ant 任务的方式,这就要求自己写几个 Ant 用的Task类,其实也不难。
emma的下载地址是:http://emma.sourceforge.net/downloads.html Read More- 关键Ant的build文件如下(已加上比较详细的说明)下面以后也会加上测试报告的贴图的。
1<?xml version="1.0" encoding="UTF-8"?> 2<project basedir="." default="main" name="excute TestCase and build test report"> 3 <!-- 测试报告存放目录 --> 4 <property name="build.reports.dir" value="${basedir}/report" /> 5 <target name="main"> 6 <!-- 删除测试报告数据,重新生成 --> 7 <delete> 8 <fileset dir="${basedir}/report"> 9 <include name="*.*" /> 10 </fileset> 11 </delete> 12 <junit fork="yes" printsummary="true"> 13 <!-- 生成的class目录以及执行TestCase所依赖的库 14 无论是用<test>还是<batchtest>都要这个配置 --> 15 <classpath location="${basedir}/bin" /> 16 <!-- 生成报告数据的格式,可能多个,支持xml/brief/plain --> 17 <formatter type="xml" /> 18 <formatter type="brief" usefile="false" /> 19 <!-- 可以用<test>也可以用<batchtest>,但两种的设置有一些区别 20 以下<test>和<batchtest>三种形式用某一种就可以的 --> 21 <!-- name指定Class的名称,如CatTest或com.unmi.CatTest --> 22 <test name="CatTest" todir="${build.reports.dir}" /> 23 <!-- 注意其中<fileset>的dir属性及<include>的name属性指代的意义 --> 24 <batchtest todir="${build.reports.dir}"> 25 <!-- dir属性指定TestCase类的源代码的路径 --> 26 <fileset dir="${basedir}/src"> 27 <!-- name属性指定TestCase源文件规则 --> 28 <include name="**/*Test.java" /> 29 </fileset> 30 </batchtest> 31 <!-- 上面的<batchtest>还可以写成如下形式,<fileset>按指定为class 32 注意其中<fileset>的dir属性及<include>的name属性指代的意义 --> 33 <batchtest todir="${build.reports.dir}"> 34 <!-- dir属性指定TestCase类的路径 --> 35 <fileset dir="${basedir}/bin"> 36 <!-- name属性指定TestCase类文件规则 --> 37 <include name="**/*Test.class" /> 38 </fileset> 39 </batchtest> 40 </junit> 41 <!-- 用执行以上TestCase生成的报告数据生成测试报告 --> 42 <junitreport todir="${build.reports.dir}"> 43 <fileset dir="${build.reports.dir}"> 44 <include name="TEST-*.xml" /> 45 </fileset> 46 <!-- 指定生成测试报告的格式frames/noframes,和报告存放目录 --> 47 <report format="frames" todir="${build.reports.dir}" /> 48 </junitreport> 49 </target> 50</project> - 下面的那一大段build.xml文件内容主要也是参考下载过来的JCoverage中的一个例子中的build文件,只是稍稍作了点修改,用下面这个build文件前,需要把JCoverage用到的 jar (下载的JCoverage中都有) 包拷到工程目录下lib子目录中,请注意理解其中的注解,以后必要时会加上更详细的中文注释。 Read More
- JCoverage不是免费的(对商业不是免费,对open source是免费的
JCoverage主页:http://www.jcoverage.com
JCoverage的允许需要JUnit和Log4j、bcel、jakarta-oro、getopt类库,这些类库在下载的JCoverage中都包含了,JCoverage主要也是和Ant结合在一起使用,
注意事项:
1 : 初始化是最好删除当前目录下的jcoverage.ser文件,这个文件就是测试的结果,如果其在当前目录下找到这个文件将不会进行测试,或者重新测试
2 : 在进行instrument时,一定要保证其class是debug模式下编译的,否则将不能注入jcoverage指令到被测试类的二进制文件中,建议从新用debug模式编译一个在当前目录 Read More
现在我们安装Linux的时候通常考虑到安全因素(默认情况下)是不打开telnet服务的,而ssh服务是有的,ant很早就支持telnet,但要求我们在Linux下要安装telnet-server,并要启用该服务。
还好自Ant1.60开始支持了SSH 及SCP 操作了,早在Ant之前若要支持SSH、SCP、SFTP等任务就必须下载j2ssh的j2ssh-ant.jar和j2ssh-core.jar(在http://www.sourceforge.net的j2ssh下有下载)。现在可以使用Ant提供的Sshexec和scp任务,由$ANT_HOME/lib/ant-jsch.jar提供支持,但是同样你也要在http://www.jcraft.com/jsch/index.html下载一个依赖包jsch-0.1.24.jar(文件名因版本而不同),jsch同样也是http://www.sourceforge.net下的一个项目。
你需要把下载的jsch-0.1.24拷贝到$ANT_HOME/lib下,如果是Eclipse下的Ant环境必须在Window->Preferences->Ant->Runtime->Classpath中加入jsch-0.1.24。 Read More