Copy files from a zip folder to another folder in nant - nant

I want to copy the files from the zip folder to another folder.
I am doing this , but it doesn't works
<copy todir="Lib">
<fileset basedir="Output/RCxSL.Client.zip/ServiceClientDlls">
<include name="*.dll" />
</fileset>
</copy>
How to achieve this ? the folder is zipped.

A ZIP folder is not a folder, it is a ZIP file, even though the operating system (through your files explorer) may make it look like a folder. Instead of using <fileset> and <copy>, use the unzip task of NAnt.
<unzip zipfile="Output/RCxSL.Client.zip" todir="Lib" />

Related

copy file with different name with phing

I wrote a script in Phing that copies files for two websites, but I can't do such thing like copy file with a name change. I want to copy this image into favicon.png.
<copy todir="C:\dest_folder\" >
<fileset dir="C:\source_folder\" >
<patternset>
<include name="assets/ico/favicon_website1.png"/>
</patternset>
</fileset>
</copy>
Can this be done in only one <copy> tag?
How can I do it?
I expect quite a few files to be copied with a changed name so I want to simplify the script.
If it's just the one file you want to rename, use tofile rather than a fileset.
<copy file="assets/ico/favicon_website1.png" tofile="C:\dest_folder\favicon.png" />

Is it possible to create an ant-build file for a wikitext project automatically in eclipse?

I have a few hundred textile files in my eclipse project and I have written an ant-build xml file for creating the output html files. This works fine normally. However, every time I add some .textile files to the project, I also have to edit the projectBuilder.xml file manually if the the output has to be generated.
Is there a way in eclipse where I can generate the projectBuilder.xml file automatically? i.e. Lets say, I add a new folder with some 50 subfolders having .textile files inside them, I want eclipse to detect this and add those paths to the build file.
Following is part of the build file for illustration purpose:
<?xml version="1.0"?>
<project name="ALM" default="generate-html">
<property name="wikitext.standalone" value="jar" />
<path id="wikitext.classpath">
<fileset dir="${wikitext.standalone}">
<include name="org.eclipse.mylyn.wikitext.*core*.jar" />
</fileset>
</path>
<taskdef classpathref="wikitext.classpath" resource="org/eclipse/mylyn/wikitext/core/util/anttask/tasks.properties" />
<target name="generate-html" description="Generate HTML from textile source">
<wikitext-to-html markupLanguage="Textile">
<fileset dir="${basedir}/..">
<include name="Docu/*.textile" />
<include name="Add-Ons/*.textile" />
<include name="uC1/asv/ASD/doc/*.textile" />
I'm not sure, which of these 2 problems you have.
To automate the transformation process, select Project->Properties->Builder. Add an Ant builder and give it the Ant script that you already have. This leads to running your script on every change in the project (like the normal Java compiler). If you want to run the Ant script only when your textile files change, then have a look at the last tab "Build options" when configuring that builder, there you can restrict it to a "working set of relevant resources".
To dynamically get the list of directories, there are multiple ant tasks available and it might depend on your project layout what to use: Using fileset you could just find all textile files and then use the fileset contents for the generation: Find all directories in which a file exists, such that the file contains a search string Or if the directory structure very plain, then you can just iterate it with foreach: Ant: How do I interate over all subfolders and perform a task in ant.

How can I set Ant to copy specific files to output?

I am developing in eclipse websites in php.
I want to create a build configuration using Ant, to copy files from the project folder to a specific output path.
How is this possible using eclipse builders?
Ant copy task: http://ant.apache.org/manual/Tasks/copy.html
Example which copies one file to another:
<!-- copy file -->
<copy file="./service.jar" tofile="./service-v1.jar" overwrite="true"/>
Example which copies all XML, PNG, and JSON files from one directory to another, maintaining folder structure:
<!-- copy files -->
<copy todir="./destination">
<fileset dir="./src">
<include name="**/*.xml"/>
<include name="**/*.png"/>
<include name="**/*.json"/>
</fileset>
</copy>

Best way to deploy large *.war to tomcat

During development I frequently have to deploy a large war-file (~45 MB) to a remote test server, normally I copy the file with scp to the server.
The WEB-INF/lib folder makes up the largest part of the war file, which includes all the required libraries (spring, apache-cxf, hibernate,...).
Now I'm searching for an fast and easy a way to redeploy only my altered files.
And how can I determine which packages are really needed by the webapp, because spring and apache-cxf comes with a lot of libs, I'm sure I don't need all of them.
When you deploy a .war, the first thing Tomcat does is to unpack that file into its webapps directory, in a subdirectory with the same name as your .war.
During development, you obviously have access to your .class files, the .jar files, configuration files and whatever else eventually goes into your .war. You can easily establish a small subset of files affected by your changes. Figure that out, and then use a script or an ant task or whatever to copy just that small handful of files straight into the webapps/yourapp directory on the server.
To see your changes take effect, you'll need to re-start your application. If Tomcat is in development mode, one easy way to force a reload (and restart, of course) is to update WEB-INF/web.xml. So have your deployment process touch that file or otherwise update it in a way that will give it a new timestamp, scp that over too (preferrably as the last of the files you update) and you should have a quick and easy reload.
What I do is exclude WEB-INF/lib/*.jar files from the WAR and reassemble on the server side. In my case, this trims a 60MB WAR down to 250k which allows for really fast deployment.
The <exclude name="**/lib/*.jar"/> command is what excludes the jar's (see last code snippet for ANT build)
On the server side, it's quite easy to assemble a fully populated WAR from the trimmed WAR:
unzip/explode the trimmed WAR that was created by the ANT script below
copy the server repository jar files into the exploded WEB-INF/lib
zip is all up into a new (large) WAR.
deploy as usual.
For example:
unzip ../myapp.trimmed.war
mkdir WEB-INF/lib
cp ../war_lib_repository/* WEB-INF/lib
zip -r ../myapp.war .
Maybe not the most elegant solution, but it saves time on frequent deployment of large WAR's. I'd like to be able to do this with Maven so if anyone has suggestions, please let me know.
ANT build.xml:
<property file="build.properties"/>
<property name="war.name" value="myapp.trimmedwar"/>
<property name="deploy.path" value="deploy"/>
<property name="src.dir" value="src"/>
<property name="config.dir" value="config"/>
<property name="web.dir" value="WebContent"/>
<property name="build.dir" value="${web.dir}/WEB-INF/classes"/>
<property name="name" value="${war.name}"/>
<path id="master-classpath">
<fileset dir="${web.dir}/WEB-INF/lib">
<include name="*.jar"/>
</fileset>
<!-- other classes to include -->
<fileset dir="${birt.runtime}/ReportEngine/lib">
<include name="*.jar"/>
</fileset>
<pathelement path="${build.dir}"/>
</path>
<target name="build" description="Compile main source tree java files">
<mkdir dir="${build.dir}"/>
<javac destdir="${build.dir}" debug="true" deprecation="false" optimize="false" failonerror="true">
<src path="${src.dir}"/>
<classpath refid="master-classpath"/>
</javac>
</target>
<target name="createwar" depends="build" description="Create a trimmed WAR file (/lib/*.jar) excluded for size">
<!-- copy the hibernate config file -->
<copy todir="${web.dir}/WEB-INF/classes">
<!-- copy hibernate configs -->
<fileset dir="${src.dir}/" includes="**/*.cfg.xml" />
</copy>
<copy todir="${web.dir}/WEB-INF/classes">
<fileset dir="${src.dir}/" includes="**/*.properties" />
</copy>
<!-- copy hibernate classes -->
<copy todir="${web.dir}/WEB-INF/classes" >
<fileset dir="${src.dir}/" includes="**/*.hbm.xml" />
</copy>
<war destfile="${name}.war" webxml="${web.dir}/WEB-INF/web.xml">
<fileset dir="${web.dir}">
<include name="**/*.*"/>
<!-- exlude the jdbc connector because it's on the server's /lib/common -->
<exclude name="**/mysql-connector*.jar"/>
<!-- exclude these jars because they're already on the server (will be wrapped into the trimmed war at the server) -->
<exclude name="**/lib/*.jar"/>
</fileset>
</war>
<copy todir="${deploy.path}" preservelastmodified="true">
<fileset dir=".">
<include name="*.war"/>
</fileset>
</copy>
</target>
I use rsync to copy my .war from my local machine to production. It usually provides a big speed up, around 8-10 times.
Another option is to use git to store the .war files. When you git push a new .war, only the differences are transferred. Also a big speed up. Some people say that git is not designed to store big files, it gets slow and does not work very well. In fact yes, the repo will grow a lot, but in some cases it could be a good option.
Some numbers: My .war is about 50MB and when I deploy a new version, it only copies about ~4MB instead of uploading a complete new war. Both with git and rsync.
UPDATE: The problem I ran into it's the git repo cannot be cloned after it has several .war versions because it will take forever to create all the deltas and transmit them to the client.
I changed the strategy by uploading the .war files into dropbox. Dropbox also uses kind of rsync and only copies deltas. From the server I wget the .war and re-reploy the app. Hope this helps.
Improving on Rori Stumpf answer, here is a Gradle task for the 'thinning'
war {
archiveName "v1.war"
}
task createThinWar(type: Copy) {
dependsOn 'war'
def tmpFolder = "${buildDir}/tmp/thin"
def outputDir = "${buildDir}/libs"
// Extract the war (zip) contents
from zipTree("${outputDir}/v1.war")
into "${tmpFolder}/v1"
doLast {
// Extracting the war third party libraries to a separate dir
ant.move(file: "${tmpFolder}/v1/WEB-INF/lib", tofile: "${tmpFolder}/v1-libs")
// Zip the third party libraries dir
ant.zip(destfile: "${outputDir}/v1-libs.zip") {
fileset(dir: "${tmpFolder}/v1-libs")
}
// Finally zip the thinned war back
ant.zip(destfile: "${outputDir}/v1-thin.war") {
fileset(dir: "${tmpFolder}/v1")
}
}
}
This will generate v1-thin.war (weighting less then 1mb), and a libs zip.
deploy the thin war to the server (and reconstruct the libs there), and deploy the libs zip whenever you modified the versions/add libraries.
I don't think there's a faster way to redeploy only the changes to a WAR file.
If you deploy in exploded fashion you can see what file timestamps have changed and act accordingly, but you'll have to write code to do it.
I don't know if OSGi can be a help here. That would allow you to partition your problem into modules that are more independent and swap-able.
Just curious:
How long does it take now?
Do you use continuous integration to build and deploy?

Once saved in eclipse, copy project to a different directory

Using Eclipse, is there a way to automatically copy a file/project's directory to a different path once it's saved?
Effectively, when i save a file, it copies it from the workspace to the deploy directory
Workspace: "/code/my_app"
deploy to: "/application/plugins/my_app"
EDIT:
This is Mainly for Python and PHP projects
You can do that with Apache Ant pretty easily. There's even an Ant View in eclipse to run the script from. See the copy task.
Here's a sample ant build.xml file:
<project name="whatever" default="copy">
<target name="copy">
<copy todir="someDir">
<fileset dir="someOtherDir/" casesensitive="yes">
<include name="**/*.java"/>
<exclude name="**/*Test*"/>
</fileset>
</copy>
</target>
</project>
You can also add more targets for deploying your application.
Try “Ant Builder” :).
i have not tried this but this looks nearly what you want.