13 September 2007

Remote copy with SCP and JDeveloper External Tools

I'm currently working on developing some examples for use cases for our Release 11 product. I tend to flick around between the IDEs I use, Eclipse and JDeveloper -- for example, I find that the support JDeveloper has for packaging J2EE applications is a bit easier to use than the analogs in Eclipse. Or perhaps its just that I've used it a bit more and know how to work around its foibles.

Anyway, the situation I ran into is that my install of 11AS is on a hosted server back at HQ. And I'm using JDeveloper 10.1.3 on my laptop here in Adelaide. So any time I wanted to deploy the applications to test them, I had to manually SCP/SFTP the application archive up to the server then deploy it. I know its trivial, but it was becoming a pain in the arse after a while. It's kind of funny how something so incidental sometimes becomes a beast of burden.

How could I make my life easier? Well I was just about to write myself a 5 line Ant script to do it, which used the task and then run that from JDeveloper to automate the copy process. But then I just happened to notice the "External Tools" menu item.
Hmm I said out loud -- could I just use that instead?

Well all you need to do is crack open the External Tools menu item and Add a new item.

To copy a file from my local PC to the server, I ultimately need a command that looks like this :

pscp -pw password username@server:/dir

All you need to do then is to fill in the relevant fields to produce that command.

There are some nice elements in the dialog that help you construct the generic command. I used three of these in my command:
  1. To allow me to enter the password when the command is run, I used the prompt directive:

    ${prompt:label=Password}

  2. To specify the file to upload, I used the file.path directive:

    ${file.path}

  3. To specify the target server, I used an environment variable substitution. I'm lazy and to avoid typing, I set the common target server details as an environment variable so that from the command line I can use some shorthand like this "pscp %SCP% ...". To include the environment variable, I used the env.var directive:

    ${env:var=SCP}
In the external tool dialog, putting it together looks like this:



Cool.

Now to put it to use.

When I want to copy an application archive up to my server for deployment, all I need to do is select the archive in the Navigator and select PSCP from the right mouse menu:



The password is then queried:



And finally the full command is constructed and run:



Voila.

One gotcha I found was that the deployment archives are not shown by default in the various JDeveloper Navigators (why it doesn't show them in a "deploy" directory in the navigator BTSOOM).

So to force JDeveloper to show you the generated archives, add the "deploy" directory to the Project Content directories:



----------------
Listening to: Ride - Twisterella

No comments: