> -----Original Message-----
> From: Rick Mann [mailto:[EMAIL PROTECTED] 
> Sent: Thursday, 5 January 2006 8:03 PM
> To: Ant Users List
> Subject: Re: Loading resources from my task's JAR?
> 
> 
> On Jan 5, 2006, at 1:04 AM, Steve Loughran wrote:
> 
> > this should work. make sure you have put the template into 
> the JAR.  
> > the <jar> task may need to explicitly ask for it, or you should be 
> > using <copy> to copy the files from their source dir to 
> build/ classes 
> > or wherever.
> >
> > I would have an "unjar" target that used <unjar> to unjar a 
> jar just 
> > built, so you can see what is going on. Once you are 100% sure that 
> > the resource is going in, then you can worry about classloading.
> 
> I have verified this. Here's the output of jar tf:
> 
> $ jar tf targets/task/dbgen-1.1.jar
> META-INF/
> META-INF/MANIFEST.MF
> com/
> com/mycompany/
> com/mycompany/tools/
> com/mycompany/tools/dbgen/
> com/mycompany/tools/dbgen/BaseClass.tmpl          <--
> com/mycompany/tools/dbgen/Class.tmpl              <--
> com/mycompany/tools/dbgen/Column.class
> com/mycompany/tools/dbgen/DBClassGenerator.class
> com/mycompany/tools/dbgen/DBClassGeneratorCLI.class
> com/mycompany/tools/dbgen/DBGenAntTask.class
> com/mycompany/tools/dbgen/PInterface.tmpl         <--
> com/mycompany/tools/dbgen/Table.class
> 
> The System property java.class.path does not contain my jar 
> or any of its classes, but obviously they're getting loaded 
> because the code is executing. It may not be significant that 
> my classes aren't in the system classpath. However, I'm not 
> sure what the classloader arrangement is in this case (I 
> don't know exactly what happens when
> Class.forName() is called).
> 
> Now, I'm using the executing class' getResourceAsStream(), so 
> one would think it would know where the jar file was.

This is not a issue of locating the jar file - after all you running which
means you class is loaded which means the JRE has located the class which
means the jar is know.  If you task class is
com/mycompany/tools/dbgen/DBGenAntTask.class then either of the following
two approaches should work:

   getClass().getResourceAsStream("Class.tmpl");

   getClass().getResourceAsStream("/com/mycompany/tools/dbgen/Class.tmpl");

/Steve.


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to