I'd like to copy a file to a remote server with scp after building, using Netbeans.
What I do now manually is:
Clean and Build Main Project
scp dist/project.jar login#dest/...../......
Is there some way to automate this task? I tried looking at the build.xml file, but it really looks like something I don't want to mess with.
Thanks
Nicola
I use WinSCP to perform something similar to this. I monitor a local directory for file changes and it automatically transfers the changes files.
This is possible, see the scp task on ant's site: http://ant.apache.org/manual/Tasks/scp.html
An example from the site:
Copy a set of files to a directory
<scp todir="user:password#somehost:/home/chuck">
<fileset dir="src_dir">
<include name="**/*.java"/>
</fileset>
</scp>
<scp todir="user:password#somehost:/home/chuck">
<fileset dir="src_dir" excludes="**/*.java"/>
</scp>
You can hardcore the password inside the build task, but that's not a great idea. Better to use public keys.
Related
When faced with the unenviable task of cleaning all generated project artefacts/resources in a stock-standard Java EE/Tomcat configuration, I generally do one (or all) of 3 things:
Project/Clean
Right-click my server, and delete any artefacts (can't remember the exact command)
Source/Clean
I'm now playing around with the Google Eclipse Plugin for Appengine, which uses an inbuilt Jetty server.
Firstly, the plugin doesn't have any options to clean out generated class files before redeploying (well, not that I can see anyway). And secondly, the sever is not available as a configuration option.
Are there any quick fixes available to clean all artefacts/resources in my war/WEB-INF directory?
You can easily make it about one click and not unenviable. Just use ant and pattern matching. Open the ant view in Eclipse and add your file and it's just a click away.
Before 1.7 when app size was more limited, I used to copy almost everything out so I could upload it and serve from the blobstore (GWT permutations galore!). I was doing this alot!!!
see these for details http://ant.apache.org/manual/Types/fileset.html and http://ant.apache.org/manual/Tasks/delete.html
Here's my simple code example:
<target name="moveXprojectGae">
<delete includeemptydirs="true">
<fileset dir="XprojectGae" includes="**/*"/>
</delete>
<move todir="XprojectGae">
<fileset dir="war/XprojectGae">
<exclude name="**.rpc"/>
<exclude name="**nocache.js"/>
</fileset>
</move>
</target>
I'm triyng to create a generic phing script that will build a joomla plugin.
Each joomla plugin must hava an .xml file that is used by joomla system to install the plugin. In this xml file we need to define what files and folders our zip archive has like this:
<files>
<folder>folder1</folder>
<filename plugin="nameofplugin">nameofplugin.php</filename>
<filename>index.html</filename>
</files>
Now, because I'm lazy and I don't want to do this thing always myself I want to have the phing script do this for me.
I have all the plugin files moved to a specific folder like this:
-pluginFolder
--folder1
--nameofplugin.php
--index.php
I see that I can use foreach like this:
<foreach param="dirname" absparam="absname" target="subtask">
<fileset dir="${destination.dir}">
<type type="file" />
<depth max="0" min="0" />
</fileset>
</foreach>
<target name="subtask">
<echo msg="<file>: ${dirname}" />
</target>
now here in the subtask I fail to figure out how to do merge all the files to a single variable so that I can then use replacetokens for example?
Any ideas about this? Should I build my own phing class that does this? Or is there an easy way to achieve this with what phing has to offer out of the box?
Ok, I managed to achieve what I wanted. I created a new phing task and made the replacement in there.
You can see how it works on the base of this joomla plugin:
https://github.com/compojoom/CUpdater
The build.xml file is here:
https://github.com/compojoom/CUpdater/blob/master/builds/plugin.xml
and the task is here:
https://github.com/compojoom/CUpdater/blob/master/builds/phingext/listjpackagefilestask.php
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.
I know about the export->war file
I would like something similar to the .jardesc that allows you to define the destination. So I could right-click on that .jardesc and do export. Except .wardesc instead of .jardesc :)
Is the war export functionality tied to an eclipse ant task?
I've put together an AHK macro so it will do the GUI motions for me... but that's a hack not a solution.
Is the war export functionality tied to an eclipse ant task?
As far as I know, yes. You might try searching for a plugin that can do this for you; I found a couple, such as the war-plugin builder, but I haven't tried it myself, as I try to avoid using extra plugins in eclipse.
Theres the Ant WAR task.
Eclipse has the notion of external commands. If you can write e.g. an ant script that does the export the way you like it you can start it from the menu/button. For ant scripts you can also pick the ant target you want to call and pass properties. This allows you to edit e.g. the path name in the Launch Configuration.
The right way to do "war export" is to use a build system (like Maven) and let it do the heavy lifting. All you need is a pom.xml with <packaging>war</packaging>.
Eclipse's exports are meant for occasional exports by humans, not for automation. And if you would really like to automate, do it right. You will benefit from other things, too. The same pom file will run on your machine, on other developers' machines and on your build server.
WAR ant task
http://ant.apache.org/manual/Tasks/war.html
from the documentation:
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
As part of the Nant copy task, I would like to change the properties of the files in the target location. For instance make the files "read-write" from "read-only". How would I do this?
Use the <attrib> task. For example, to make the file "test.txt" read/write, you would use
<attrib file="test.txt" readonly="false"/>
Also, for a list of files, the command is:
<attrib readonly="false">
<fileset basedir="mydirectory">
<include name="**"/>
</fileset>
</attrib>