Phing - imported build file does not execute - phing

New to phing, I feel dumb but when I import one build file into another. The imported build file does not execute. I must have something wrong (note that $ phing --buildfile imported.xml runs fine).
I have tried:
<?xml version="1.0" encoding="UTF-8"?>
<project name="myproject" default="project" basedir="." description="Set up project">
<target name="project">
<echo msg="Deploy" />
</target>
<import file="import.xml"/>
</project>
AND
<?xml version="1.0" encoding="UTF-8"?>
<project name="myproject" default="project" basedir="." description="Set up project">
<target name="project">
<echo msg="Deploy" />
<import file="import.xml"/>
</target>
</project>

Nevermind, I see that you have to make a inside the default target.
so now:
<?xml version="1.0" encoding="UTF-8"?>
<project name="myproject" default="project" basedir="." description="Set up project">
<target name="project">
<echo msg="Deploy" />
<phingcall target="importedTarget" />
</target>
<import file="import.xml"/>
</project>

I think that the problem is with the "namespaces". I explain you my case, that could be yours.
I have a build.xml file that imports this structure:
.
├── bin
│   ├── phing
│   │   ├── qgpl
│   │   │   ├── console.xml
│   │   │   └── folder.xml
│   │   └── skel.xml
importing these tasks at the bottom of build.xml
<import file="${tasks.dir}/phing/skel.xml" optional="false" />
<import file="${tasks.dir}/phing/qgpl/console.xml" optional="false" />
<import file="${tasks.dir}/phing/qgpl/folder.xml" optional="false" />
If the file bin/phing/qgpl/console.xml is defined with:
<project name="qgpl.console" basedir="${build.dir}" >
I get the targets duplicated:
phing -l
Buildfile: build.xml
[property] Loading etc/config.ini
[property] Loading etc/local-config.ini
[property] Loading etc/after-local-config.ini
Default target:
-------------------------------------------------------------------------------
build Build the application
Main targets:
-------------------------------------------------------------------------------
base64Encode Convertim a Base64 una cadena preguntada
[...]
qgpl_console.base64Encode Convertim a Base64 una cadena preguntada
But if there is only one base64Encode target in the project, I must to execute it with
phing base64Encode
because
phing qgpl_console.base64Encode
do nothing, no errors but nothing executed.
I fix it removing the project name keyword in the imported files
<project basedir="${build.dir}" >
And adding the "namespace" in each target
<target name="qgpl.console.base64Encode" description="Convertim a Base64 una cadena preguntada" >
<input propertyname="stringPlain">Input string to convert to Base64</input>
<qgpl.base64Encode string="${stringPlain}" returnProperty="string64" />
<echo>${string64}</echo>
</target>
I was searching in the documentation, but I don't found other way to do it.

Related

Missing output files after running Ant script from Eclipse

I have a simple web application developed in the Eclipse Luna. The directory structure of the application is like:
Project name is SchoolSchedule.
Under the project name, there are Java Resources, build, WebContent folders, and the build.xml file.
Under Java Resources, it is the "src" folder and my Java code package name is under the "src" folder.
Under the WebContent, there are META-INF, WEB-INF and my jsp files
Under the WEB-INF, there are web.xml file and the "lib" directory.
The build.xml is at the project root. This web application runs successfully and produces expected results.
I created an Ant script to compile, build a WAR file, and deploy the WAR. But, even the basic task does not work. I right click on the build.xml --> run as ... --> Ant build. In the console, I can see all the echo messages and no error. However, I do not see any new directories created (I "refresh" the project.). No "class" files compiled from the Java code and not to mention build and deploy those tasks.
There is something I did not get it right. Please help. Here is my Ant script:
<?xml version="1.0" encoding="UTF-8"?>
<project name="AntWarWebApp" basedir="." >
<echo>Define properties</echo>
<property name="name" value="SchoolSchedule"/>
<property name="src" location="src"/>
<property name="web" location="WebContent"/>
<property name="build" location="build"/>
<property name="classDir" location="${build}/src"/>
<property name="distDir" location="${build}/dist"/>
<property name="warDir" location="${build}/war"/>
<property name="tomcat.webapps" value="C:\apache-tomcat-7.0.70\webapps" />
<echo>time stamp</echo>
<tstamp prefix="build-info">
<format property="current-date" pattern="d-MMMM-yyyy" locale="en" />
<format property="current-time" pattern="hh:mm:ss a z" locale="en" />
<format property="year-month-day" pattern="yyyy-MM-dd" locale="en" />
</tstamp>
<echo>clean up previous build directories</echo>
<target name="clean" description="Delete old build directories">
<delete dir="${distDir}"/>
<delete dir="${warDir}"/>
<delete dir="${classDir}"/>
</target>
<echo>create directories</echo>
<target name="init" depends="clean">
<mkdir dir="${build}"/>
<mkdir dir="${classDir}"/>
<mkdir dir="${warDir}"/>
<mkdir dir="${distDir}"/>
<mkdir dir="${warDir}/WEB-INF"/>
<mkdir dir="${warDir}/WEB-INF/classes"/>
</target>
<echo>start compiling</echo>
<target name="compile" depends="clean, init" description="Compile main
source tree java files">
<javac srcdir="${src}" destdir="${classDir}" />
<classpath>
<fileset dir="${basedir}/WebContent/WEB-INF/lib">
<include name="*" />
</fileset>
</classpath>
</target>
<echo>start building WAR file</echo>
<target name="buildwar" depends="clean, init, compile">
<war basedir="${wardir}" destfile="${distDir}/${name}.war"
webxml="${wardir}/WEB-INF/web.xml">
<webinf dir="${wardir}/WEB-INF/">
<include name="**/*.jar" />
</webinf>
<manifest>
<attribute name="Built-On" value="${build-info.current-date}" />
<attribute name="Built-At" value="${build-info.current-time}" />
</manifest>
</war>
</target>
<echo>end building WAR file</echo>
<target name="deploy" depends="init, compile, buildwar" description="Deploy application">
<delete dir="${tomcat.webapps}/*.war" />
<echo>copy WAR file to Tomcat deploy directory</echo>
<copy file="${distdir}/*.war" todir="${tomcat.webapps}" />
</target>
</project>
Aren't you supposed to have some kind of top-level element
<project>
....
</project>
around all this?

Apache IVY Unable to resolve dependencies for MAVEN Projects

I have a setup of Apache Ivy(Version 2.4.0) and Netbeans IDE(8.0.2). I have not been able to resolve dependencies for full blown maven projects(For example:org.glassfish.jersey). Apache Ivy successfully resolves dependencies for more specific modules like (org.glassfish.jersey.core).
Non working Example:
<dependency org="org.glassfish.jersey" name="project" rev="2.13" conf="solrj->*"/>
Working Examples:
<dependency org="org.apache.solr" name="solr-solrj" rev="5.0.0" conf="solrj->default"/>
<dependency org="org.glassfish.jersey.core" name="jersey-server" rev="2.13" conf="JerseyCore-2.13->default,optional"/>
<dependency org="org.glassfish.jersey.core" name="jersey-client" rev="2.13" conf="JerseyCore-2.13->default,optional"/>
<dependency org="org.glassfish.jersey.core" name="jersey-common" rev="2.13" conf="JerseyCore-2.13->default,optional"/>
ivy.xml
<ivy-module version="2.0">
<info organisation="org.sonatype.nexus.examples" module="simple-project" revision="1.0.0-SNAPSHOT"/>
<configurations>
<conf name="solrj" description="Jars from the SOLRJ Library Collection"/>
</configurations>
<dependencies>
<dependency org="org.glassfish.jersey" name="project" rev="2.13" conf="solrj->*"/>
<dependency org="org.apache.solr" name="solr-solrj" rev="5.0.0" conf="solrj->default"/>
</dependencies>
ivysettings.xml
<ivysettings>
<settings defaultResolver="ibiblio"/>
<resolvers>
<ibiblio name="ibiblio" m2compatible="true"/>
</resolvers>
build.xml(Just the IVY Part).
<!-- Resolve all the dependencies that we declared in the build.xml file.
Resolving means that ivy will download the jar file from the MAVEN 2 Repository
and put them under the directory that you specify in the build.xml file.
In my case this is where all the jar files will be downloaded "C:\Users\ajalgaon\Accurev\solrj\lib" -->
<target name="init">
<ivy:settings file="ivysettings.xml" />
<ivy:resolve/>
<ivy:report todir="prebuilt/ivy-report" graph="false"/>
<ivy:retrieve conf="solrj" pattern="prebuilt/jars/solrj-lib/[artifact].[ext]"/>
</target>
Apache IVY Successfully resolves dependencies for the solr-solrj module. But it does not resolve dependency for "org.glassfish.jersey". Apache IVY Does not resolve dependencies for anything that has the attribute name="project" in the ivy.xml file. Kindly let me know if I need to post more information here. Thanks a lot in advance.
Cannot reproduce your issue.
Example
├── build.xml
├── ivy.xml
└── target
├── ivy-reports
│   ├── ivy-report.css
│   └── org.sonatype.nexus.examples-simple-project-solrj.html
└── jars
├── commons-io.jar
├── httpclient.jar
├── httpcore.jar
├── httpmime.jar
├── noggit.jar
├── slf4j-api.jar
├── solr-solrj.jar
├── stax2-api.jar
├── woodstox-core-asl.jar
└── zookeeper.jar
ivy.xml
<ivy-module version="2.0">
<info organisation="org.sonatype.nexus.examples" module="simple-project" revision="1.0.0-SNAPSHOT"/>
<configurations>
<conf name="solrj" description="Jars from the SOLRJ Library Collection"/>
</configurations>
<dependencies>
<dependency org="org.glassfish.jersey" name="project" rev="2.13" conf="solrj->*"/>
<dependency org="org.apache.solr" name="solr-solrj" rev="5.0.0" conf="solrj->default"/>
</dependencies>
</ivy-module>
build.xml
<project name="demo" default="resolve" xmlns:ivy="antlib:org.apache.ivy.ant">
<property name="build.dir" location="target"/>
<available classname="org.apache.ivy.Main" property="ivy.installed"/>
<target name="resolve" depends="install-ivy" description="Use ivy to resolve classpaths">
<ivy:resolve/>
<ivy:report todir='${build.dir}/ivy-reports' graph='false' xml='false'/>
<ivy:retrieve conf="solrj" pattern="${build.dir}/jars/[artifact].[ext]"/>
</target>
<target name="install-ivy" description="Install ivy" unless="ivy.installed">
<mkdir dir="${user.home}/.ant/lib"/>
<get dest="${user.home}/.ant/lib/ivy.jar" src="http://search.maven.org/remotecontent?filepath=org/apache/ivy/ivy/2.4.0/ivy-2.4.0.jar"/>
<fail message="Ivy has been installed. Run the build again"/>
</target>
<target name="clean" description="Cleanup build files">
<delete dir="${build.dir}"/>
</target>
<target name="clean-all" depends="clean" description="Additionally purge ivy cache">
<ivy:cleancache/>
</target>
</project>

Ant Builder for SASS in Zend Studio (Eclipse) "Is A Directory" Error

The build script I am using:
<?xml version="1.0" encoding="UTF-8"?>
<project basedir="." default="sass">
<target name="sass">
<apply dest="./sass" executable="sassy.bat">
<srcfile />
<targetfile />
<mapper from="*.scss" to="*.css" type="glob"/>
<fileset dir="./sass" includes="**/*.scss" />
</apply>
</target>
</project>
And it works great, with the condition that I have this external sassy.bat script on my %%PATH%%.
sass %1 %2
It compiles sass/*.scss files and puts the *.css in the same directory. However, if I don't use my sassy.bat and rather just use sass.bat it produces:
ruby.exe: Is a directory -- C:/project/sass (LoadError)
But in theory it should be running the same thing. Any idea what I'm doing wrong?
I ended up solving this problem recently. The first step is to ensure that the builder is set to use a "Separate JRE" (Zend Studio's). The second step was to update my buildfile to the following:
<?xml version="1.0" encoding="UTF-8"?>
<project basedir="." default="sass">
<target name="sass">
<exec osfamily="windows" vmlauncher="false" executable="sass">
<arg value="--update" />
<arg value="scss/:css/" />
<arg value="--style=compressed" />
</exec>
</target>
</project>
The key was to set the vmlauncher attribute to false on Windows.

How to build and deploy adapter with single ANT script Worklight 6.1

At 6.1 the ant jar was split into two jars: worklight-ant-builder.jar and worklight-ant-deployer.jar. I can run the build or the deploy tasks by themselves but I have to change the fileset. I want to run the build adapter and deploy adapter out of a single ant script.
I've tried a few ways to include both jars in the taskdef fileset:
include name="*.jar"
or
filename name="*.jar"
or
include name="worklight-ant-builder.jar"
include name="worklight-ant-deployer.jar"
Its almost like the tasks won't accept multiple jars. The build always works, but the deploy only when the deployer.jar is "include name="worklight-ant-deployer.jar" by itself.
<taskdef resource="com/worklight/ant/defaults.properties">
<classpath>
<fileset dir="${worklight.server.install.dir}/WorklightServer">
<include name="*.jar"/>
<!-- <filename name="*.jar"/> -->
<!-- <include name="worklight-ant-builder.jar"/> -->
<!-- <include name="worklight-ant-deployer.jar"/> -->
</fileset>
</classpath>
</taskdef>
I understand the multi-script answer but I think I shouldn't have to do that. This is my full script:
<?xml version="1.0" encoding="UTF-8"?>
<project name="BuildDeployAdapter" basedir="." default="help">
<property name="worklight.server.install.dir" value="C:/IBM/Worklight61/"/>
<property name="adapter-source-files-folder" value="C:/Worklight/workspaces/base61p/HelloWorklight/adapters/HTTPAdapter"/>
<property name="destination-folder" value="C:/Worklight/workspaces/base61p/HelloWorklight/binANT"/>
<property name="myAdapter.adapter" value="${destination-folder}/HTTPAdapter.adapter"/>
<property name="http.server.port.context" value="http://mydomain:9080/worklight"/>
<taskdef resource="com/worklight/ant/defaults.properties">
<classpath>
<fileset dir="${worklight.server.install.dir}/WorklightServer">
<include name="*.jar"/>
<!-- <filename name="*.jar"/> -->
<!-- <include name="worklight-ant-builder.jar"/> -->
<!-- <include name="worklight-ant-deployer.jar"/> -->
</fileset>
</classpath>
</taskdef>
<target name="buildAdapter">
<adapter-builder
folder="${adapter-source-files-folder}"
destinationfolder="${destination-folder}"/>
</target>
<target name="deployAdapter">
<adapter-deployer deployable="${myAdapter.adapter}"
worklightserverhost="${http.server.port.context}"
userName="username" password="password" />
</target>
</project>
Right now I have to switch the included jar for each task, when I want to use the masked include - either include name=".jar" or filename name=".jar". This seems to be a limititation on the specific task not accepting more than one jar. Am I off base here?
Given the information you provided, it seems that a solution could be to create a separate script that would invoke the build and deploy scripts in sequence, like this:
<project name="Adapter Stuff" default="do.all" basedir=".">
<target name="do.all">
<ant antfile="path/to/worklight-build-adapter.xml"
target="build-target" inheritall="false"/>
<ant antfile="path/to/worklight-deploy-adapter.xml"
target="deploy-target" inheritall="false"/>
</target>
</project>

Ant buildfile does not contain a javac task

I have build.xml file and I want to create Java project from Existing Ant Buildfile. But I have an error: Specified buildfile does not contain a javac task
My file has simple structure:
<project>
<target ...>
</target>
...
</project>
Provide javac to your build.xml as below:
<javac srcdir="src" destdir="bin" />
As Puneet Pandey pointed out, this error occurs when your build.xml file is lacking a <javac> XML element.
The <javac> XML element in the build.xml file (referred to as javac task) tells the compiler or IDE (Eclipse in this case) where the source Java files are for compiling. Once you know that it should be quite clear why Eclipse can't import your build.xml without a <javac> XML element.
In case you are not sure where to stick the <javac> tag I'll add a slightly fuller example. You will need to navigate to your build.xml and edit it so that it contains the <javac> line in the appropriate section inside the <project> tag.
<project ...>
<javac srcdir="src" destdir="bin" />
<target ...>
</target>
...
</project>
You need something like this,
<target name="compile">
<javac destdir="build/classes" srcdir="src" includeantruntime="false">
<classpath refid="compile.classpath"/>
</javac>
</target>
<target name="war" depends="compile">
<war destfile="build/${name}.war" webxml="WebContent/WEB-INF/web.xml">
<fileset dir="WebContent" casesensitive="no">
</fileset>
<lib dir="WebContent/WEB-INF/lib"/>
<classes dir="build/classes">
</classes>
</war>
</target>