You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

Readme.html 16KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490
  1. <html>
  2. <HEAD>
  3. <META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1">
  4. <TITLE>Read Me First</TITLE>
  5. </HEAD>
  6. <body>
  7. <h1>Javassist version 2</h1>
  8. <h3>in May, 2003.
  9. <br>Copyright (C) 2000-2003 by Shigeru Chiba, All rights reserved.</h3>
  10. <p><br></p>
  11. <p>Javassist (JAVA programming ASSISTant) makes Java bytecode manipulation
  12. simple. It is a class library for editing bytecodes in Java;
  13. it enables Java programs to define a new class at runtime and to
  14. modify a class file when the JVM loads it. Unlike other similar
  15. bytecode editors, Javassist provides two levels of API: source level
  16. and bytecode level. If the users use the source-level API, they can
  17. edit a class file without knowledge of the specifications of the Java
  18. bytecode. The whole API is designed with only the vocabulary of the
  19. Java language. You can even specify inserted bytecode in the form of
  20. source text; Javassist compiles it on the fly. On the other hand, the
  21. bytecode-level API allows the users to directly edit a class file as
  22. other editors.
  23. <p><br>
  24. <h2>Files</h2>
  25. <ul>
  26. <table>
  27. <tr>
  28. <td><li><tt><a href="License.html">License.html</a></tt></td>
  29. <td>License file
  30. (Also see the <a href="#copyright">copyright notices</a> below)</td>
  31. </tr>
  32. <tr>
  33. <td><li><tt><a href="tutorial/tutorial.html">tutorial/tutorial.html</a></tt></td>
  34. <td>Tutorial</td>
  35. </tr>
  36. <tr>
  37. <td><li><tt>./javassist.jar</tt></td>
  38. <td>The Javassist jar file (class files)</td>
  39. </tr>
  40. <tr>
  41. <td><li><tt>./src/main</tt></td>
  42. <td>The source files</td>
  43. </tr>
  44. <tr>
  45. <td><li><tt><a href="html/index.html">html/index.html</a></tt></tr>
  46. <td>The top page of the Javassist API document.</td>
  47. </tr>
  48. <tr>
  49. <td><li><tt>./sample/</tt></td>
  50. <td>Sample programs</td>
  51. </tr>
  52. </table>
  53. </ul>
  54. <p>To extract source files from the archive, use the jar command:<br>
  55. <ul><pre>% jar xvf javassist-src.zip</pre></ul>
  56. <p><br>
  57. <h2>How to run sample programs</h2>
  58. <p>JDK 1.2.2 or later is needed.
  59. <h3>1. Move to the directory where this Readme.html file is located.</h3>
  60. <p>In the description below, we assume that the platform is JDK 1.2
  61. (or later) for Solaris. If the platform is JDK 1.2 (or later) for
  62. Windows, the class-path option is:
  63. <ul><pre>
  64. -classpath ".;javassist.jar"
  65. </pre></ul>
  66. <p>If you don't want to put the class-path option, copy
  67. <tt>./javassist.jar</tt> to
  68. <ul>&lt;<i>java-home</i>&gt;<tt>/jre/lib/ext/</tt>.</ul>
  69. <p>&lt;<i>java-home</i>&gt; depends on the system. It is usually
  70. <tt>/usr/local/java</tt>, <tt>c:\jdk1.2\</tt>, etc.
  71. <p>If you don't use javassist.jar, first compile Javassist:
  72. <ul><pre>
  73. % cd src
  74. % javac -d .. javassist/*.java javassist/*/*.java
  75. % cd ..
  76. </pre></ul>
  77. <p>Then you can compile and run the sample programs without the class-path
  78. option.
  79. <h3>2. sample/Test.java</h3>
  80. <p> This is a very simple program using Javassist.
  81. <p> To run, type the commands:
  82. <ul><pre>
  83. % javac -classpath ".:javassist.jar" sample/Test.java
  84. % java -cp ".:javassist.jar" sample.Test
  85. </pre></ul>
  86. <p> For more details, see <a type="text/plain" href="sample/Test.java">sample/Test.java</a>
  87. <h3>3. sample/reflect/*.java</h3>
  88. <p> This is the "verbose metaobject" example well known in reflective
  89. programming. This program dynamically attaches a metaobject to
  90. a Person object. The metaobject prints a message if a method
  91. is called on the Person object.
  92. <p> To run, type the commands:
  93. <ul><pre>
  94. % javac -classpath ".:javassist.jar" sample/reflect/*.java
  95. % java -cp ".:javassist.jar" javassist.reflect.Loader sample.reflect.Main Joe
  96. </pre></ul>
  97. <p>Compare this result with that of the regular execution without reflection:
  98. <ul><pre>% java -cp ".:javassist.jar" sample.reflect.Person Joe</pre></ul>
  99. <p> For more details, see <a type="text/plain" href="sample/reflect/Main.java">sample/reflect/Main.java</a>
  100. <p> Furthermore, the Person class can be statically modified so that
  101. all the Person objects become reflective without sample.reflect.Main.
  102. To do this, type the commands:
  103. <ul><pre>
  104. % java -cp ".:javassist.jar" javassist.reflect.Compiler sample.reflect.Person -m sample.reflect.VerboseMetaobj
  105. </pre></ul>
  106. <p> Then,
  107. <ul><pre>
  108. % java -cp ".:javassist.jar" sample.reflect.Person Joe
  109. </pre></ul>
  110. <h3>4. sample/duplicate/*.java</h3>
  111. <p> This is another example of reflective programming.
  112. <p> To run, type the commands:
  113. <ul><pre>
  114. % javac -classpath ".:javassist.jar" sample/duplicate/*.java
  115. % java -cp ".:javassist.jar" sample.duplicate.Main
  116. </pre></ul>
  117. <p>Compare this result with that of the regular execution without reflection:
  118. <ul><pre>% java sample.duplicate.Viewer</pre></ul>
  119. <p>For more details, see
  120. <a type="text/plain" href="sample/duplicate/Main.java">sample/duplicate/Main.java</a>
  121. <h3>5. sample/vector/*.java</h3>
  122. <p>This example shows the use of Javassit for producing a class representing
  123. a vector of a given type at compile time.
  124. This is a demonstration of the use of <tt>javassist.preproc</tt> package.
  125. <p> To run, type the commands:
  126. <ul><pre>
  127. % javac -classpath ".:javassist.jar" sample/vector/*.java
  128. % java -cp ".:javassist.jar" javassist.preproc.Compiler sample/vector/Test.j
  129. % javac sample/vector/Test.java
  130. % java sample.vector.Test
  131. </pre></ul>
  132. <p>For more details, see
  133. <a type="text/plain" href="sample/vector/Test.j">sample/vector/Test.j</a>
  134. and <a type="text/plain" href="sample/vector/VectorAssistant.java">sample/vector/VectorAssistant.java</a>
  135. <h3>6. sample/rmi/*.java</h3>
  136. <p> This demonstrates the javassist.rmi package.
  137. <p> To run, type the commands:
  138. <ul><pre>
  139. % javac -classpath ".:javassist.jar" sample/rmi/*.java
  140. % java -cp ".:javassist.jar" sample.rmi.Counter 5001
  141. </pre></ul>
  142. <p> The second line starts a web server listening to port 5001.
  143. <p> Then, open <a href="sample/rmi/webdemo.html">sample/rmi/webdemo.html</a>
  144. with a web browser running
  145. on the local host. (<tt>webdemo.html</tt> trys to fetch an applet from
  146. <tt>http://localhost:5001/</tt>, which is the web server we started above.)
  147. <p> Otherwise, run sample.rmi.CountApplet as an application:
  148. <ul><pre>
  149. % java -cp ".:javassist.jar" javassist.web.Viewer localhost 5001 sample.rmi.CountApplet
  150. </pre></ul>
  151. <h3>7. sample/evolve/*.java</h3>
  152. <p> This is a demonstration of the class evolution mechanism implemented
  153. with Javassist. This mechanism enables a Java program to reload an
  154. existing class file under some restriction.
  155. <p> To run, type the commands:
  156. <ul><pre>
  157. % javac -classpath ".:javassist.jar" sample/evolve/*.java
  158. % java -cp ".:javassist.jar" sample.evolve.DemoLoader 5003
  159. </pre></ul>
  160. <p> The second line starts a class loader DemoLoader, which runs a web
  161. server DemoServer listening to port 5003.
  162. <p> Then, open <a href="http://localhost:5003/demo.html">http://localhost:5003/demo.html</a> with a web browser running
  163. on the local host.
  164. (Or, see <a href="sample/evolve/start.html">sample/evolve/start.html</a>.)
  165. <h3>8. Hints</h3>
  166. <p>Javassist provides a class file viewer for debugging. For more details,
  167. see javassist.Dump.
  168. <p><br>
  169. <h2>Changes</h2>
  170. <p>- version 2.5 in May, 2003.
  171. <br>From this version, Javassist is part of the JBoss project.
  172. <ul>
  173. <li>The license was changed from MPL to MPL/LGPL dual.
  174. <li>ClassPool.removeClassPath() and ClassPath.close() have been added.
  175. <li>ClassPool.makeClass(InputStream) has been added.
  176. <li>javassist.expr.Handler has been added.
  177. <li>CtMethod.isEmpty() and CtConstructor.isEmpty() have been added.
  178. <li>LoaderClassPath has been implemented.
  179. </ul>
  180. <p>- version 2.4 in February, 2003.
  181. <ul>
  182. <li>The compiler included in Javassist did not correctly work with
  183. interface methods. This bug was fixed.
  184. <li>Now javassist.bytecode.Bytecode allows more than 255 local
  185. variables in the same method.
  186. <li>javassist.expr.Instanceof and Cast have been added.
  187. <li>javassist.expr.{MethodCall,NewExpr,FieldAccess,Instanceof,Cast}.where()
  188. have been added. They return the caller-side method surrounding the
  189. expression.
  190. <li>javassist.expr.{MethodCall,NewExpr,FieldAccess,Instanceof,Cast}.mayThrow()
  191. have been added.
  192. <li>$class has been introduced.
  193. <li>The parameters to replaceFieldRead(), replaceFieldWrite(),
  194. and redirectFieldAccess() in javassist.CodeConverter are changed.
  195. <li>The compiler could not correctly handle a try-catch statement.
  196. This bug has been fixed.
  197. </ul>
  198. <p>- version 2.3 in December, 2002.
  199. <ul>
  200. <li>The tutorial has been revised a bit.
  201. <li>SerialVersionUID class was donated by Bob Lee. Thanks.
  202. <li>CtMethod.setBody() and CtConstructor.setBody() have been added.
  203. <li>javassist.reflect.ClassMetaobject.useContextClassLoader has been added.
  204. If true, the reflection package does not use Class.forName() but uses
  205. a context class loader specified by the user.
  206. <li>$sig and $type are now available.
  207. <li>Bugs in Bytecode.write() and read() have been fixed.
  208. </ul>
  209. <p>- version 2.2 in October, 2002.
  210. <ul>
  211. <li>The tutorial has been revised.
  212. <li>A new package <code>javassist.expr</code> has been added.
  213. This is replacement of classic <code>CodeConverter</code>.
  214. <li>javassist.ConstParameter was changed into
  215. javassist.CtMethod.ConstParameter.
  216. <li>javassist.FieldInitializer was renamed into
  217. javassist.CtField.Initializer.
  218. <li>A bug in javassist.bytecode.Bytecode.addInvokeinterface() has been
  219. fixed.
  220. <li>In javassist.bytecode.Bytecode, addGetfield(), addGetstatic(),
  221. addInvokespecial(), addInvokestatic(), addInvokevirtual(),
  222. and addInvokeinterface()
  223. have been modified to update the current statck depth.
  224. </ul>
  225. <p>- version 2.1 in July, 2002.
  226. <ul>
  227. <li>javassist.CtMember and javassist.CtBehavior have been added.
  228. <li>javassist.CtClass.toBytecode() has been added.
  229. <li>javassist.CtClass.toClass() and javassist.ClassPool.writeAsClass()
  230. has been added.
  231. <li>javassist.ByteArrayClassPath has been added.
  232. <li>javassist.bytecode.Mnemonic has been added.
  233. <li>Several bugs have been fixed.
  234. </ul>
  235. <p>- version 2.0 (major update) in November, 2001.
  236. <ul>
  237. <li>The javassist.bytecode package has been provided. It is a
  238. lower-level API for directly modifying a class file although
  239. the users must have detailed knowledge of the Java bytecode.
  240. <li>The mechanism for creating CtClass objects have been changed.
  241. <li>javassist.tool.Dump moves to the javassist package.
  242. </ul>
  243. <p>version 1.0 in July, 2001.
  244. <ul>
  245. <li>javassist.reflect.Metaobject and ClassMetaobject was changed.
  246. Now they throw the same exception that they receive from a
  247. base-level object.
  248. </ul>
  249. <p>- version 0.8
  250. <ul>
  251. <li>javassist.tool.Dump was added. It is a class file viewer.
  252. <li>javassist.FiledInitializer.byNewArray() was added. It is for
  253. initializing a field with an array object.
  254. <li>javassist.CodeConverter.redirectMethodCall() was added.
  255. <li>javassist.Run was added.
  256. </ul>
  257. <p>- version 0.7
  258. <ul>
  259. <li>javassit.Loader was largely modified. javassist.UserLoader was
  260. deleted. Instead, Codebase was renamed to ClassPath
  261. and UserClassPath was added. Now programmers who want to
  262. customize Loader must write a class implementing UserClassPath
  263. instead of UserLoader. This change is for sharing class search paths
  264. between Loader and CtClass.CtClass(String).
  265. <li>CtClass.addField(), addMethod(), addConstructor(), addWrapper() were
  266. also largely modified so that it receives CtNewMethod, CtNewConstructor,
  267. or CtNewField. The static methods for creating these objects were
  268. added to the API.
  269. <li>Constructors are now represented by CtConstructor objects.
  270. CtConstructor is a subclass of CtMethod.
  271. <li>CtClass.getUserAttribute() was removed. Use CtClass.getAttribute().
  272. <li>javassist.rmi.RmiLoader was added.
  273. <li>javassist.reflect.Metalevel._setMetaobject() was added. Now
  274. metaobjects can be replaced at runtime.
  275. </ul>
  276. <p>- version 0.6
  277. <ul>
  278. <li>Javassist was modified to correctly deal with array types appearing
  279. in signatures.
  280. <li>A bug crashed resulting bytecode if a class includes a private static
  281. filed. It has been fixed.
  282. <li>javassist.CtNewInterface was added.
  283. <li>javassist.Loader.recordClass() was renamed into makeClass().
  284. <li>javassist.UserLoader.loadClass() was changed to take the second
  285. parameter.
  286. </ul>
  287. <p>- version 0.5
  288. <ul>
  289. <li>a bug-fix version.
  290. </ul>
  291. <p>- version 0.4
  292. <ul>
  293. <li>Major update again. Many classes and methods were changed.
  294. Most of methods taking java.lang.Class have been changed to
  295. take javassist.CtClass.
  296. </ul>
  297. <p>- version 0.3
  298. <ul>
  299. <li>Major update. Many classes and methods were changed.
  300. </ul>
  301. <p>- version 0.2
  302. <ul>
  303. <li>Jar/zip files are supported.
  304. </ul>
  305. <p>-version 0.1 in April, 1999.
  306. <ul>
  307. <li>The first release.
  308. </ul>
  309. <p><br>
  310. <h2>Bug reports etc.</h2>
  311. <dl>
  312. <dt>Bug reports:
  313. <dd><tt><a href="mailto:chiba@acm.org">chiba@acm.org</a></tt>
  314. <br>or
  315. <tt><a href="mailto:chiba@is.titech.ac.jp">chiba@is.titech.ac.jp</a></tt>
  316. <br>
  317. <p><dt>The home page of Javassist:
  318. <dd>Visit <a href="http://www.jboss.org/index.html?module=html&op=userdisplay&id=developers/projects/javassist"><tt>www.jboss.org</tt></a>
  319. </dl>
  320. <p><br>
  321. <a name="copyright">
  322. <h2>Copyright notices</h2>
  323. <p>Javassist, a Java-bytecode translator toolkit.
  324. <br>Copyright (C) 1999-2003 Shigeru Chiba. All Rights Reserved.
  325. <p>The contents of this software, Javassist, are subject to
  326. the Mozilla Public License Version 1.1 (the "License");<br>
  327. you may not use this software except in compliance
  328. with the License. You may obtain a copy of the License at
  329. <br>http://www.mozilla.org/MPL/
  330. <p>Software distributed under the License is distributed on an "AS IS"
  331. basis, WITHOUT WARRANTY OF <br>ANY KIND, either express or implied.
  332. See the License for the specific language governing rights and
  333. <br>limitations under the License.
  334. <p>The Original Code is Javassist.
  335. <p>The Initial Developer of the Original Code is Shigeru Chiba.
  336. Portions created by the Initial Developer are<br>&nbsp;
  337. Copyright (C) 1999-2003 Shigeru Chiba. All Rights Reserved.
  338. <p>Contributor(s): ______________________________________.
  339. <p>Alternatively, the contents of this software may be used under the
  340. terms of the GNU Lesser General Public License Version 2.1 or later
  341. (the "LGPL"), in which case the provisions of the LGPL are applicable
  342. instead of those above. If you wish to allow use of your version of
  343. this software only under the terms of the LGPL, and not to allow others to
  344. use your version of this software under the terms of the MPL, indicate
  345. your decision by deleting the provisions above and replace them with
  346. the notice and other provisions required by the LGPL. If you do not
  347. delete the provisions above, a recipient may use your version of this
  348. software under the terms of either the MPL or the LGPL.
  349. <p>If you obtain this software as part of JBoss, the contents of this
  350. software may be used under only the terms of the LGPL. To use them
  351. under the MPL, you must obtain a separate package including only
  352. Javassist but not the other part of JBoss.
  353. <p><br>
  354. <h2>Acknowledgments</h2>
  355. <p>The development of this software is sponsored in part by the PRESTO
  356. programs of <a href="http://www.jst.go.jp/">Japan
  357. Science and Technology Corporation</a>.
  358. <p>I'd like to thank Michiaki Tatsubori, Johan Cloetens,
  359. Philip Tomlinson, Alex Villazon, Pascal Rapicault, Dan HE, Eric Tanter,
  360. Michael Haupt, Toshiyuki Sasaki, Renaud Pawlak, Luc Bourlier,
  361. Eric Bui, Lewis Stiller, Susumu Yamazaki, Rodrigo Teruo Tomita,
  362. Marc Segura-Devillechaise, Jan Baudisch, Julien Blass, Yoshiki Sato,
  363. Fabian Crabus, Bo Norregaard Jorgensen, Bob Lee, Bill Burke,
  364. Remy Sanlaville, Muga Nishizawa, Alexey Loubyansky, Saori Oki,
  365. Andreas Salathe, Dante Torres estrada, S. Pam, Nuno Santos,
  366. Denis Taye, and Colin Sampaleanu
  367. for their contributions.
  368. <p><br>
  369. <hr>
  370. <a href="http://www.is.titech.ac.jp/~chiba">Shigeru Chiba</a>
  371. (Email: <tt>chiba@acm.org</tt>)
  372. <br>Dept. of Math. and Computing Sciences,
  373. <a href="http://www.titech.ac.jp">Tokyo Institute of Technology</a>