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.

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