Using bcel to modify .class file

i want to modfiy all the methods in a class so that when they returns the will print a message. a part of the code is shown below
String mesg = "Hello from " + Utility.methodSignatureToString(m.getSignature(),
                                        name,
                                        Utility.accessToString(flags));
InstructionList patch = new InstructionList();
patch.append(new GETSTATIC(out));
patch.append(new PUSH(cp, mesg));
patch.append(new INVOKEVIRTUAL(println));
MethodGen mg = new MethodGen(m, class_name, cp);
InstructionList il = mg.getInstructionList();
InstructionHandle[] ihs = il.getInstructionHandles();
for(InstructionHandle ih:ihs)
if(ih.getInstruction().toString().indexOf("return")!=-1)
il.append(ih,patch);
the problem with this is the for each loop is modifying only the first return statement encountered in the function.
what should i do?

Hi,
I'm running into the same problem deploying the classes generated by the class generator. Code works fine from JDeveloper, but had to put my DTD in the directory where my classes are. Deploying the classes with Apache's JServ gives me a NullPointer exception on the first addNode method. I guess it can't find the DTD. I tried to put the DTD in many locations but this didn't fix the problem. Any suggestions?
Steve,
Did you fix this problem? Thanx!
null

Similar Messages

  • Update jar file with modified class files

    hi all,
    I'm developing a jar utility for updating a jar file with modified class files as of now i have reached a point where in i can browse files and set it to required location
    i.e i have developed a swings GUI application using JfileChooser and browse the files ..now my requirement is to update the jar files with modified class file
    GUI looks like below
    ....enter the modified class file ----> d:\c.class
    ....enter the jar file path ---> d:\a.jar
                                                          update button now i have the requirement as
    1> when i click on the update button ,my jar file (a.jar) should get updated with the latest class file (c.class)
    can u help me to achieve this requirement.???
    im stuck with this,,,if u can provide me wit the code for updating jar file with latest class file...it will really be helpful
    if u can help me with the code on click on update button it will be really helpful
    Thanks and expecting a faster response from u all java experts....

    Please find my query in bolds...i have written the partial code now,i need some help now
    hope u guys can help me out...
    import javax.swing.*;
    import java.awt.*;
    import java.awt.event.*;
    import java.io.File;
    public class FileExplorer extends JDialog implements ActionListener
         JTextField txtLocation_class;
         JButton btnBrowse_class;
         JLabel label_class;
         JTextField txtLocation_jar;
         JButton btnBrowse_jar;
         JLabel label_jar;
         JButton updatebutton;
         public FileExplorer()
                   setSize(600,300);
                   //for class files
                   label_class = new JLabel("Please select Modified Class File");
                   txtLocation_class= new JTextField(20);
                   btnBrowse_class = new JButton("Browse");
                   btnBrowse_class.addActionListener(this);
                   //for jar files               
                   label_jar = new JLabel(" Please select the Jar file");
                   txtLocation_jar= new JTextField(20);
                   btnBrowse_jar = new JButton("Browse");
                   btnBrowse_jar.addActionListener(this);
                   ActionListener updateListener = new ActionListener(){
                    public void actionPerformed(ActionEvent ae){
                     if(ae.getActionCommand().equalsIgnoreCase("Update")){               
                      System.out.println("ae.getActionCommand() :: "+ae.getActionCommand());
                      System.out.println("Update Button is pressed");               
                    *//Query :how do i access FilePath and FilePath1 here which*
    *                // has been set in public void actionPerformed(ActionEvent ae)*
    *                //method below*
    *                // FilePath  ---??*
    *                // FilePath1  ---??*
    *                // how do i access the above 2 parameters*
    *                //Query :on click of update button i have to pass*
    *                //two parameters FilePath and FilePath1 to*
    *                //perform some functionality. please help me*
    *                //to achieve this..how do i access Filepath and Filepath1*
    *                //here which has been set below.*
                     } // end of if               
                   } // end of actionPerformed
                };// end of ActionListener
                  updatebutton = new JButton("Update");
                  updatebutton.addActionListener(updateListener);
                   //adding to the panel               
                   JPanel pnl = new JPanel();
                   pnl.add(label_class);
                   pnl.add(txtLocation_class);
                   pnl.add(btnBrowse_class);
                   pnl.add(label_jar);
                   pnl.add(txtLocation_jar);
                   pnl.add(btnBrowse_jar);
                  pnl.add(updatebutton);
                   getContentPane().add(pnl);                         
         public void actionPerformed(ActionEvent ae)
              Object obj=ae.getSource();
              if(obj==btnBrowse_class)
                   final JFileChooser fcstudent = new JFileChooser();
                   int rtrnval = fcstudent.showOpenDialog(this);
                   if(rtrnval==JFileChooser.APPROVE_OPTION)
                        try
                             File file=fcstudent.getSelectedFile();                         
                             String path = file.getPath();
                             System.out.println("This is Path:"+path);
                             txtLocation_class.setText(""+path);
                             String FilePath=txtLocation_class.getText();
                             System.out.println("FilePath is ::"+FilePath);                                        
                        catch(Exception ex)               
                             ex.printStackTrace();
              }else if(obj==btnBrowse_jar){
                             final JFileChooser fcstudent = new JFileChooser();
                             int rtrnval = fcstudent.showOpenDialog(this);
                             if(rtrnval==JFileChooser.APPROVE_OPTION)
                                  try
                                       File file=fcstudent.getSelectedFile();                         
                                       String path1 = file.getPath();
                                       System.out.println("This is Path:"+path1);
                                       txtLocation_jar.setText(""+path1);
                                       String FilePath1=txtLocation_jar.getText();
                                       System.out.println("FilePath is ::"+FilePath1);                                        
                                  catch(Exception ex)               
                                       ex.printStackTrace();
         public static void main(String arg[]){
                   FileExplorer Exm= new FileExplorer();
                   Exm.setVisible(true);
    }

  • Tomcat Web-server uses old .class files

    Hi Friends,
    My Tomcat webserver uses old .class files. The problem persists even if I delete old class files. The new ones are formed but then if i again recompile, the new-old ones are used :)
    Am I doing something wrong????
    Please suggest!!

    I have experienced this problem before as well. Tomcat seems to cache compiled class files for better speed. To get Tomcat to reload class files that I've recently recompiled here is what I do:
    1. Go into the Tomcat server administration area (http://localhost/admin)
    2. Choose the context that is using the classes that you want to reload (from Service / Host)
    3. Make sure reloadable is set to true
    3. Click save, and then commit changes
    Hope this helps, but if there is a better way to get Tomcat to use the most recent class files I would love to hear it!

  • Hot deployment of class files (non-EJB)

     

    Also posting to the servlet newsgroup.
    "Craig Ambrose" <[email protected]> wrote in message
    news:[email protected]..
    >
    I am using WebLogic 6.1 and am interested in using auto-deployment indevelopment
    mode of JSPs and class files that those JSPs rely on. I have a simpleWebLogic
    application that gets deployed using the exploded directory format andwhen I
    modify the JSPs or the class files that they use everything reloadsproperly and
    a newly modified class file will be reloaded the next time the pageutilizing
    the Java class is requested.
    I have a much more complicated application (the one I am really doing workon)
    and I can't get the hot deploy of the class files to take effect. The JSPswill
    reload but I can't seem to cause the class loader to reload any changedclass
    files. If I use the WebLogic Console and un-deploy and then re-deploy theapplication
    then the class files will be reloaded, but I thought that wasn't necessaryfor
    hot deployment. This complex application stores many things in the HTTPsession
    context. I am wondering if that has an effect on the class loader fordependant
    class files.
    I'm pretty sure it is not a configuration issue as I have it working forthe simple
    application. I have the application deployed under the.\config\<domainname>\applications
    directory and am using the exploded directory format with the class filesalso
    exploded in the WEB-INF\classes directory.
    Any insights on dependancies of the hot depployment would be helpful.

  • How can I hide constant variable value in class file?

    hi,everybody.
    I am having a problem with constant variable which define connectted with database(URL,username,password).
    when I used UltraEdit to open class file, I can see constant variable value.
    Thanks!

    OK, let's see. Firstly, if I may correct your terminology, the phrase "constant variable" is a paradox (I think that is the right word). You have either one of the other. You declaration is either 'constant' or 'variable' (ie: it can change at run-time or it doesn't). People often use the term 'variable' and 'declaration' interchangably which is where the confusion lies.
    Anyway, onto the real problem. It seems that you want to protect your connection details (in particular the password, I would guess). Unfortunately, Java compiles not to machine-code, but byte-code which is semi-human-readable. So people, if they are inquisitive enough, will always be able to see it if they try hard enough.
    You can do one of two things:
    (1) Get an 'obfusticator'. An obfusticator is something that you run over Java source files and it completely messes it up (without modifying functionality). You then compile and the original source is such gibberish that the byte-code is very difficult to understand. However, the password will still be in there somewhere.
    (2) Don't put sensitive information into your source. Have this kind of info in external files (encrypted) and allow your class to read this file, decrypt, and use it.
    Hope that helps.
    Ben

  • Where to put class files

    hi,
    i use Tomcat v4.0.5, my jsp files import some classes. i put these classes to /classes folder under /jakarta-tomcat-4.0.5 base directory. but when i make some changes to these classes, i have to restart the Tomcat. i think there must be some other folders to put these class files and there wont be need any more to restart Tomcat.

    Hi
    It is necessary to restart your Tomcat if you are modifying class files, because tomcat will build a cache for the previously compiled classes and objects. As you are under development this is of no harm.
    And one more thing place any classes in the WEB-INF/classes directory of your tomcat application.
    Thanks
    Swaraj

  • How can I change the time of photos in info in iPhoto for iOS. I've done it in iPhoto for Mac but when I sync to my ipad the info field goes back to the camera time ignoring "modify original files" in iPhoto for Mac?

    I used "adjust date and time" and"modify original files" to correct the time of photos taken on a camera used in Peru which was set to UK rather than local time. which is 6 hours  behind. This was to bring them into line with shots taken with other cameras set to local time. This was using iphoto 08 on a Mac. I then synced to my iPad. The photos stayed in the correct order in photos but in iphoto (iOS version) the original dates appear (the camera dates) and so the photos are out of chronological order again. This looks like a bug but is there a fix?

    don't know what you mean by "write to master" but speculate that it means modify the original times, in which case the taken times on the camera should no longer be present
    No,I meant your using the option "modify original files" will do exactly that - change the capture date original master files stored in the iPhoto library. Only when you do that, the "date modified" of your original files will be changed as well, and it will now be the date of your manipulation of the capture date.
    Oh - I hadnt considered that possibility - but of that were the case, why don't my manipulated photos go to the end of the sequence as I have done all the manipulation after the end of the holiday??
    In photos the synced album maintains the chronological order which I set up on the mac by modifying the originals, as you said,
    That is what the linked article is describing: "some apps may sort your photos in the order you specify in the app (such as iPhoto or Aperture"
    The problem I have is that, in the album, iphoto (ipad) sorts them differently to both iphoto (Mac) and the photos tab on the ipad
    In addition to albums and events, synced photos appear in a unified category called Photo Library (on iPad, this is the Photos tab). Photos are not duplicated. This category will also sort photos in ascending order by the date modified.
    "on ipad this is the Photos tab" - but this displays as per the original sequence ignoring time adjustments - the manipulations seem to be ignored (but are reflected in the album in the photos tab) and the photos tahat have been modified stay in their original positiom - they don't get put the end
    Because the library uses a different date - the date modified - the date of the last time the file has been changed in any way - any editing you do to your image, including adjust date and time will change the "date modified"
    This may change the sorting of the database but it appears not to influence the order in the albums
    In addition to albums and events, synced photos appear in a unified category called Photo Library (on iPad, this is the Photos tab). Photos are not duplicated. This category will also sort photos in ascending order by the date modified.
    So how can i get my photos in date and time order in an album in iphoto for ipad?
    Thanks for your help

  • How to put the ".class" file in Memory with Javac?

    The J2SE 6 RC have an tool : javax.tools.JavaComplier. I can use it to compile the source code in memory( I implemented an JavaFileObject).
    But the compiler aways put the output file(.class) to file system. It;s not my want to do . I am writing an IDE ,I use javac to determine the code error after the user's typing. So complier is used a lot , writing to file system is a time consuming job.
    I also want to use the byte code(".class" file) for reflection , so if the JavaCompiler can put the output file in memory and then I can reflect it.
    My current solution is puting the output file to file system then use Class.forName() to reload it in memory then reflect it. It seems a useless IO operation with file system.
    How can I do with it?
    Thanks!

    Those 'useless' I/O operations are one or two out of thousands that are implied by compiling a Java source file.
    I wouldn't worry about it.

  • In PI 7.1 - Java UDF's Compiled Class files - Jar File location

    Hi All,
    In PI 7.1 Does anybody know where the compiled Java UDF's (which are used in Graphical mapping) class files stored in jar are located in integration server? I want to use this jar file in my XSLT mapping.

    Hi,
    I guess it would be under
    \usr\sap\<SID>\DVEBMGS00\j2ee\cluster\server0\temp\classpath_resolver
    or
    \usr\sap\<SID>\DVEBMGS00\j2ee\cluster\server0\.\temp\classpath_resolver
    Where SID is your XI instance name.
    Thanks,
    Gujjeti
    Edited by: Praveen Gujjeti on Jun 23, 2008 5:12 PM

  • Tomcat6 does not load class files from WEB-INF/lib/myjarfile.jar  WHY???

    I have placed my jar file in c:\tomcat6\webapps\my-application\WEB-INF\lib\myjarfile.jar
    But, after restarting tomcat6, when i try to import the class file contained in the myjarfile.jar in a servlet, it says
    ProcessFileUpload.java:4: package test.test1 does not exist
    import test.test1.*;
    ^It clearly tomcat's class loading problem.
    As i unzipped my jar and placed the packagefolder structure to
    c:\tomcat6\webapps\my-application\WEB-INF\classes\testand it works perfectly.
    Anyone knows its workaround? please suggest if any configuration changes is required in tomcat or so.
    Thanks.
    ---Sujoy

    Thank you gimbal2 . There was error in creating the jar file myjarfile.jar.
    But, now I have created it again and placed it in place
    c:\tomcat6\webapps\my-application\WEB-INF\lib\myjarfile.jarand tried to use one on the Class file included within the jar to compile my servlet. But, still I am getting error at servlet compilation time. I want to place executable jar files in
    c:\tomcat6\webapps\my-application\WEB-INF\lib\myjarfile.jar and compile my servlet and execute the servlet.
    I DO NOT WANT TO unzip the jar, placing all unzipped files to
    c:\tomcat6\webapps\my-application\WEB-INF\classes\ folder and comiple my servlet and execute the servlet. But, I am failing to user WEB-INF\lib\ folder facility....please help me why i am not getting class files from WEB-INF\lib\ folder.
    If you please see the small code bit and tell me any possible error that would be very helpful.
    Step 1: my library java file MyClass.java
    package test.test1;
    public class MyClass {
         String myName = "Default return string value";
         public void setMyName(String varName) {
              this.myName = varName;
         public String getMyName() {
              return this.myName;
    }Step2 : Creating jar file of my library class files
    C:\jdk1.6\bin>jar cvf myjarfile.jar test
    added manifest
    adding: test/(in = 0) (out= 0)(stored 0%)
    adding: test/test1/(in = 0) (out= 0)(stored 0%)
    adding: test/test1/MyClass.class(in = 452) (out= 296)(deflated 34%)
    adding: test/test1/MyClass.java(in = 230) (out= 140)(deflated 39%)
    C:\jdk1.6\bin>Step3 : Double checking the created jar file content by listing its content
    C:\jdk1.6\bin>jar tf myjarfile.jar
    META-INF/
    META-INF/MANIFEST.MF
    test/
    test/test1/
    test/test1/MyClass.class
    test/test1/MyClass.java
    C:\jdk1.6\bin>Step4 : Placed myjarfile.jar to
    c:\tomcat6\webapps\my-application\WEB-INF\lib\Step5 : Restarted standalone Tomcat6 in my Windows XP SP2.
    Step6 : Created a simple servlet LibFolderTest.java within my-application\WEB-INF\classes\ folder with code
    import java.io.*;
    import javax.servlet.*;
    import javax.servlet.http.*;
    import test.test1.*;
    public class LibFolderTest extends HttpServlet {
         public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
              response.setContentType("text/html");
              PrintWriter out = response.getWriter();
              MyClass mc = new MyClass();
              out.println(mc.getMyName());
    }Step7 : Tried to compile my servlet LibFolderTest.java and got the following error
    LibFolderTest.java:4: package test.test1 does not exist
    import test.test1.*;
    ^
    LibFolderTest.java:11: cannot find symbol
    symbol  : class MyClass
    location: class LibFolderTest
                    MyClass mc = new MyClass();
                    ^
    LibFolderTest.java:11: cannot find symbol
    symbol  : class MyClass
    location: class LibFolderTest
                    MyClass mc = new MyClass();
                                     ^
    3 errorsThe above servlet compilation error on Step7 is telling me that myjarfile.jar is not loaded by Tomcat6 or not available for use when compiling servlet. I want to use myjarfile.jar from within WEB-INF\lib\ folder but I can not. please help.
    ---Sujoy

  • Java version for class file

    i have some class files, and i need to know what Java compiler used to compiled that class file (only care for the version number...like 1.4.2, 1.5.0, 1.1.0, etc)
    any one know how i can get this info? or any good google keywords?

    thanx, since now i know how the class file bytes are set up..i guess i can get the version number by looking at the hex.
    tedious (but not that tedious)...thought there be a simplier way...oh well..
    thanx again

  • Java version from class file

    How to decide from class file that which java version (1.3, 1.4 etc) was used to compile it?

    Sorry I made a mistake,
    its minor, major
    Dont we have some utility given by Sun for this?
    javap -verbose <classname>will print out versions plus more...
    Do I need to use InputStream for reading class file then see the version?
    DataInputStream din = new DataInputStream(new FileInputStream(classFile));
    din.readInt();
    short minor = din.readShort();
    short major = din.readShort();Why do you need to do this?

  • Problems trying to "hot-deploy" class files in iPlanet. Want to deploy a compiled class (i.e. servlet, jsp) without having to bounce the server. Known issue in iPlanet? How can I get around?

    Currently iPlanet is not allowing us to hot deploy a modified class file(i.e., servlet) as it advertises. It doesn't seem to have a problem with jsp's however. But everytime we modify a servlet(say in an emergency), and wish to deploy, we still have to bounce the KJS. We would like to avoid this if possible. How? I heard this might be a known issue in iPlanet.

    I apologize but this is a clarification of this problem. We are having a problem dynamically reloading java classes that are referenced by jsp's and servlets. The problem DOES NOT exist when trying to reload jsps or servlets themselves. We would like to reload these classes without having to restart the processes. Any thoughts would be helpful. Thanks.

  • Reflection - reading a .class file

    I want to read in a .class file, and be able to use reflection to get a list of that class's methods. I'm using a JFileChooser to find the file, I just need to know how to use the output from the JFileChooser (a path to the file) to load the file into the program, and use reflection methods to create an appropriate Class object.

    kajbj wrote:
    fredley_m wrote:
    kajbj wrote:
    fredley_m wrote:
    I don't think I'm making myself clear. I can read in a file, I don't know how to use reflection on a .class file. I need to know how to complete the following line of code:
    Class reflectedClass =reflectedClass should then contain a copy of the class from the .class file.You load a class using Class.forName(..)This does not work.
    JFileChooser fc = new JFileChooser();
    int returnVal = fc.showOpenDialog(main_panel);
         if(returnVal == 0)
              String fileName = fc.getSelectedFile().getName();
              fileName = fileName.substring(0,fileName.lastIndexOf('.')); //also doesn't work without this line
              Class c = Class.forName(fileName);
    ...I get a ClassNotFoundException when I try to open MyClass.classYou need to know about how class loaders work, and use one. Read the javadoc:
    [http://java.sun.com/javase/6/docs/api/java/lang/ClassLoader.html]
    The NetworkClassLoader sample is pretty close to what you want.Thanks, the URLClassLoader is perfect, however my code:
    String fileName = fc.getSelectedFile().getName();
    fileName = fileName.substring(0,fileName.lastIndexOf('.'));
    URL[] urls = {new URL(filePath)};
    URLClassLoader cl = new URLClassLoader(urls);
    Class c = cl.findClass(fileName);does not compile: "findClass has protected access"

  • Problems on zipping and unzipping class files

    I am trying to add a class file to a new jar file using FileInputStream and JarOutputStream.
    I am getting a very unique problems.
    when I read a class file using FileInputStream from my local hard disk I am getting 30 bytes less than then actual file size (the difference in bytes is exactly 30 bytes for any file, either class or xml or java, I dont understand this concept). after reading the contents I am writing the bytes read to a jar file using JarOutputStream. This all gets done fine. But when I extract the class file written into the jar file and try to run the class it is giving me the exception as follows:
    java.lang.ClassNotFoundException: com.wipro.flowbrix.plugins.factory.NewClass
    Exception in thread "main" java.lang.ClassFormatError: com/wipro/flowbrix/plugins/factory/NewClass (Bad magic number)
    at java.lang.ClassLoader.defineClass0(Native Method)
    at java.lang.ClassLoader.defineClass(Unknown Source)
    at java.security.SecureClassLoader.defineClass(Unknown Source)
    at java.net.URLClassLoader.defineClass(Unknown Source)
    at java.net.URLClassLoader.access$100(Unknown Source)
    at java.net.URLClassLoader$1.run(Unknown Source)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    at java.lang.ClassLoader.loadClassInternal(Unknown Source)
    at java.lang.Class.forName0(Native Method)
    at java.lang.Class.forName(Unknown Source)
    The classpath to the folder from where I am running the file is set. I have double checked the classpath.
    any information or solutions regarding this would be of great help.

    A "magic number" is a short sequence of data at the beginning of a file used to identify the file. ".class" files, for instance, always start with OxCA, 0xFE, 0xBA and 0xBE.
    If the 30 bytes missing are at the beginning of your file, there's nothing suprising in getting a "ClassFormatError" exception.
    I think we should concentrate on your first problem. Can you post the code used to add the class file, please?
    /Stephane

Maybe you are looking for

  • How can I print just a select/highlighted portion of a webpage/email? FF prints EVERYTHING on each page, wasting ink.

    I switched form IE to FF. In IE, I could select text (or photos) and print just the portion of web pages and emails that I wanted, thus saving paper and ink. I have not been able to do that with FF. I have to print all of each page, so text, ads, and

  • CS4 Bridge Keywords - Delete when Bridge is close.

    Greetings I have gone through and applied keywords to hundreds of images, along with a respective Hierarchy KeyWords as well. As long as Bridge remains open and my computer is on I have access to sort, and find files based on Keywords. "Close Bridge"

  • How to send mail using Java Server Pages(JSP)

    Plz reply me the code for it and send me mail

  • Jspx template migration to jsf 2 problematic

    Hello experts, I have a ADF web application developed with JDeveloper 11.1.1.4 using JSF 1.2 deployed on WebLogic server 10.3.4. When I migrate to the new version jsf 2: Build JDEVADF_11.1.2.2.0_GENERIC_120418.2212.6183.1 and WebLogic server 10.3.5,

  • Utilization Report

    Hi all, I need to prepare a utilization report(in WebDynpro) which accepts two dates(start date and end date) as input and gives the output as follows: ex: St.date : 10/04/2006      End Date: 30/05/2006                April                May