niyue

Archive for the ‘java’ Category

获取运行中的JVM系统属性

In java on 3月 4, 2005 at 4:24 上午

获取运行中的JVM系统属性

getProperties

public static Properties getProperties()
Determines the current system properties.First, if there is a security manager, its checkPropertiesAccess method is called with no arguments. This may result in a security exception.

The current set of system properties for use by the getProperty(String) method is returned as a Properties object. If there is no current set of system properties, a set of system properties is first created and initialized. This set of system properties always includes values for the following keys:

Key Description of Associated Value
java.version Java Runtime Environment version
java.vendor Java Runtime Environment vendor
java.vendor.url Java vendor URL
java.home Java installation directory
java.vm.specification.version Java Virtual Machine specification version
java.vm.specification.vendor Java Virtual Machine specification vendor
java.vm.specification.name Java Virtual Machine specification name
java.vm.version Java Virtual Machine implementation version
java.vm.vendor Java Virtual Machine implementation vendor
java.vm.name Java Virtual Machine implementation name
java.specification.version Java Runtime Environment specification version
java.specification.vendor Java Runtime Environment specification vendor
java.specification.name Java Runtime Environment specification name
java.class.version Java class format version number
java.class.path Java class path
java.library.path List of paths to search when loading libraries
java.io.tmpdir Default temp file path
java.compiler Name of JIT compiler to use
java.ext.dirs Path of extension directory or directories
os.name Operating system name
os.arch Operating system architecture
os.version Operating system version
file.separator File separator (“/” on UNIX)
path.separator Path separator (“:” on UNIX)
line.separator Line separator (“\n” on UNIX)
user.name User’s account name
user.home User’s home directory
user.dir User’s current working directory

Multiple paths in a system property value are separated by the path separator character of the platform.

Note that even if the security manager does not permit the getProperties operation, it may choose to permit the getProperty(String) operation.

Returns:
the system properties
Throws:
SecurityException – if a security manager exists and its checkPropertiesAccess method doesn’t allow access to the system properties.
See Also:
setProperties(java.util.Properties), SecurityException, SecurityManager.checkPropertiesAccess(), Properties

Spring中的异常

In javaprogramming on 3月 2, 2005 at 10:36 上午
public class BeanDefinitionStoreException
extends FatalBeanException

Exception thrown when a BeanFactory encounters an internal error, and its definitions are invalid: for example, if an XML document containing bean definitions isn’t well-formed.

程序中抛出了这个异常,检查了半天也没发现原因,后来仔细看了一下print stack信息,发现原来我同时在最外层的类和其中引用的其他类中使用了spring,出错发生在引用类中,所以是引用类的spring bean的xml文件出错了,出错的原因用XML SPY配合spring-bean.dtd一检查,原来是把java的注释符号//当成xml中的注释符号<!– –>来用了~

eclipse wtp project

In java on 2月 26, 2005 at 1:45 上午

eclipse wtp project
Eclipse Web Tools Platform (WTP) Project

All About The WTP Project
The Eclipse Web Tools Platform (WTP) project extends the Eclipse platform with tools for developing J2EE Web applications. The WTP project includes the following tools: source editors for HTML, Javascript, CSS, SQL, XML, DTD, XSD, and WSDL; graphical editors for XSD and WSDL; J2EE project natures, builders, and models and a J2EE navigator; a Web service wizard and explorer, and WS-I Test Tools; and database access and query tools and models.

非常酷的工具集,到底是IBM捐献的,功能异常的强大,不过pre-requirements也是非常之多,eclipse的插件要爆炸了

Spring – Java/J2EE Application Framework 参考手册

In javaprogramming on 2月 7, 2005 at 6:34 上午

Spring – Java/J2EE Application Framework 参考手册

使用Apache Common Id生成标识符

In javaprogramming on 2月 5, 2005 at 4:10 下午

现在的项目中要用到标识符的生成,早就看到Apache上面Jakarta项目的common子项目下有一个id子子项目(^_^,这就是apache),使用它很容易的就可以完成唯一的标识符的生成。今天稍微花了一点时间试验了一下,很容易就搞定了,基本没碰到什么困难。主要的步骤如下:

  1. 下载Apache-common-id。因为这个sub-sub-project是属于sandbox(沙盒中的项目用户可以自由使用,但是这些项目的维护并不得到保证,很可能会一直处于目前的状态)中的一个项目,所以没有binary的下载。只能下载源代码以后编译得到。我是使用Eclipse中的cvs的客户端访问apache的cvs得到的源代码。cvs站点名称为cvs.apache.org,访问路径为/home/cvspublic,用户名为anoncvs,不需要密码。登录到cvs服务器上后检出id项目的所有相关文件。
  2. 使用ant对源代码进行编译。我开始用Eclipse里面自带的ant进行编译,但是build失败了。编译器报错说我的jre中的类库版本号与需要的版本号不一致(需要的是48.0版的,我用的J2SE5.0,那个类库的版本号显示是49.0)。我满试了一下不用Eclipse里面自带的ant,自己下载一个ant对源代码编译,结果通过编译了居然(编译的时候ant会根据那个build.xml文件从网上下载相关的类库,所以需要连接到Internet才可以成功)。
  3. 然后后面的工作就很轻松了,用jar把编译后的class打包就可以了。
  4. 打包好后就可以很容易的使用了。一行代码就可以生成数字字符混合的id号。
String id=IdentifierUtils.nextStringAlphanumericIdentifier();

编写Javadoc

In javaprogramming on 2月 5, 2005 at 1:09 下午

以下是参考的一些文章:

  1. How to Write Doc Comments for the Javadoc Tool
  2. javadoc,在 Java 的注释上做文章
  3. 在java源码中为Javadoc编写文档注释(1)

v4_java_logo.gif  在java编码规范中,提到了文档注释可被javadoc用来生成API文档。具体的写法,另有说明。下面是学习笔记,主要是摘了一些值得注意的要点。

1、javadoc的获取

只能从相应的JDK中取得,安装后在bin目录下。具体如下:
* Javadoc 1.4 is included in Java 2 SDK, Standard Edition v 1.4
* Javadoc 1.3 is included in Java 2 SDK, Standard Edition v 1.3
* Javadoc 1.2 is included in Java 2 SDK, Standard Edition v 1.2
* Javadoc 1.1 is included in JDK 1.1

2、文档注释编写(principles)

  • Java平台API文档由源码中的文档注释定义,且任何此类文档皆从此类注释取得
  • Java平台API文档是调用者(caller)和实现之间的契约(contract)
  • 除非另有说明,Java平台API文档声明(assertion)应为与具体实现无关(implelementation-independent)
  • Java平台API文档应有足够的声明,以使得软件质量保证部门能写出完全的JCK (Java Compatibility Kit)测试。

3、文档注释编写细则

  1. 每个文档注释的第一句,应是个概要句,简明但无遗地描述API项。第一句在第一个后跟空格的点号前结束。当句中出现非结束意义的点加空格时,需要空格进行转义,如 等。
  2. 自动重利用父类/接口方法(method)的注释,当(1)一个类方法重写(override)父类的方法时,或(2)一个接口方法重写父接口的方法时,或(3)一个类方法实现一个接口方法时。如果当前方法没文档注释,则从父方法复制,如果有,则不复制而是前两者有小标题 “Overrides”,后者有”Specified by”.
  3. 用<code>…</code>来标注关键词或名字
  4. 节约使用行内链接{@link}
  5. 对方法和构建函数的说明,要去掉括号
  6. 可以为了简短使用短语而不是句子
  7. 使用第3人称而不是第2人称
  8. 以一个动词短语开始对一个方法的描述
  9. 对类/接口/字段(field)的描述,可以忽略主语
  10. 用”this”而不是“the”来引用从当前类生成的对象
  11. 不要仅是简单地把API名字里的单词展开来做描述,要增加一些信息。
  12. 当作用”field”一词时,注意它易引起混淆
  13. 避免拉丁语缩写
  14. 标签顺序
    1. @author,多个作者时按参考修改代码的年代为序
    2. @version
    3. @param,多个参数时以方法声明中的顺序为序,单个@param后跟参数名(不要相应的类型),再加描述
    4. @return
    5. @exception,多个异常时以异常名字的字母顺序为序
    6. @see,多个参见时据 #field,#Constructor(Type, Type…),#Constructor(Type id, Type id…),#method(Type, Type,…),#method(Type id, Type, id…),Class,Class#field,Class#Constructor(Type, Type…),Class#Constructor(Type id, Type id),Class#method(Type, Type,…),Class#method(Type id, Type id,…),package.Class,package.Class#field,package.Class#Constructor(Type, Type…),package.Class#Constructor(Type id, Type id),package.Class#method(Type, Type,…),package.Class#method(Type id, Type, id),package排序
    7. @since
    8. @serial
    9. @deprcated
  15. @param和@return(当返回不是void时)都是必须的

Struts中进行数据验证

In java on 1月 30, 2005 at 8:22 上午

Developer STRUTS

Check Your Form with Validator

By James Holmes

Enabling the Validator Plug-in

配置Validator插件,也即在配置struts-config.xml,加入该插件

Configuring validator-rules.xml

大多数情况下你不需要修改预定义的验证规则,除非你希望给框架自定义验证规则。

Included Validations

默认情况下已经包含了一些常用的验证器,如required,CreditCard和email等

Creating Form Beans

为了使用验证器,应用中的Form Bean应该是验证器ActionForm的子类,
而不能是ActionFrom本身。这一子类提供了ActionForm的validate()方法的一个实现。Form Bean继承了子类之后并不需要将验证进行硬编码,完全可以将这一方法忽略掉。验证器会帮你提供验证需要的代码。
form bean在struts-config.xml中的配置也同常规的Form Bean相同验证的时候配置validation.xml。两种标准的方式创建Form Bean。一种是创建一个具体的Form Bean,另一种是创建一个动态的Form Bean,validator.xml的Form Bean的验证与struts-config.xml中的Form Bean一对一的绑定,这种机制可以适用于绝大多数的情况,但是当Form Bean在多个Action间复用(可能有的用的字段多一些有的用的少一些)时,就不适用了。为了解决这一问题,验证器有两个子类ValidatorActionForm和DynaValidatorActionForm允许将验证与action进行绑定而不是与Form Bean进行绑定。

Configuring validation.xml

Configuring ApplicationResources.properties

验证器使用Struts的资源束机制来显示错误消息。主要配置ApplicationResource.properties(添加消息文本和对应的key)文件和validation.xml(利用key引用消息文本)文件。

如果不想使用资源束机制的话,也可以在validation.xml文件中直接表明。

Enabling Client-Side Validations

除了服务端的数据验证,Struts还有机制支持客户端验证。
在validator-rules.xml中标明了在客户端用于验证的JavaScript代码(可选的标明)
为了使用客户端验证,就要在每个需要验证的JSP插入Struts HTML标签库的JavaScript标签。而无论是否使用客户端验证,服务端验证都会进行。

其他的一些文章:

Struts Validator验证器使用指南(推荐阅读)

在struts中使用validator做页面验证

Struts Validator的使用

学习Struts

In javalearning on 1月 28, 2005 at 2:34 上午

最近不断在看Struts方面的资料,应该说Struts已经是很成熟的一种技术了,在网上的相关介绍也是连篇累牍,但是看了能够增进理解有所帮助的还是比较难见到。下面是我觉得在Struts学习中对我有帮助的一些资料:

下面是我学习中遇到的一些困难及解决:

    • 在Tomcat上部署Struts的例子的时候碰到了问题,解决:Unable to find a javac compiler
    • 表单数据验证失败时发生错误,“No input attribute for mapping path”,原因是没有填写配置文件action中的input属性值。解决:Struts中不同的Action和ActionForm组合
    • 两次输入密码比较的验证,解决:Struts Validator: Validating Two Fields Match by Matt Raible. Howto article.开始漏看了最后一句重要的话,没看完就开始了,结果因为那个小问题浪费了两个多小时,真是不值得。
    • 实现下拉框时出现错误”Cannot find bean under name org.apache.struts.taglib.html.BEAN”。解决:JSP FAQ @ jGuru
    • 部署新的action时发生错误”No Action Instance for Path /CreateContent could be created”,开始在网上找了一下,发现大多数此类错误都是由于Action的type名称写错了,但是我仔细核对发现这里没有错,我的错误在于没有将Action的type类声明成public的!
    • 上面的数据验证的例子中采用的API调用已经被deprecated掉了,Struts 1.2用也还可以用,但是Eclipse里面会出来感叹号说不赞成使用ValidatorUtil和Resources.getActionError()方法,解决:Struts Upgrade Notes 11 to 124
    • 开了一个新的sample应用的时候,出现异常java.lang.IllegalArgumentException: Resources cannot be null.
      at org.apache.commons.validator.Validator.(Validator.java:188)
      后来发现是strut
      中没有添加validator插件,同时validation.xml文件和validator-rules.xml文件不存在
    • 使用Struts将应用分成为几个模块配置的时候,无论如何配置,一直出现找不到子模块中的action的异常,”Cannot retrieve mapping for action /mindforce/SubmitLogon”.后来发现原来是tab的链接没有通过action进行转发,而是直接写了要显示的jsp页面视图的url,因此struts进行模块间转换时无法自动识别,故action mapping找不到对应的action.正确的配置方法是:子模块中的action路径均填写模块下的相对路径,jsp页面中的action也填写相对于模块的路径而不要加上模块名称,struts会自动在模块切换时添加模块名.模块切换方法请见:5.3.3 Switching Modules

进行Struts开发时一些有用的工具:

    • Scioworks™ Camino

      Visual Modelling Tool for Struts

      Scioworks™ Camino is a visual modelling tool for Jakarta Struts Framework, the de-facto J2EE web MVC framework. Designed for rapid assembly of web applications, its unique visual drag-and-connect paradigm allows for rapid development and re-wiring of web application with minimal coding.

Exadel Struts Studio now supports Eclipse 3.0.x. This version includes design-time JSP Preview, JSP, CSS, JavaScript and XML Prompting with autocomplete functionality, Java debugging of Web applications under the Tomcat, JBoss and Sun J2EE SDK environment, and one-step adding of Struts support to J2EE projects created with other Eclipse plug-ins.

    • JamesHolmes.com

Struts Console

The Struts Console is a FREE standalone Java Swing application for developing and managing Struts-based applications. With the Struts Console you can visually edit JSP Tag Library, Struts, Tiles and Validator configuration files.

The Struts Console also plugs into multiple, popular Java IDEs for seamless management of Struts applications from one central development tool.

FWA Software‘s Visual Tags Dreamweaver extension suites for JSTL and Struts enable web developers to use Macromedia’s Dreamweaver MX web design and development product to

  • Visually design, implement, and maintain web pages for JSTL and Struts-based web applications
  • Rapidly prototype web pages for JSTL and Struts-based web applications
  • Exploit open source technologies with Dreamweaver to create JSTL and Struts-based web applications

Eclipse Plugins

In java on 1月 27, 2005 at 4:37 下午

Eclipse Plugins

Java Server Faces Resources

In javaprogramming on 1月 21, 2005 at 1:45 下午

JamesHolmes.com
Java Server Faces Resources


Articles
Books
Blog Entries
Chats / Interviews
FAQs
Forums / Mailing Lists
In The News

Links
Presentations
Software – Components
Software – GUI Tools
Software – Implementations
Software – Miscellaneous
Tutorials