I am trying to scp my local ear to a remote server by using ant scp task. When I am trying to scp one single file this is working fine.
But when I am trying to scp ear it just displaying "[scp] Connecting to 192.168.1.44:22" But no response at all.
These are my 2 ant targets,
1.)
<target name="copy_to_remote_folder">
<scp todir="krish#192.168.1.44:/test/jboss-4.0.3SP1/server/default/deploy" password="123456" port="22">
<fileset dir="${ant.local.ear.dir}/testPro.war"/>
</scp>
<target>
2.)
<target name="copy_to_remote_file">
<scp file="${ant.local.ear.dir}/test.xml" todir="krish#192.168.1.44:/test/jboss-4.0.3SP1/server/default/deploy" password="123456"/>
</target>
copy_to_remote_file target is working fine and the copy_to_remote_folder is not working.
What could be the reason for this?
A WAR or EAR is a single file. This line...
<fileset dir="${ant.local.ear.dir}/testPro.war"/>
... doesn't make sense. The dir attribute should be used to specify a path, the base path that contains the files you are including in the set. Instead you are pointing it to a specific file. Try this...
<target name="copy_to_remote_folder">
<scp todir="krish#192.168.1.44:/test/jboss-4.0.3SP1/server/default/deploy" password="123456" port="22">
<fileset dir="${ant.local.ear.dir}">
<include name="*.war" />
</fileset>
</scp>
<target>
... or just use your copy_to_remote_file target.
Related
I am using PMD source code analyzer (PMD) for my java web project through ant task. The computer is offline (not connected to the Internet). Part of ant task is as follows:
<target name="pmd">
<taskdef name="pmd" classname="net.sourceforge.pmd.ant.PMDTask">
<classpath>
<fileset dir="E:/pmd-bin-6.41.0/lib">
<include name="*.jar"/>
</fileset>
</classpath>
</taskdef>
<pmd shortfilenames="true" cachelocation="pmd.cache" encoding="UTF-8">
<ruleset>web/resources/category/java/bestpractices.xml</ruleset>
<formatter type="html" tofile="report.html">
</formatter>
<fileset dir="src/java/">
<include name="**/*.java"/>
</fileset>
</pmd>
</target>
When I run pmd target, report.html file is generated ok. The html file basically lists <fileName, lineNumber, description> triplets.
e.g.
foo.java...43...The initializer for variable "tempIDNo" is never used (overwritten on lin 67)
The description in this html file has a link as file:///E:ws/project/${pmd.website.baseurl}/pmd_rules_java_bestpractices.html#unusedassignment which does not work. E:ws/project/ is the folder where my project resides.
As a matter of fact, I have all the necessary html files (such as pmd_rules_java_bestpractices.html) unzipped in E:/pmd-doc-6.41.0 folder.
Could you please help me how to set up description link in html file to show local folder?
Thank you.
Here is the solution I have come up with:
(Using suggestion from (How can I create a link to a local file on a locally-run web page?)) Before ant pmd target define property pmd.website.baseurl
<propery name="pmd.website.baseurl" value="file:///E:/pmd-doc-6.41.0"/>
(Using usage/suggestion from (https://ant.apache.org/manual/Types/filterchain.html#expandproperties), ANT replacing strings in specified files using file with properties ) Change inside target as follows
...
<pmd ...>...
</pmd>
<copy file="report.html" tofile="report2.html">
<filterchain>
<filterreader classname="org.apache.tools.ant.filters.ExpandProperties"/>
</filterchain>
</copy> ...
Run the ant target.
I'm trying to copy the schema files from my workspace to a config folder as part of build.
I've achieved that by using the sync task.
These are my requirements:
1.Need to replace only the latest not every file each time.
2.Need to display in console, what are the files being changed (copied /removed)
<target name="copy-schema">
<sync todir="C:/config/schema">
<fileset dir="${schema.dir}" id="schema_dir"/>
<preserveintarget preserveemptydirs="true">
<include name="**/**" />
</preserveintarget>
</sync>
</target>
This copies the schema Files, but I'm not able to see what are the files copied.
I've tried the below,
<target name="copy-schema">
<sync todir="C:/config/schema">
<fileset dir="${schema.dir}" id="schema_dir"/>
<preserveintarget preserveemptydirs="true">
<include name="**/**" />
</preserveintarget>
</sync>
<property name="filesCopied" refid="schema_dir"/>
<echo>${fileCopied}</echo>
</target>
But it prints all the files in the directory.
Any help is appreciated.
Thanks in advance
The sync task supports a verbose attribute to log the files that are being copied.
Try adding the verbose attribute in your sync:
<sync todir="C:/config/schema" verbose="true">
I have to create a single command to create multiple(dev|qa|uat) war/ear.
Something like :
ant -f build.xml -Denv=dev|qa|uat -propertyfile= devProp|qaProp|uatProp
-Dstage.dir=devdir|qadir|uatdir
I already have different properties file, different staging, deploying target for each environment. I also have different .cmd files to build each of them separately.
What I am stuck at is: How do I build them all in one go?
You can use the <subant /> instruction in your target.
Write down a new ant script (namely master.xml), assuming that your original build is in script build.xml, you can have something like:
<target name="build-all">
<subant target="build-prod">
<fileset dir="." includes="build.xml"/>
<propertyset ......../> <!-- properties for the prod build -->
</subant>
<subant target="build-dev">
<fileset dir="." includes="build.xml"/>
<propertyset ......../> <!-- properties for the dev build -->
</subant>
</target>
Is there a way to call the Ant replace task on files in an FTP? I have a project with some static IDs in the code that change depending on whether I am on development platform or production. I setup my and build.xml file to copy all my files to FTP, but I need to change those static IDs either on the way to the FTP or when they hit it.
Ant doesnot have inbulit replace task.
I achieved it by calling "del" first and than used "put", as below.
<ftp action="del" server="%ftpservername%" userid="%ftpserver_user%" password="%ftpserver_pwd%">
<fileset>
<include name="%file1%.db" />
<include name="%file2%.db" />
</fileset>
</ftp>
<ftp action="put" retriesAllowed="-1" remotedir="%dest_dir%" server="%ftpservername%" port="%ftpport%" userid="%ftpserver_user%" password="%ftpserver_pwd%" binary="yes">
<fileset dir="%src_dir%">
<include name="%file1%.db" />
<include name="%file2%.db" />
</fileset>
</ftp>
we can also do for directory which is in ant.apache.org
If you are looking to do replace within the ant ftp task, it looks like this is not supported. But you could do a replace followed by ftp.
<replace dir="${ftp.src} token="###" value="replaced"/>
<ftp server="server" userid="user" password="password">
<fileset dir="${ftp.src}"/>
</ftp>
Or perhaps you are looking for something different.
I am trying to create a war file out of an eclipse project using ant
The responsible ant target looks like this
<target name="jar" depends="build" description="Erzeugt das WAR File">
<war destfile="${project.dir.dist}/xyz.jar" webxml="${basedir}/WebRoot/WEB-INF/web.xml" duplicate="fail" basedir="${basedir}">
<lib dir="${project.dir.dist}" excludesfile="${project.dir.dist}/xyz.jar" />
<classes dir="${project.dir.bin}" />
<webinf dir="${basedir}/WebRoot/WEB-INF" excludes="*.class" />
<metainf dir="${basedir}/WebRoot/META-INF" />
</war>
</target>
And it fails with the following error:
F:\eclipse_workspaces\skyeye\railWeb\build.xml:35: Syntax error in property: ??? ???i8?
Google search turned up only this: http://209.85.135.132/search?q=cache:OrmNOY9EJd0J:teamcity.jetbrains.com/viewLog.html%3Bjsessionid%3D114D52086BAE423B2F69A99B4CFACACD%3FbuildId%3D29573%26tab%3DbuildChangesDiv%26buildTypeId%3Dbt134+ant+war+task+%22Syntax+error+in+property%22&cd=1&hl=en&ct=clnk&client=firefox-a
Can anybody explain, what the heck is going on?
The propblem was that I used 'excludesFile' assuming it would exclude a single file. Instead ANT tried to parse it as an property file which gets difficult since it actually was a jar file.
The correct way to exclude a jar file is given in the documentation. If anyone face same issue, they can refer to this link.
This example is taken from the documentation, here we are removing jdbc1.jar from lib
Assume the following structure in the project's base directory:
thirdparty/libs/jdbc1.jar
thirdparty/libs/jdbc2.jar
build/main/com/myco/myapp/Servlet.class
src/metadata/myapp.xml
src/html/myapp/index.html
src/jsp/myapp/front.jsp
src/graphics/images/gifs/small/logo.gif
src/graphics/images/gifs/large/logo.gif
then the war file myapp.war created with
<war destfile="myapp.war" webxml="src/metadata/myapp.xml">
<fileset dir="src/html/myapp"/>
<fileset dir="src/jsp/myapp"/>
<lib dir="thirdparty/libs">
<exclude name="jdbc1.jar"/>
</lib>
<classes dir="build/main"/>
<zipfileset dir="src/graphics/images/gifs"
prefix="images"/>
</war>
will consist of
WEB-INF/web.xml
WEB-INF/lib/jdbc2.jar
WEB-INF/classes/com/myco/myapp/Servlet.class
META-INF/MANIFEST.MF
index.html
front.jsp
images/small/logo.gif
images/large/logo.gif