ant newbie question

A

Ann

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>
 
R

Real Gagnon

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.
 
T

Tony Morris

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

Ann

works great! thanks guys

Real Gagnon said:
try with something like

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

Bye.
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,535
Members
45,007
Latest member
obedient dusk

Latest Threads

Top