ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Rick Mann <rm...@latencyzero.com>
Subject Loading resources from my task's JAR?
Date Thu, 05 Jan 2006 05:48:43 GMT
I wrote an Ant task that needs to load some files (it's a source  
generator that loads template files). I'd like to store those files  
in the task's .jar file, but so far I've met with no success. I've  
tried storing the files in various parts of the .jar:

templates/Class.tmpl
com/mycompany/tools/dbgen/Class.tmpl
Class.tmpl

and I've tried getting at it with (and more) from within my task's code:

getClass().getResourceAsStream("templates/Class.tmpl")
getClass().getResourceAsStream("/templates/Class.tmpl")
getClass().getResourceAsStream("Class.tmpl")

I test my task with ant. Here's the build.xml snippet:

	<path id="test.classpath">
		<fileset refid="compile.classpath.fileset"/>
		<pathelement location="${target.task}/${taskName}-$ 
{taskVersion}.jar"/>
	</path>
	
	<target name="test-task" depends="task" description="--> Test the  
Ant task">
		<echo message="classpath: ${java.class.path}"/>
		<taskdef	name="dbgen"
					classname="com.keepmedia.tools.dbgen.DBGenAntTask">
			<classpath refid="test.classpath"/>
		</taskdef>
		
		<dbgen customizationDir="custDir" destDir="destDir">
			<fileset dir="../../db/definitions1">
				<include name="*.def"/>
			</fileset>
		</dbgen>
					
	</target>


In all cases, it returns null. So, I decided to check the class path  
(with System.getProperty("java.class.path")), and it's this. Note  
that only basic and Ant jars are there (not the jar containing my task).

/Developer/Java/Ant/lib/ant-launcher.jar
/Developer/Java/Ant/lib/ant-antlr.jar
/Developer/Java/Ant/lib/ant-apache-bcel.jar
/Developer/Java/Ant/lib/ant-apache-bsf.jar
/Developer/Java/Ant/lib/ant-apache-log4j.jar
/Developer/Java/Ant/lib/ant-apache-oro.jar
/Developer/Java/Ant/lib/ant-apache-regexp.jar
/Developer/Java/Ant/lib/ant-apache-resolver.jar
/Developer/Java/Ant/lib/ant-commons-logging.jar
/Developer/Java/Ant/lib/ant-commons-net.jar
/Developer/Java/Ant/lib/ant-icontract.jar
/Developer/Java/Ant/lib/ant-jai.jar
/Developer/Java/Ant/lib/ant-javamail.jar
/Developer/Java/Ant/lib/ant-jdepend.jar
/Developer/Java/Ant/lib/ant-jmf.jar
/Developer/Java/Ant/lib/ant-jsch.jar
/Developer/Java/Ant/lib/ant-junit.jar
/Developer/Java/Ant/lib/ant-launcher.jar
/Developer/Java/Ant/lib/ant-netrexx.jar
/Developer/Java/Ant/lib/ant-nodeps.jar
/Developer/Java/Ant/lib/ant-starteam.jar
/Developer/Java/Ant/lib/ant-stylebook.jar
/Developer/Java/Ant/lib/ant-swing.jar
/Developer/Java/Ant/lib/ant-trax.jar
/Developer/Java/Ant/lib/ant-vaj.jar
/Developer/Java/Ant/lib/ant-weblogic.jar
/Developer/Java/Ant/lib/ant-xalan1.jar
/Developer/Java/Ant/lib/ant-xslp.jar
/Developer/Java/Ant/lib/ant.jar
/Developer/Java/Ant/lib/junit.jar
/Developer/Java/Ant/lib/xercesImpl.jar
/Developer/Java/Ant/lib/xml-apis.jar



What can I do to get at resources in my tasks .jar file?

TIA,

-- 
Rick



---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org


Mime
View raw message