I have a VS solution hosted in a TFS 2012 Express with a Build system (service, controller, agent) in place. I also created a build definition with this build project file as target:
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0"
DefaultTargets="Build"
xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<OutDir Condition=" '$(OutDir)'=='' ">$(MSBuildThisFileDirectory)bin\</OutDir>
<Configuration Condition=" '$(Configuration)'=='' ">Release</Configuration>
<SourceHome Condition=" '$(SourceHome)'=='' ">$(MSBuildThisFileDirectory)</SourceHome>
<ToolsHome Condition=" '$(ToolsHome)'=='' ">$(MSBuildThisFileDirectory)tools\</ToolsHome>
</PropertyGroup>
<ItemGroup>
<Solution Include="$(SourceHome)*.sln">
<AdditionalProperties>OutDir=$(OutDir);Configuration=$(Configuration)</AdditionalProperties>
</Solution>
</ItemGroup>
<Target Name="RestorePackages">
<Exec Command=""$(MSBuildProgramFiles32)\NuGet\NuGet.exe" config -set http_proxy=http://********" />
<Exec Command=""$(MSBuildProgramFiles32)\NuGet\NuGet.exe" config -set http_proxy.user=******" />
<Exec Command=""$(MSBuildProgramFiles32)\NuGet\NuGet.exe" config -set http_proxy.password=********" />
<Exec Command=""$(MSBuildProgramFiles32)\NuGet\NuGet.exe" restore "$(SourceHome)*.sln"" />
</Target>
<Target Name="Clean">
<MSBuild Targets="Clean"
Projects="#(Solution)" />
</Target>
<Target Name="Build" DependsOnTargets="RestorePackages">
<MSBuild Targets="Build"
Projects="#(Solution)" />
</Target>
<Target Name="Rebuild" DependsOnTargets="RestorePackages">
<MSBuild Targets="Rebuild"
Projects="#(Solution)" />
</Target>
</Project>
But somehow the build keeps failing again and again. This is the error:
Exception Message: Access to the path '******************\packages\AjaxControlToolkit.15.1.4.0\Content\Web.config.transform' is denied. (type UnauthorizedAccessException).
I have no clue what's going on, any ideas?
You may check whether the files are read-only.
At the end the issue was the NETWORK SERVICE account used for the build service. That account does not seem to have enough privileges to use the proxy. Changed it to my account finally worked. I know it's not the ideal approach, but does the trick for now.
Related
I have installed Ant in my centos 6.3 , installed location are
/opt/ant and also ANT_HOME env are same
I have created build.xml to test by deleting testdir. This directory exist in the /opt/ant/testdir like this.
build.xml
<?xml version="1.0"?>
<project name="testdir" default="all" basedir=".">
<property name="src" value="src"/>
<property name="build" value="build"/>
<property name="lib" value="lib"/>
<target name="all" depends="clean, compile" description="Builds the whole project">
<echo>Doing all</echo>
</target>
<target name="clean">
<echo message="Deleting bin/java ..." />
<delete dir="testdir/test" />
</target>
</project>
Using Command :-
ant -buildfile build.xml Clean
getting error:-
BUILD FAILED
Target "Clean" does not exist in the project "testdir".
Any suggestion to make it work?
You mis-spelt the target name ? 'Clean' as against 'clean' ??
I have found solution. I missed target="compile" block in build.xml.
<target name="compile">
<echo message="Compiling source code"/>
</target>
Run command :-
ant clean
I am using following Ant script to create a war of simple web application.
<?xml version="1.0" encoding="UTF-8"?>
<project name="MyProject" default="war">
<path id="compile.classpath">
<fileset dir="WebContent/WEB-INF/lib">
<include name="*.jar" />
</fileset>
</path>
<target name="compile">
<javac destdir="WebContent/WEB-INF/classes" debug="true" srcdir="src">
<classpath refid="compile.classpath" />
</javac>
</target>
<target name="war" depends="compile">
<war destfile="build/myproject.war" webxml="WebContent/WEB-INF/web.xml">
<fileset dir="WebContent">
<include name="**/*.jsp" />
</fileset>
<lib dir="WebContent/WEB-INF/lib" />
<classes dir="WebContent/WEB-INF/classes" />
</war>
</target>
</project>
It's creating the war but when I am opening the war, it's not containing JSP files due to which application is not running. Any idea what is wrong?
Also, right now I am coping war manually in Weblogic. Is there any Ant command which can deploy war?
I don't know exact answer but here is my way of using Ant build.xml for webapps. Give it a try. This works inside Eclipse or run from the command line. Few key points are:
build.xml has reference to compile-time libraries, including servlet-api.jar
dynamic META-INF/MANIFEST.MF
separate targets for compile, jar and war tasks to allow easier per project custom rules
webapp war don't have individual .class files but compiled web-inf/lib/mywebapp.jar library to minimize filesystem noice
you may create web/WEB-INF/classes/ folder and put some .properties file or extreme case "binary provided" class files. They are put inside war package along with other jsp,html,js files.
folder structure is very streamlined, I can use mywebapp/web/ folder directly in Tomcat service during development. Each html, jsp etc changes are reflected at runtime. Compiling jar triggers Tomcat to reload webapp instance.
Use this common folder structure for webapp project.
/mywebapp/ant.bat
/mywebapp/build.xml
/mywebapp/classes/
/mywebapp/src/
/mywebapp/src/META-INF/MANIFEST.MF
/mywebapp/lib/
/mywebapp/web/
/mywebapp/web/WEB-INF/web.xml
/mywebapp/web/WEB-INF/lib/
/mywebapp/web/META-INF/context.xml
mywebapp/build.xml
<?xml version="1.0" encoding="UTF-8"?>
<project name="mywebapp" default="build" basedir=".">
<property name="name" value="${ant.project.name}" />
<property name="classes" value="./classes" />
<property name="src" value="./src" />
<property name="webdir" value="./web" />
<property name="version" value="1.0"/>
<property environment="env"/>
<path id="libs">
<pathelement location="lib/servlet-api.jar" />
<pathelement location="web/WEB-INF/lib/somelib1.jar" />
<pathelement location="web/WEB-INF/lib/somelib2.jar" />
<pathelement location="web/WEB-INF/lib/gson-2.2.4.jar" />
</path>
<tstamp>
<format property="TODAY" pattern="yyyy-MM-dd HH:mm:ss" />
</tstamp>
<target name="updatemanifest" description="Update manifest">
<buildnumber file="build.num"/>
<copy file="${src}/META-INF/MANIFEST.MF"
todir="${classes}/META-INF/" overwrite="true" preservelastmodified="true"
/>
<manifest file="${classes}/META-INF/MANIFEST.MF" mode="update">
<attribute name="Implementation-Version" value="${version}.${build.number} (${TODAY})" />
<attribute name="Implementation-Title" value="${name}" />
</manifest>
</target>
<target name="clean" description="Clean compiled classes">
<delete dir="${classes}" />
</target>
<target name="compile" depends="clean" description="Compile classes">
<mkdir dir="${classes}"/>
<javac srcdir="${src}" destdir="${classes}" target="1.6" source="1.6" encoding="ISO-8859-1"
debug="true" debuglevel="lines,source"
excludes="" includeantruntime="false" >
<classpath refid="libs" />
<compilerarg value="-Xlint:deprecation" />
</javac>
</target>
<target name="jar" depends="updatemanifest" description="Create a .jar file">
<echo message="Build release: ${release}" />
<jar
manifest="${classes}/META-INF/MANIFEST.MF"
jarfile="${webdir}/WEB-INF/lib/${name}.jar" >
<fileset dir="${classes}">
</fileset>
</jar>
</target>
<target name="war" depends="compile,jar" description="Create a .war file">
<delete file="${name}.war" />
<zip destfile="${name}.war"
basedir="${webdir}"
excludes="
**/CVS*
"
/>
</target>
<target name="build" depends="war" description="Build lib">
</target>
</project>
src/META-INF/MANIFEST.MF
Implementation-Title: myappname
Implementation-Version: 1.0.0 (2010-03-01)
Implementation-Vendor: My Name Ltd.
Implementation-URL: http://www.myname.com
mywebapp/build.bat
call c:\apache-ant-1.7.0\bin\ant.bat build
pause
Build script creates war package and manifest.mf within web-inf/lib/mywebapp.jar is updated to have build number, title and version. Very handy you can use folder content as a template for new webapp projects. Just edit build.xml to have new project name.
Some compile-time dependencies point mywebapp/web-inf/lib folder. Non war-packaged libraries are put to mywebapp/lib/ folder for compile time only. I like keeping each dependency within project version control so thats a reason for this lib folder. You may use *.jar wildcard ant syntax but I explictly list each file for self documentation purpose.
Here is a bonus file to be used in Tomcat during development time. It publishes webapp on Tomcat and any changes in project folder is seen immediately, its very handy for client file changes (html,js,jsp).
this file is a copypaste from mywebapp/web/META-INF/context.xml file but an explicit docBase attribute is added.
It directs Tomcat to use files directly from project folder, no redeployment needed at runtime
Start tomcat and keep it running, you may run several webapp projects withing same Tomcat instance. Sometimes bigger development projects need it.
Remote debugging hook requires some java magic not included here
tomcat/conf/Catalina/localhost/mywebapp.xml
<?xml version="1.0" encoding="UTF-8"?>
<Context docBase="C:/mywebapp/web"
debug="0" reloadable="true" crossContext="true" >
<!--
<Valve className="org.apache.catalina.valves.RemoteAddrValve"
allow="127.0.0.1" />
-->
<!--
<Valve className="org.apache.catalina.valves.RequestDumperValve"/>
-->
<!-- pooled db connection -->
<Resource name="jdbc/mywebappDB" auth="Container" type="javax.sql.DataSource"
maxActive="10" maxIdle="2" maxWait="20000"
driverClassName="com.microsoft.sqlserver.jdbc.SQLServerDriver"
username="myuserid" password="mypwd"
url="jdbc:sqlserver://mysqlserv1.com:1433;DatabaseName=MyDB;applicationName=mywebapp"
validationQuery="SELECT 1"
/>
<!-- <ResourceLink name="jdbc/mywebappDB" global="jdbc/mywebappDB" type="javax.sql.DataSource" /> -->
<Resource name="jdbc/mywebappDB2" auth="Container" type="javax.sql.DataSource"
maxActive="100" maxIdle="20" maxWait="10000"
driverClassName="com.mysql.jdbc.Driver"
username="myuserid" password="mypwd"
url="jdbc:mysql://localhost:3306/myDB2?useUnicode=true&characterEncoding=utf8"
validationQuery="SELECT 1" removeAbandoned="true" removeAbandonedTimeout="300"
/>
</Context>
ps: Ant build system is fine no matter what some people may say. Go with it as you please.
I'm trying to import Google's ZXing.
I downloaded the latest release from https://code.google.com/p/zxing/downloads/detail?name=ZXing-2.2.zip&can=2&q=
From the cmd prompt I navigated to the root directory of the downloaded zxing and tried to execute
ant -f core\build.xml
PROBLEM :
Buildfile : build.xml does not exist!
Build failed
My zxing-2.2/core file contains :
src
test
pom.xml
Questions:
How to build a file that is missing?
Is it a problem from the zxing-2.2.jar I downloaded?
This problem happened to me too, I solved it by creating the build.xml file inside core folder
change name="whatever you want" in the second line, here it's "project"
code of build.xml:
<?xml version="1.0" encoding="utf-8" ?>
<project name="project" default="jar" basedir=".">
<target name="compile" description="Compile source">
<mkdir dir="bin" />
<javac srcdir="src" includes="**" destdir="bin"/>
<copy todir="bin">
<fileset dir="src" />
</copy>
</target>
<target name="jar" description="Package into JAR" depends="compile">
<jar destfile="project.jar" basedir="bin" compress="true" />
</target>
</project>
Run the build command again and see if it works.
Please do consider that you can always use the pom.xml to achieve the same. This is the method prescribed in the official zxing documentation
https://code.google.com/p/zxing/wiki/GettingStarted
The commands I have used are as follows:
cd core
mvn -DskipTests -Dgpg.skip=true install
That's it, you are done. Obviously, maven is to be installed before using the code
I tried the accepted answer, but unfortunately it not worked. Actually the jar was built successfully, but it was not built into the apk when Eclipse built the project. This was when i referenced ZXing as a library project. I managed to write an ant script which works, so i share it here:
<?xml version="1.0" encoding="utf-8" ?>
<project name="core" basedir="." default="dist" >
<property name="dist.dir" value="dist" />
<property name="src.dir" value="src" />
<property name="build.dir" value="bin" />
<target name="dist" depends="clean, package" />
<target name="clean" >
<delete dir="${build.dir}" />
</target>
<target name="init" >
<mkdir dir="${build.dir}" />
</target>
<target name="compile" >
<javac debug="off" destdir="${build.dir}" source="1.6" srcdir="${src.dir}" target="1.6" />
</target>
<target name="package" depends="init, compile" >
<jar basedir="${build.dir}" destfile="${dist.dir}/core.jar" />
</target>
</project>
If you just need the core.jar from zxing, you can skip that process and get the pre-built JARs from the GettingStarted wiki page
Core.jar is the library solution to integrate zxing in your app
(the other option is via Intent but BarcodeScanner.apk is needed)
For zxing2.2, you can obtain the core.jar from the zxing Maven repository here
Zxing 2.2 and above don't include core/build.xml
If the original file is necessary I recommend using Zxing 2.1, which can be found here:
https://code.google.com/p/zxing/downloads/detail?name=ZXing-2.2.zip&can=2&q=
I have the following defined in a file called build-dependencies.xml
<?xml version="1.0" encoding="UTF-8"?>
<project name="build-dependencies">
...
<path id="common-jars">
<fileset file="artifacts/project-1/jar/some*.jar" />
<fileset file="artifacts/project-2/jar/someother*.jar" />
</path>
...
</project>
I include it at the top of my build.xml file. Now I need to make the artifacts folder a parameter so it can be changed during execution of different targets.
Having this...
<?xml version="1.0" encoding="UTF-8"?>
<project name="build-dependencies">
...
<path id="common-jars">
<fileset file="${artifacts}/project-1/jar/some*.jar" />
<fileset file="${artifacts}/project-2/jar/someother*.jar" />
</path>
...
</project>
...and defining an "artifacts" property (and changing it) in the target does not work because it seems that the property substitution happens when the path is defined in build-dependencies.xml
How can I solve this? One way I was thinking was to have a parameterized macro and call that before the path is actually used, but that seems not elegant. Something like this:
<macrodef name="create-common-jars">
<attribute name="artifacts"/>
<sequential>
<path id="common-jars">
<fileset file="#{artifacts}/project-1/jar/some*.jar" />
<fileset file="#{artifacts}/project-2/jar/someother*.jar" />
</path>
</sequential>
</macrodef>
EDIT: Ivy and command line parameters are not an option.
You don't want a parameterized path. You want a PatternSet. You can define the patternset at the top-level and then just refer to it in individual targets when you need it. For your example:
<?xml version="1.0" encoding="UTF-8"?>
<project name="build-dependencies">
...
<patternset id="common-jars">
<include name="project-1/jar/some*.jar" />
<include name="project-2/jar/someother*.jar" />
</patternset>
...
<path id="instrumented-jars">
<fileset dir="instrumented">
<patternset refid="common-jars" />
</fileset>
</path>
...
<path id="standard-jars">
<fileset dir="not-instrumented">
<patternset refid="common-jars" />
</fileset>
</path>
...
</project>
I'd recommend using ivy to manage your classpath dependencies. Ivy has a neat concept called configurations that allows you to group collections of artifacts based on their usage.
Here's an adaption from one of my own build files:
<target name="retrieve" description="3rd party dependencies">
<ivy:resolve/>
<ivy:cachepath pathid="build.path" conf="build"/>
<ivy:cachepath pathid="runtime.path" conf="runtime"/>
</target>
The configurations are managed in the ivy.xml file (Would replace your build-dependencies.xml file)
<ivy-module version="2.0">
<info organisation="com.myspotontheweb" module="HelloWorld"/>
<configurations>
<conf name="build" description="jars needed for build" />
<conf name="runtime" extends="build" description="jars needed at runtime" />
</configurations>
<dependencies>
<dependency org="org1" name="project1" rev="1.0" conf="build->default"/>
<dependency org="org2" name="project2" rev="1.0" conf="build->default"/>
<dependency org="org3" name="project3" rev="1.0" conf="runtime->default"/>
<dependency org="org4" name="project4" rev="1.0" conf="runtime->default"/>
</dependencies>
</ivy-module>
The jar artifacts associated with each project would be downloaded and cached automatically from the on-line maven repositories or you can create your own local repository to hold collections of locally owned artifacts.
Lets call your file build.xml. So you execute it by running ant command. In the first case the artifacts names is hardcoded in the property defined on the third line below
<?xml version="1.0" encoding="UTF-8"?>
<project name="build-dependencies">
<property name="artifacts" value="first-value" />
...
<path id="common-jars">
<fileset file="artifacts/project-1/jar/some*.jar" />
<fileset file="artifacts/project-2/jar/someother*.jar" />
</path>
...
</project>
Now when you want to change it and use another value for that artifacts property, we run the script thus
ant -Dartifacts=new-value
This will override the hardcoded artifacts value in build.xml
If working in terms of ant targets you can do something similar, in the target on first line define the property, and if you want to overwrite the default value then pass the property as a parameter when that target is called.
Your comment reminded me of something else. Have your developers create a artifacts-dir-name.xml file. It will have only one line:
<?xml version="1.0" encoding="UTF-8"?>
<project name="artifacts-file">
<property name="artifacts" value="new-value" />
</project>
Now in your build.xml file, before the line where artifacts property is defined, import that file thus:
<import file="artifacts-dir-name.xml" optional="true" />
Now in Eclipse if this file exists, then the property is read from it and artifacts is set to "new-value", else the property is read from build.xml and is set to "first-value". All the developers need to do is to ensure artifacts-dir-name.xml file exists in that directory. This can run within Eclipse too.
is using environment variables an option (if they are set when eclipse is launched they will be picked up)? If so, have each one set ARTIFACTS and this should work:
<?xml version="1.0" encoding="UTF-8"?>
<project name="build-dependencies">
<property environment="env"/>
<path id="common-jars">
<fileset file="${env.ARTIFACTS}/project-1/jar/some*.jar" />
<fileset file="${env.ARTIFACTS}/project-2/jar/someother*.jar" />
</path>
</project>
OK, I think there is no other obvious way for me to do what I am trying to do, except use a macro that takes a parameter and creates the path with the appropriate artifacts folder.
To give a bit of context, why I was trying to what I wanted is to have "instrumented" and "not-instrumented" artifacts in separate folders. And in my "targets" I could just vary the artifacts mode. So what I do now is I have a macro: <initialise-build-settings artifacts-mode="instrumented" /> that sets up all the paths and other variables.
Thanks for your answers guys.
You can do this with different dependencies:
setpath.xml:
<project name="setpath">
<target name="setCommonJars">
<path id="common-jars">
<fileset file="${param1}/some*.jar" />
<fileset file="${param1}/someother*.jar" />
</path>
</target>
</project>
build.xml:
<project name="Test path" basedir=".">
<import file="./setpath.xml" />
<target name="buildT1" depends="setT1,setCommonJars">
<property name="jar-str" refid="common-jars" />
<echo message="buildT1: ${jar-str}" />
</target>
<target name="buildT2" depends="setT2,setCommonJars">
<property name="jar-str" refid="common-jars" />
<echo message="buildT2: ${jar-str}" />
</target>
<target name="setT1">
<property name="param1" value="t1" />
</target>
<target name="setT2">
<property name="param1" value="t2" />
</target>
</project>
If you call target buildT1 then the t1 directory will be used, if you call buildT2 then the t2 directory will be used.
I have a bunch of ant projects that build plug-ins that all conform to the same API. The plug-ins incorporate the third-party libraries that they depend on so that they are self-contained. As much of the behaviour in the individual build scripts was similar, I decided to pull out the common parts to a common build script.
The original build scripts looked something like this:
ProjectA/build.xml:
<project name="ProjectA" basedir=".">
...
<target name="jar">
<jar destfile="${project.target}" manifest="manifest.mf">
<fileset dir="${project.build.bin.dir}" />
<zipfileset src="externlib1.jar" />
<zipfileset src="externlib2.jar" />
</jar>
</target>
...
</project>
ProjectB/build.xml:
<project name="ProjectB" basedir=".">
...
<target name="jar">
<jar destfile="${project.target}" manifest="manifest.mf">
<fileset dir="${project.build.bin.dir}" />
<zipfileset src="externlib2.jar" />
<zipfileset src="externlib3.jar" />
</jar>
</target>
...
</project>
Here is what my build scripts look like after refactoring:
Common.xml:
<project name="Common" basedir=".">
...
<target name="jar">
<jar destfile="${project.target}" manifest="common-manifest.mf">
<fileset dir="${project.build.bin.dir}" />
<zipfileset refid="extern.libs" />
</jar>
</target>
...
</project>
ProjectA/build.xml:
<project name="ProjectA" basedir=".">
...
<zipfileset id="extern.libs">
<file file="externlib1.jar" />
<file file="externlib2.jar" />
</zipfileset>
...
<import file="../common.xml" />
</project>
ProjectB/build.xml:
<project name="ProjectB" basedir=".">
...
<zipfileset id="extern.libs">
<file file="externlib2.jar" />
<file file="externlib3.jar" />
</zipfileset>
...
<import file="../common.xml" />
</project>
However, the refactored build does not work--I believe that the problem is that I cannot declare a zipfileset that has multiple files.
I cannot figure out a way that I can declare a fileset such that the behaviour with the common jar task is the same as the behaviour where the jar tasks are declared in each project's build script. Has anyone solved this problem before? Is there a different way I can accomplish the same thing?
It's a bit fiddly, but the zipgroupfileset of the jar task may help.
Something like this for ProjectA should work. I've guessed the directory, adjust as appropriate.
<fileset dir="${project.build.lib.dir}" id="extern.libs">
<include name="externlib1.jar" />
<include name="externlib2.jar" />
</fileset>
Then in the common.xml file, I've renamed your common-manifest.mf.
<target name="jar">
<jar destfile="${project.target}" duplicate="preserve" manifest="common-manifest.mf">
<zipgroupfileset refid="extern.libs"/>
</jar>
</target>