Ant build file to compile NSIS script - ant

I am new to ANT scripting. I need to develop a Ant script to compile .nsi script, which is developed using NSIS 2.46 version.
I am not sure how to start with it.
Can someone suggest how to to do it or post a example Ant script here which does the job of compiling the script which is placed on a local machine drive.

Besides running makensis as an exec task, there exists an NSIS plugin After downloading this and placing the plugin into the lib folder you can activate it like this:
<taskdef name="nsis" classname="net.sf.nsisant.Task">
<classpath location="nsisant-{version}.jar">
</taskdef>
After that is done, you can run the nsis script like this:
<nsis script="some_script_path\build_me.nsi">
<!-- eventually some defines here for controlling the nsis script -->
</nsis>

Related

How to build solr.tgz file from source using "ant package"

I want to build a .tgz distribution file from solr.
The build.xml file tells me to use "ant package".
However, running ant package gets everything from svn and builds ./package/solr-6.0.0-SNAPSHOT.zip whereas my code base is from lucene_4_10_x branch.
How do I build ./package/solr-4.10.3.zip from the source code?
I need to build from the source code because I have some local changes that I want to compile and deploy.
According to LUCENE-4288, Solr will only package properly if it's checked out from SVN by default. However, if you change package-src-tgz to package-local-src-tgz, it will properly package. Find the following lines in solr/build.xml:
<!-- make a distribution -->
<target name="package" depends="package-src-tgz,..."/>
And change package-src-tgz to package-local-src-tgz.
<!-- make a distribution -->
<target name="package" depends="package-local-src-tgz,..."/>
Then just rerun ant package inside solr/, and the packaged archives (solr-<version>-SNAPSHOT.tgz and solr-<version>-SNAPSHOT.zip) will be available under solr/package/.

Calling Ant from Nant without batch

We have an automated build process that uses Nant scripts, and we just inherited a Java project that has an existing, working Ant script. I have searched all over and it seems most people use a batch file to call Ant scripts from Nant. This seems a little hacky to me. Is there a way to call Ant scripts directly from Nant in task format?
This similar question addresses it with a batch file but I want to do it without.
<!-- calling the Ant build Process-->
<target name="AntBuildProcess" description="Created to call the Ant build during this NAnt build process" >
<echo message="Starting the Ant Build Process..." />
<exec program="ant" commandline='-buildfile YourAntBuild.xml' failonerror="true"/>
</target>
Then during your Build process, you just call this target at the point you need it to be built. <call target="AntBuildProcess" />
Ant is a batch file. Take a look, and you'll see a file called ant.bat in the %ANT_HOME%\bin directory.
Ant is actually a Java program, so you could launch it from the java command by running the class org.apache.tools.ant.launch.Launcher which is basically what the ant.bat file is doing.
However, why reinvent the wheel? The ant.bat runs the Java command the right way, gives you options to change the way it's executed, and makes sure everything is setup correctly.
Addendum
I see, Nant, unlike Ant, will always call cmd.exe and use suffixes and %PATHEXEC% to figure out if something is a batch script or other type of script. Thus, if you want to run Ant using Ant as a batch script via <exec/> you would do this:
<exec executable="cmd.exe"
dir="${working.dir}">
<arg value="/c"/>
<arg value="ant.bat"/>
</exec>
However, in Nant you can simply do it this way:
<exec program="ant"
workingdir=${working.dir}"/>

Runnable jar file without ant java task - how is this possible?

I've inherited some code from a previous developer, which gets built using Ant into an executable jar file that runs by double clicking. The application runs, but under some conditions crashes with an OutOfMemoryError. To investigated this, I'd like to add the -XX:+HeapDumpOnOutOfMemory jvm arg to the Ant buildfile, and as I understand it, the <jvmarg value="-XX:+HeapDumpOnOutOfMemory" /> element needs to go under a <java ...> task. However, there is no <java ...> task to be found in this or any other Ant buildfiles in this code base.
How is this even possible? How can the jar file be executable without a <java ...> task?
I'm asking primarily to find out what in fact makes my jar file executable so that I can figure out where to put that <jvmarg /> element to debug the OOME.
Thanks!
A <java> task doesn't create an executable jar file. It executes a Java program.
I don't think it's possible to specify VM parameters when starting an executable jar file by double-clicking on it. If you want to pass VM parameters, open a command prompt and execute the jar this way:
java -XX:+HeapDumpOnOutOfMemory -jar nameOfTheJar.jar
Your jar is executable because it has a Main-Class defined in the META-INF/MANIFEST.MF file. Double clicking it to run doesn't do anything with Ant. Ant is simply used to package the jar.
In order to add the parameter and still launch via a double click you could create a shortcut that runs the command in JB Nizet's answer

#Grab annotation fails under Ant

I'm using a #Grab annotation to grab the definition of an Html parser I can give to the XMLSlurper (I think it's the tagsoup parser) and all is good when I run my script from the cmd line. If I invoke the same script from Ant I get an Ivy NoClassDefFound error. I think it may berelated to having Ivy in Antlib. Is there another way to parse Html without customizing the slurper via #Grab?
This:
#Grab(group='org.ccil.cowan.tagsoup', module='tagsoup', version='1.2' )
doc = new XmlSlurper(new org.ccil.cowan.tagsoup.Parser()).parse(confluenceWebPageInputStream)
Works just fine from the command line but when I run it from an Ant build target:
<target name="update-wiki-chart">
<echo message="Will update chart for version ${version}"/>
<java dir="${basedir}" classname="groovy.lang.GroovyShell">
<arg value="ParseWikiPage.groovy"/>
<classpath refid="groovylib"/>
</java>
</target>
where groovyLib is a path ref pointing to the Groovy-1.8.6 jar downloaded from our internal Nexus repo, I get the NoClassDefFound error. I'm thinking this is probably due to having Ivy installed in Antlib causing the class loader to find it in two places. I just thought of something while writing this post. I can probably run java in forked mode or do something to cause it to not see/share Ant's classpath.It's been a few years since I've wrestled w/ Ant and class loader issues. My project is a little delinquent due to the bug and I'm looking for a quick/easy fix.
I just tried running my groovy on the cmd line via the "java" cmd and loading groovy-all jar in the class path and I realized that I get the NoClassDefFound error there as well. It has nothing to do with collisions with Ivy under Antlib. Rather, I am missing Ivy altogether. I had assumed it was included in Groovy-all.jar. I just need a clever way of passing Ivy from AntLib into my java task to get this all up and running.
Sounds like you're missing one or more jars from the classpath. I'd suggest digging around the classpathref you've labelled "groovylib".
A less error prone way to launch groovy from within ANT using the groovy ANT task.
Here's a similar example to your use-case:
Parse HTML using with an Ant Script
My example uses ivy directly to manage all build dependencies. The Grab annotations are still supported but obviously these would only manage the dependencies of the groovy script.

Maven run ant builds in subdirectories

I have multiple JavaFX 2.0 apps (built with the default ant scripts generated by netbeans 7.0) which I want to be wrapped up into a war by a maven pom in the parent directory.
The war-building pom has lots of ant tasks in the compile phase that look like this:
<ant antfile="FXapplication1/build.xml" target="jar"/>
But when I go to run 'mvn compile', I get this error from ant:
"C:\path\to\warbuilder\FXapplication1\nbproject\build-impl.xml:209: Must set src.dir"
The ant script builds fine when explicitly called inside its own directory, so I'm assuming that the problem is that it's looking in the war builder's local directory for its source files, rather than looking for them relative to the build.xml. Is there a way to specify a working path for a given ant task?
Try making the JavaFX apps modules of the warbuilder app, each with their own pom which executes <ant antfile="build.xml" target="jar"/>,
rather than running <ant antfile="FXapplication1/build.xml" target="jar"/> from the parent.
The parent should list the children as modules, they will then be executed as part of the parent build process.

Resources