Getting Ant to recognise a classpath

Here’s an example from a project I am currently working on. I suspect you can modify it to work for your situation. <path id=”master-classpath”> <fileset dir=”${web.dir}/WEB-INF/lib”> <include name=”*.jar”/> </fileset> <fileset dir=”${appserver.lib}”> <include name=”servlet*.jar”/> </fileset> <pathelement path=”${build.dir}”/> </path> … <javac destdir=”${build.dir}”> <src path=”${src.dir}”/> <classpath refid=”master-classpath”/> </javac>

Error executing command ‘ant’ on Mac OS X 10.9 Mavericks when building for Android with PhoneGap/Cordova

The error message proved to be true as Apache Ant isn’t in the path of Mac OS X Mavericks anymore. Bulletproof solution: Download and install Homebrew by executing following command in terminal: ruby -e “$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)” Install Apache Ant via Homebrew by executing brew install ant Run the PhoneGap build again and it should … Read more

Is it possible to call Ant or NSIS scripts from Java code?

You can call ant scripts from Java code. See this article (scroll down to the “Running Ant via Java” section) and this article: File buildFile = new File(“build.xml”); Project p = new Project(); p.setUserProperty(“ant.file”, buildFile.getAbsolutePath()); p.init(); ProjectHelper helper = ProjectHelper.getProjectHelper(); p.addReference(“ant.projectHelper”, helper); helper.parse(p, buildFile); p.executeTarget(p.getDefaultTarget()); Update I tried with the following ant file , it … Read more

Make ant quiet without the -q flag?

One option might be to set the logging level from within the target. You can access loggers by means of a short script task. Something like: <target … > <script language=”javascript”> var logger = project.getBuildListeners( ).firstElement( ); logger.setMessageOutputLevel( 0 ); </script> … </target> I’m not familiar with how Eclipse calls Ant, but it might be … Read more

Make javac treat warnings as errors

Use the -Werror flag. It’s not listed in the -help output, but it works. I found it through this blog entry and tested on my own code (in NetBeans with Ant). The output was: MyClass.java:38: warning: [serial] serializable class MyClass has no definition of serialVersionUID public class MyClass extends JComponent { 1 warning BUILD FAILED … Read more

URLConnection FileNotFoundException for non-standard HTTP port sources

The response to my HTTP request returned with a status code 404, which resulted in a FileNotFoundException when I called getInputStream(). I still wanted to read the response body, so I had to use a different method: HttpURLConnection#getErrorStream(). Here’s a JavaDoc snippet of getErrorStream(): Returns the error stream if the connection failed but the server … Read more

Generate manifest class-path from in Ant

<path id=”build.classpath”> <fileset dir=”${basedir}”> <include name=”lib/*.jar”/> </fileset> </path> <pathconvert property=”manifest.classpath” pathsep=” “> <path refid=”build.classpath”/> <mapper> <chainedmapper> <flattenmapper/> <globmapper from=”*.jar” to=”lib/*.jar”/> </chainedmapper> </mapper> </pathconvert> <target depends=”compile” name=”buildjar”> <jar jarfile=”${basedir}/${test.jar}”> <fileset dir=”${build}” /> <manifest> <attribute name=”Main-Class” value=”com.mycompany.TestMain”/> <attribute name=”Class-Path” value=”${manifest.classpath}”/> </manifest> </jar> </target> For further information check out this article.