今天在为新项目搭建JBoss Webservice环境时,注意到了endorsed

JBossAS 4.2.3.GA can be compiled with both Java5 & Java6. The Java5 compiled binary is our primary/recommended binary distribution. It has undergone rigorous testing and can run under both a Java 5 and a Java 6 runtime. When running under Java 6 you need to manually copy the following libraries from the JBOSS_HOME/client directory to the JBOSS_HOME/lib/endorsed directory, so that the JAX-WS 2.0 apis supported by JBossWS are used:

  • jboss-jaxrpc.jar
  • jboss-jaxws.jar
  • jboss-jaxws-ext.jar
  • jboss-saaj.jar
  • jaxb-api.jar

什么是endorsed呢?Google一把后,在官网找到了答案:http://download.oracle.com/javase/6/docs/technotes/guides/standards/index.html

From time to time it is necessary to update the Java platform in order to incorporate newer versions of standards that are created outside of the Java Community Process (Endorsed Standards), or in order to update the version of a technology included in the platform to correspond to a later standalone version of that technology (Standalone Technologies).
The Endorsed Standards Override Mechanism provides a means whereby later versions of classes and interfaces that implement Endorsed Standards or Standalone Technologies may be incorporated into the Java Platform.

JDK包括Java运行环境,Java工具和Java基础的类库。岁月变化,它也慢慢长大。壮大过程中当然主要有Java Community Process(JCP)母亲的哺育,但自身也虚心求学,掌握了很多Endorsed Standards。我们利用JDK来开发,发现其中的某个第三方技能已经过时了。怎么办?背书一下,临时抱个佛脚,把那项技能拷贝到Endorsed 目录,现学现用。

If you are running Java 1.4, an older version of Xalan is bundled with Java. You will want to download and install a newer version of Xalan. Unfortunately, just setting your CLASSPATH to the new jar files is not sufficient. You also need to supply a Java option to force it to use the newer versions.

比如在Java1.4 里绑定了一个很低版本的Xalan,可是我想用最新的Xalan。仅仅是把新的Jar加到CLASSPATH 是不行的,还需要把Jar拷贝到系统属性java.endorsed.dirs 所指的目录。官方文档指出位于:

<java-home>\lib\endorsed [Microsoft Windows] <java-home>/lib/endorsed [Solaris or Linux]。 总算是把原理弄清楚了。回过头来看看JBoss是怎么把目录指向到JBOSS_HOME/lib/endorsed的。 bin目录下的run.bat 里有这么关键两段:

rem Setup the java endorsed dirs
set JBOSS_ENDORSED_DIRS=%JBOSS_HOME%\lib\endorsed

:RESTART
"%JAVA%" %JAVA_OPTS% ^
   -Djava.endorsed.dirs="%JBOSS_ENDORSED_DIRS%" ^
   -classpath "%JBOSS_CLASSPATH%" ^
   org.jboss.Main %*

只要指定java.endorsed.dirs参数即可。来看看默认情况下JBoss都背书了些啥。 Java 背书_休闲