Results 1 to 1 of 1
  1. #1
    angryboy's Avatar
    angryboy is offline Senior Member
    Join Date
    Jan 2009
    Posts
    742
    Rep Power
    6

    Cool FYI: Ant-Netbean Dependency Issues & The Fix

    There seems to be a problem w/ ant, that it can't recompile those classes that depend on an interface which has changed.
    To illustrate:
    Java Code:
    public class Test implements TestInterface{
      public static void main(String[] args){
        System.out.println(VALUE);
        System.out.println(NAME);
        System.out.println(obj);
      }
    }
    Java Code:
    public interface TestInterface {
      int VALUE = 5;
      String NAME = "FOO";
      Object obj = null;
    }
    the build file:
    Java Code:
      <target name="compile" depends="init" description="Compiles src files.">
        <mkdir dir="${classes.dir}"/>
        
        <depend srcdir="${src.dir}" destdir="${build.dir}" 
          cache=".depcache" closure="true">
            <include name= "**/*.java"/>    
        </depend>
    
        <javac srcdir="${src.dir}" destdir="${classes.dir}"
          deprecation="true" optimize="true" fork="true"/>
      </target>
    First run:
    Java Code:
    A:\>ant clean run
    Buildfile: build.xml
    init:
    clean:
    init:
    compile:
        [mkdir] Created dir: A:\build\classes
        [javac] Compiling 2 source files to A:\build\classes
    run:[b]
         [java] 5
         [java] FOO
         [java] null
    [/b]
    BUILD SUCCESSFUL
    Total time: 8 seconds
    A:\>
    Now edit the interface and recompile
    Java Code:
    public interface TestInterface {
      int VALUE = 99;
      String NAME = "BAR";
      Object obj = "Hello World!";
    }
    Java Code:
    A:\>ant run
    Buildfile: build.xml
    init:
    compile:[b]
       [depend] The class classes.Test in file A:\build\classes\Test.class is out of
     date due to TestInterface but has not been deleted because its source file could
     not be determined[/b]
        [javac] Compiling 1 source file to A:\build\classes
    run:[b]
         [java] 5
         [java] FOO
         [java] Hello World!
    [/b]
    BUILD SUCCESSFUL
    Total time: 6 seconds
    A:\>

    The Fix:
    Use an external lib: JMake (was JavaMake).
    src only: The jmake utility &mdash; Project Kenai
    bin attached below...
    Java Code:
      <target name="compile" depends="init" description="Compiles src files.">
        <mkdir dir="${classes.dir}"/>
        
        <taskdef name="jmake" classpath="jmake.jar"
          classname="com.sun.tools.jmake.ant.JavaMake"/>
          
        <jmake srcdir="${src.dir}" destdir="${classes.dir}"
          deprecation="true" optimize="true" fork="true"
          pdbFilename=".depcache/jmake.pdb"
          failondependentjar="true"/>
      </target>
    On second run after "ant clean run" using jmake
    Java Code:
    A:\>ant run
    Buildfile: build.xml
    init:
    compile:
        [jmake] Jmake version 1.3.5
        [jmake] Opening project database...  Done.
        [jmake] Compiling 1 source file to A:\build\classes
        [jmake] Checking TestInterface
        [jmake] Compiling 1 source file to A:\build\classes
        [jmake] Checking Test
        [jmake] Writing project database...  Done.
    run:[b]
         [java] 99
         [java] BAR
         [java] Hello World!
    [/b]
    BUILD SUCCESSFUL
    Total time: 10 seconds
    A:\>


    Now what if this is used on netbeans, would it be faster not having to call "ant clean" on every build?
    I'll leave that test to IDE users...
    Attached Files Attached Files
    USE CODE TAGS--> [CODE]...[/CODE]
    Get NotePad++ (free)

Similar Threads

  1. Replies: 1
    Last Post: 03-31-2009, 05:04 PM
  2. Replies: 5
    Last Post: 08-16-2008, 04:33 PM
  3. Maven Dependency Overview 1.1
    By Java Tip in forum Java Software
    Replies: 0
    Last Post: 07-02-2008, 07:13 PM
  4. Maven Dependency Overview 1.0
    By Java Tip in forum Java Software
    Replies: 0
    Last Post: 04-15-2008, 06:52 PM
  5. Dependency Analyzer 1.0.3-rc0
    By levent in forum Java Software
    Replies: 0
    Last Post: 07-30-2007, 04:34 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •