ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Erik Earle" <erikea...@hotmail.com>
Subject ClassLoading within <script> using javascript
Date Thu, 20 May 2004 00:50:22 GMT
I have a file stucture like so:

./build.xml
./lib/foo.jar

foo.jar is NOT on my classpath when I invoke ant.

I want to be able to dynamically load classes from foo.jar or append the jar 
to the classpath in a task or something.  I haven't been able to make it 
happen.

The following would be ideal BUT throws an  AccessControlException

<property name="jarfile" location="${basedir}/lib/foo.jar"/>
<script language="javascript">
<![CDATA[

    importPackage(java.lang, java.util, java.io, java.net);
    importPackage(Packages.org.apache.tools.ant);
    importPackage(Packages.org.apache.tools.ant.taskdefs);

    file = new File(jarfile);
    urls = java.lang.reflect.Array.newInstance(java.net.URL,1);
    urls[0] = file.toURL();

    loader = new URLClassLoader(urls);

    c = loader.loadClass( cName, true );
]]>
</script>


I've tried other end-arounds but no love.


anyone?

_________________________________________________________________
Get 200+ ad-free, high-fidelity stations and LIVE Major League Baseball 
Gameday Audio! http://radio.msn.click-url.com/go/onm00200491ave/direct/01/


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


Mime
View raw message