It is common for build scripts to compile their own tasks and then taskdef them. Unfortunately there is then no standard way to find ant.jar to put in the classpath (assuming you use ${build.sysclasspath}=ignore), unless you happen to include a copy of this JAR with your project. You can use ${ant.home}/lib/ant.jar which works with command-line Ant from apache.org but might not work with (1) IDEs which bundle Ant, (2) the RPM from jpackage.org which uses a different directory structure, etc. Suggest a new built-in property, ${ant.jar}, specifically for a JAR file containing central Ant classes you would want to import into custom task sources. (org.apache.tools.ant.*, basic datatypes and utilities, MatchingTask, etc.) Motivation: http://www.netbeans.org/issues/show_bug.cgi?id=35123
Created attachment 7494 [details] Suggested patch
Can you use the Locator class in o.a.t.a.launch?
Yes, probably Locator.getClassSource would work as well as using java.security.CodeSource. Note that Locator.fromURI is obsoleted by the File(URI) constructor in JRE 1.4 - I think I already filed that separately.
yes but we are going for 1.2 compat now - not 1.4
[Re. File(URI)] - yes of course, I meant using reflection, when available.
Cf. also bug #32405.
can we close this issue?
I still think it would be helpful, but am willing to drop it if others disagree (or to work on a patch if others agree).
For the 1.4 introspection or another way to find ant.jar ?
Doesn't really matter since there is a general util method to take URI -> File, which should in the future be fixed to behave correctly under JDK 1.4+ (and use whatever tricks on 1.2 + 1.3).
I don't see any reason you can't add whatever you want in that regard.
In any event, the original request here is satisfied: File antjar = org.apache.tools.ant.launch.Locator.getClassSource( org.apache.tools.ant.Project.class);
From *code* it's available, but not from a build script.
Against CVS HEAD: <whichresource class="org.apache.tools.ant.Main" property="main" /> <pathconvert> <string value="${main}" /> <chainedmapper> <globmapper from="*!/org/apache/tools/ant/Main.class" to="*" /> <globmapper from="jar:*" to="*" /> <!-- if you want to assume it's a file, use: <globmapper from="jar:file:/*" to="*" /--> </chainedmapper> </pathconvert> yields: [pathconvert] file:/D:/ant/lib/ant.jar an alternative would be <pathconvert> <url javaresource="org/apache/tools/ant/Main.class" /> <chainedmapper> <globmapper from="*!/org/apache/tools/ant/Main.class" to="*" /> <globmapper from="jar:*" to="*" /> <!-- if you want to assume it's a file, use: <globmapper from="jar:file:/*" to="*" /--> </chainedmapper> </pathconvert> i.e., <url javaresource="" /> overlaps <whichresource> somewhat.
1. That's way too complicated. Few people would ever figure out such a thing for themselves. 2. URL -> file conversion using prefix removal is not safe on all platforms / filesystems and for all directory names.
Also poses a problem for running the NB IDE over JNLP (under development) using the bundled Ant, since the original Ant directory structure is not preserved: http://www.netbeans.org/nonav/issues/show_bug.cgi?id=73990
I have implemented this using ingredients from matt, jesse and myself. I have called the property ant.core.lib as to not tie the property to a jar file per se.
(In reply to comment #15) > 1. That's way too complicated. Few people would ever figure out such a thing for > themselves. Just reread this and had me laughing my a$$ off... yes, it was way too complicated, but oh what fun! :) -Matt