ant newbie question

Discussion in 'Java' started by Ann, Nov 6, 2004.

  1. Ann

    Ann Guest

    New to ant, I am.
    This seems like it should be simple, but I have
    not been able to find it in the ant documentation.
    If it is there, a pointer will suffice.

    I built a jar file that includes two gif files.
    The gif files are actually in the jar file.
    The names of the gif files are in
    META-INF/INDEX.LIST
    One of the classes uses the gif files like this:
    ImageIcon leafIcon = new ImageIcon("TABLE_ICON.gif");
    I run the jar file: "java -jar NewDraw.jar"
    It runs fine, but the gif files don't show up,
    it appears it is not finding them and using the default.
    If I extract the gif files into the same directory
    as the jar file, they are found and used.

    What change is needed to avoid the extraction?
    Here is my bulid.xml file
    -------------------------------
    <project name="NewDraw" default="compile" basedir=".">

    <target name="compile">
    <javac srcdir="src"
    destdir="bin"
    debug="on"
    />
    </target>

    <target name="jar" depends="compile">
    <jar destfile="NewDraw.jar"
    basedir="bin"
    includes="**/*.class"
    index="true"
    >

    <fileset dir="src"
    includes="**/*ICON*.gif"
    />
    <fileset dir="src"
    includes="fileNotFound.jpg"
    />
    <fileset dir="src"
    includes="viewlist.txt"
    />
    <manifest>
    <attribute name="Built-By" value="${user.name}"/>
    <attribute name="Main-Class" value="NewDraw"/>
    </manifest>
    </jar>
    </target>

    <target name="run" depends="jar">
    <java classname="NewDraw"
    classpath="NewDraw.jar"
    fork="true"
    />
    </target>

    </project>
    Ann, Nov 6, 2004
    #1
    1. Advertising

  2. Ann

    Real Gagnon Guest


    > One of the classes uses the gif files like this:
    > ImageIcon leafIcon = new ImageIcon("TABLE_ICON.gif");


    try with something like

    URL url = this.getClass().getResource("myIcon.gif");
    ImageIcon leafIcon = new ImageIcon(url);

    Bye.

    --
    Real Gagnon from Quebec, Canada
    * Looking for Java or PB snippets ? Visit Real's How-to
    * http://www.rgagnon.com/howto.html
    Real Gagnon, Nov 7, 2004
    #2
    1. Advertising

  3. Ann

    Tony Morris Guest

    Nothing to do with Ant and everything to do with class loaders.
    Look up the method getResource of java.lang.Class.

    --
    Tony Morris
    http://xdweb.net/~dibblego/
    Tony Morris, Nov 7, 2004
    #3
  4. Ann

    Ann Guest

    works great! thanks guys

    "Real Gagnon" <realgagnon_@_yahooSpamIsBadSstripunderscore.com> wrote in
    message news:Xns9599DFC2D5424realhowtowwwrgagnonc@140.99.99.130...
    >
    >
    > > One of the classes uses the gif files like this:
    > > ImageIcon leafIcon = new ImageIcon("TABLE_ICON.gif");

    >
    > try with something like
    >
    > URL url = this.getClass().getResource("myIcon.gif");
    > ImageIcon leafIcon = new ImageIcon(url);
    >
    > Bye.
    >
    > --
    > Real Gagnon from Quebec, Canada
    > * Looking for Java or PB snippets ? Visit Real's How-to
    > * http://www.rgagnon.com/howto.html
    Ann, Nov 7, 2004
    #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. Chris Bedford
    Replies:
    6
    Views:
    2,213
  2. jose luis fernandez diaz

    Ant newbie question

    jose luis fernandez diaz, Feb 16, 2004, in forum: Java
    Replies:
    0
    Views:
    460
    jose luis fernandez diaz
    Feb 16, 2004
  3. john martin
    Replies:
    2
    Views:
    2,204
    john martin
    Apr 7, 2005
  4. Replies:
    1
    Views:
    487
    Larry
    Mar 7, 2006
  5. Replies:
    6
    Views:
    861
Loading...

Share This Page