Methodology to remove unused classes?

Discussion in 'Java' started by wgblackmon@yahoo.com, Aug 21, 2006.

  1. Guest

    My team needs to get rid of classes in a large application that are no
    longer used. There are around 1500 class files in total and we estimate
    that about 25% of these classes are no longer used. Is there some type
    of tool that can identify classes that have been run during a certain
    time period or some way to identify these classes other then removing
    them from a build and getting compliation errors? We are using Eclipse
    as a development tool and Tomcat as a server.
     
    , Aug 21, 2006
    #1
    1. Advertising

  2. wrote:
    > My team needs to get rid of classes in a large application that are no
    > longer used. There are around 1500 class files in total and we estimate
    > that about 25% of these classes are no longer used. Is there some type
    > of tool that can identify classes that have been run during a certain
    > time period or some way to identify these classes other then removing
    > them from a build and getting compliation errors? We are using Eclipse
    > as a development tool and Tomcat as a server.


    Could you check the access times of the class files?

    ls -Rt
    (or) dir /s /od
     
    Jeffrey Schwab, Aug 21, 2006
    #2
    1. Advertising

  3. wrote:
    > My team needs to get rid of classes in a large application that are no
    > longer used. There are around 1500 class files in total and we estimate
    > that about 25% of these classes are no longer used. Is there some type
    > of tool that can identify classes that have been run during a certain
    > time period or some way to identify these classes other then removing
    > them from a build and getting compliation errors? We are using Eclipse
    > as a development tool and Tomcat as a server.


    If you compile with javac just specifying you entry classes, then only
    reachable classes will be compiled.

    If it's a simple webapp then the entry classes will be servlets,
    filters, any listeners in web.xml and any you obtain through
    Class.forName. I guess JSPs could potentially reference other classes.
    IIRC, Jasper will save the .java files, so they can be specified too.

    Once you have all of that compiled, list the class files into a text
    file. Use you favourite editor (sed, say) and search and replace to
    remove .class and anything from a $. Then do another search and replace
    to make it into a shell/batch file to move your used source files from
    one directory to another.

    Tom Hawtin
    --
    Unemployed English Java programmer
    http://jroller.com/page/tackline/
     
    Thomas Hawtin, Aug 21, 2006
    #3
  4. wrote:
    > My team needs to get rid of classes in a large application that are no
    > longer used. There are around 1500 class files in total and we estimate
    > that about 25% of these classes are no longer used.


    What is it what you want to remove? You say "class files", this
    typically means compiled java source code in files ending with .class,
    or do you eman source code (.java files)?

    If it is the first, remove them all and recompile. If it is the second,
    also remove all .class files, compile your main class, let the java
    compiler find the dependencies, check which .class files it had
    generated and take the corresponding .java files for a start. You might
    need some more files, depending on how your application loads classes.

    Oh, and improve your configuration management procedures to avoid such
    problems in the future.

    /Thomas
    --
    The comp.lang.java.gui FAQ:
    ftp://ftp.cs.uu.nl/pub/NEWS.ANSWERS/computer-lang/java/gui/faq
    http://www.uni-giessen.de/faq/archiv/computer-lang.java.gui.faq/
     
    Thomas Weidenfeller, Aug 22, 2006
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Joey
    Replies:
    18
    Views:
    7,102
    Ingo R. Homann
    Jul 19, 2006
  2. Replies:
    32
    Views:
    1,696
    dgutson
    Sep 15, 2012
  3. Scott M.

    Remove Unused References?

    Scott M., Sep 13, 2008, in forum: ASP .Net
    Replies:
    0
    Views:
    430
    Scott M.
    Sep 13, 2008
  4. ton
    Replies:
    5
    Views:
    1,406
    Scott M.
    Feb 2, 2010
  5. Gerhard Haslberger

    tool/idea to "opimize" code / remove unused methods

    Gerhard Haslberger, Aug 6, 2008, in forum: Perl Misc
    Replies:
    1
    Views:
    113
    Ben Morrow
    Aug 6, 2008
Loading...

Share This Page