I have unjar ant task like below that was working until I changed classpath to include one more jar file. Wondering what the trick is to unjar every jar listed in javac.classpath. Basically it is breaking once javac.classpath has more than one jar file. I am Ant newbee. I am trying to figure out a way to enumerate every jar in javac.classpath and unjar it to build.classes.dir folder.
<unjar dest="${build.classes.dir}">
<fileset file="${javac.classpath}" >
</fileset>
</unjar>
if javac.classpath points to a folder then
<unjar dest="${build.classes.dir}">
<fileset dir="${javac.classpath}" >
</fileset>
</unjar>
will unjar all jar files in that folder.
if javac.classpath is a comma/semicolon separated list of file paths then you should change script a little bit to use filesets instead, like;
<?xml version="1.0" encoding="UTF-8"?>
<project name="Un-jar Demo" default="un-jar">
<fileset id="javac.classpath" dir="/path/to/jar/folder">
<include name="jar-file-1.jar" />
<include name="jar-file-2.jar" />
</fileset>
<target name="un-jar">
<unjar dest="test">
<fileset refid="javac.classpath">
</fileset>
</unjar>
</target>
</project>
of course, you can find some other ways to convert comma seperated list of files to a fileset
Related
I am trying to generate a build script for a plugin outside the IDE
Below is mybuild.xml
<project name="com.foo.poo" xmlns='antlib:org.apache.tools.ant'>
<target name="build.plugin">
<antcall target="generateBuildScript" />
<ant dir="${workspace.dir}/${project.name}"
antfile="build.xml"
target="build.update.jar" />
<copy todir="${eclipse.dir}/plugins">
<fileset dir="${workspace.dir}/${project.name}">
<include name="*.jar"/>
</fileset>
</copy>
</target>
<target name="generateBuildScript">
<eclipse.buildScript elements="plugin#${project.name}"
buildDirectory="${workspace.dir}"
baseLocation="${eclipse.dir}"
configInfo="linux,gtk,win32,win32,x86"/>
</target>
</project>
Expecting build.xml to be generated Please Guide me
When I run above script
$java -jar {$Eclipse.Dir}/plugins/org.eclipse.equinox.launcher_1.3.100.v20150511-1540.jar -application org.eclipse.ant.core.antRunner -buildfile <Project_path>\mybuild.xml
I nothing is happening on build success.
Here i have found the answer may help some new bees like me..
<project name="com.foo.poo" xmlns='antlib:org.apache.tools.ant'>
...
</project>
As there is no default set, it is not generating the required jar file so
modified only the first line as
<project name="com.foo.poo" default="build.plugin" xmlns='antlib:org.apache.tools.ant'>
...
</project>
now the required jar is generated under plugin folder and even copied to plugin folder of eclipse.
baseLocation : Target Plugins Directory absolute path.
buildDirectory: Absolute path to the plugin folder in which the Plugin Project is present.
In netBeans 8.2, I'm having an issue reading groovy inside a build.xml file.
I have a project in which I run my script via a build.xml using the build-in Ant 1.9.7.
In it, for my groovy task, I set the following:
<property environment="env" />
<path id="groovy.classpath">
<fileset dir="${env.GROOVY_HOME}/embeddable" />
</path>
<taskdef name="groovy" classname="org.codehaus.groovy.ant.Groovy" classpathref="groovy.classpath" />
For environment variable {env.GROOVY_HOME}, I have set the following in windows environment variable:
GROOVY_HOME with the value C:\Program Files (x86)\Groovy\Groovy-2.4.10
Yet I'm still having an error ""Script failed" when reaching the step with Groovy at the following stage in the build.xml file:
<groovy>
def corePlatformList = []
[Groovy code here...]
</groovy>
I know the script is working fine as it does run perfectly in Eclipse and IntelliJ.
It would seem ant can't link with Groovy 2.4.10 for some reason.
I believe that you have some trivial error.
You need to include the library file.
Change from:
<path id="groovy.classpath">
<fileset dir="${env.GROOVY_HOME}/embeddable" />
</path>
To:
<path id="groovy.classpath">
<fileset dir="${env.GROOVY_HOME}/embeddable">
<include name="**/groovy-all-*.jar"/>
</fileset>
</path>
EDIT: based on OP comments
Here is the complete build.xml and I can see it working.
<project name="MyProject" default="runscript" basedir=".">
<path id="groovy.classpath">
<fileset dir="d:/softwares/groovy-2.4.5/embeddable">
<include name="**/groovy-all-*.jar"/>
</fileset>
</path>
<taskdef name="groovy" classname="org.codehaus.groovy.ant.Groovy" classpathref="groovy.classpath" />
<target name="runscript"
description="compile the source">
<groovy>
def corePlatformList = [1,2,3,4]
println corePlatformList
</groovy>
</target>
</project>
I needed servlet-api.jar and jsp-api.jar in my eclipse dynamic web
project.
So I went to Project -> Properties -> Targeted Runtimes -> Checked Apache Tomcat 6.0.
Now I try to build a war file using Ant as I have to deploy the war file on a unix machine.
Problem - Ant build fails (package javax.servlet does not exist, etc etc) because the jar files are not under /WEB-INF/lib/. How do I include these jar files in the classpath ? I can't hardcode it as the path is different in windows(D:\Program Files\Apache...) and unix(/usr/local/apache..).
Current classpath-
<path id="compile.classpath">
<fileset dir="${web.home}/WEB-INF/lib">
<include name="*.jar"/>
</fileset>
</path>
p.s. My Apache-Tomcat versions are different on windows(6.0.32) and unix(6.0.36)
I would check if a variable like CATALINA_HOME is set on any machine where the build might run, then you could use something like:
<path id="compile.classpath">
<fileset dir="${web.home}/WEB-INF/lib">
<include name="*.jar"/>
</fileset>
<fileset dir="${env.CATALINA_HOME}/lib">
<include name="*.jar"/>
</fileset>
</path>
Try this:
Double click on your build.xml -> Run as -> Ant build...
Choose "Classpath" and add the jars needed
I think that should be enough
This script works good for the first server (server1), but it doesn't work for the second pass (server2) as at that point all 'modified' files are already flagged by the first pass.
<macrodef name="copythings">
<attribute name="todir"/>
<sequential>
<scp todir="#{todir}" trust="true">
<fileset dir=".">
<modified/>
<include name="cgi-bin/Application/" />
<exclude name="**/*.log" />
</fileset>
</scp>
</sequential>
</macrodef>
<target name="deploy">
<copythings todir="server1"/>
<copythings todir="server2"/>
</target>
I'd suggest copying the files from the fileset to a temporary folder first.
And copy to the server from that directory.
copy required files to a tempory folder
run the targets and use the temporay folder as base/filset for scp
delete the temporary folder
How do you do this? Given several build files, I only want to include the ones where the target (specified from the command line) exists. Using target::exists in does not seem to work. Thanks.
<target name="*">
<property name="curr.target" value="${target::get-current-target()}"/>
<nant target="${curr.target}">
<buildfiles>
<include name="*.build" if="${target::exists(curr.target)}"/>
<!-- avoid recursive execution of current build file-->
<exclude name="${project::get-buildfile-path()}" />
</buildfiles>
</nant>
</target>
Using robaker's solution, my final build file looks like this. It does not fail anymore if the target is not found in a certain build file (unlike my previous code).
<project>
<include buildfile="A.build"/>
<include buildfile="B.build"/>
<target name="*">
<nant target="${target::get-current-target()}"/>
</target>
</project>
Why not just use the include task to include all your child build scripts instead?