Code Generation FAQ

  1. How do I install asm in eclipse ?
  2. How do I set the classpath ?
  3. What if I don't use eclipse?

horizontal rule

How do I install asm in eclipse ?

The first thing you need to do is download asm-3.1.jar from asm.objectweb.org and add it to your project's buildpath. There are several ways to do this--try rightclicking on your project and selecting "add external archive".  Then browse to and select the jar file, etc.  After you do this, SimpleImageDemo should work.

To have the bytecode viewer and "asmifier" available, you need to download the eclipse plugins.  From the Help menu across the top, select "Software Updates".  Then select "Available Software".  Add the update site http://andrei.gmxhome.de/eclipse, select the appropriate plugin for whatever version of eclipse you are using, and click install. When this is done, you should be able to open a bytecode viewer window by going to the "Window" menu, select "Show view" and "ByteCode".  You might have to select "Other" before you see "ByteCode".

 

Back to Top

horizontal rule

How do I set the classpath?

Java uses the classpath to know where to look for class and jar files. First, find the complete paths to the directories containing the classfiles or jar file you need and add these to your classpath. You can do this permanently (go to control panel-->
system-->advanced-->environment variables)  or explicitly give it on the command line every time--something like

java -classpath .;c:\the\path\to\dir0;c:\xxx.jar  test1 image0.jpg

. is the current directory
entries in the list are separated by ;

java -help
gives you info about all the command line options for java.

 

Back to Top
 
 

horizontal rule

What if I'm not using eclipse?

I'm not aware of asm plugins for other IDEs.  However,  you really only need two things, neither of which require eclipse.  First, you want to be able to look at the bytecode.  You can do this with javap.  Second, it is sometimes helpful to see "asmified" code.  The org.objectweb.asm.util.ASMifierClassVisitor class will show you this.  It contains a main method that takes a class file as a command line parameter and print the asmified code to the console.  

 

 

Back to Top

 


Revised: November 10, 2008 .