Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

Overview

Although deploying sites to a Unix based server is easier such an option is not always available. In such a situation it is possible to configure maven for automated site deployment to a Windows box. Unfortuantely, as of this writting only the wagon-ssh and wagon-ssh-external implementations are capable of deploying a directory as required by the site plugin. The actual wagon-ssh implementation goes through the following steps in moving a directory.

...

No Format
titlesite:deploy console output
dos prompt>mvn  site:deploy
[INFO] Scanning for projects...
[INFO] Searching repository for plugin with prefix: 'site'.
[INFO] ----------------------------------------------------------------------------
[INFO] Building Maven NDoc Report Plugin
[INFO]    task-segment: [site:deploy]
[INFO] ----------------------------------------------------------------------------
[INFO] [site:deploy]
scp://whouatl8z9tn91/cygdrive/c/Apps/Tomcat5.5/webapps/ROOT/mvnsites/maven-ndoc-plugin/1.0.1-SNAPSHOT - Session: Opened

Executing command: mkdir -p /cygdrive/c/Apps/Tomcat5.5/webapps/ROOT/mvnsites/maven-ndoc-plugin/1.0.1-SNAPSHOT/.
Executing command: mkdir -p /cygdrive/c/Apps/Tomcat5.5/webapps/ROOT/mvnsites/maven-ndoc-plugin/1.0.1-SNAPSHOT/.
Executing command: scp -t /cygdrive/c/Apps/Tomcat5.5/webapps/ROOT/mvnsites/maven-ndoc-plugin/1.0.1-SNAPSHOT/./wagon65147
.zip
Uploading: ./wagon65147.zip to scp://whouatl8z9tn91/cygdrive/c/Apps/Tomcat5.5/webapps/ROOT/mvnsites/maven-ndoc-plugin/1.
0.1-SNAPSHOT

###########################
Transfer finished. 110209 bytes copied in 0.081 seconds
Executing command: cd /cygdrive/c/Apps/Tomcat5.5/webapps/ROOT/mvnsites/maven-ndoc-plugin/1.0.1-SNAPSHOT/.; unzip -q -o w
agon65147.zip; rm -f wagon65147.zip
scp://whouatl8z9tn91/cygdrive/c/Apps/Tomcat5.5/webapps/ROOT/mvnsites/maven-ndoc-plugin/1.0.1-SNAPSHOT - Session: Disconn
ecting
scp://whouatl8z9tn91/cygdrive/c/Apps/Tomcat5.5/webapps/ROOT/mvnsites/maven-ndoc-plugin/1.0.1-SNAPSHOT - Session: Disconn
ected
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESSFUL
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 5 seconds
[INFO] Finished at: Thu Sep 07 09:28:07 CDT 2006
[INFO] Final Memory: 3M/6M
[INFO] ------------------------------------------------------------------------

dos prompt>

Non-Interactive Shell Considerations

It is very important to realize that executing a command in a non-interactive ssh shell is different from executing it via an interactive ssh shell. When running a non-interactive command the unix shell is configured with a subset of the dot files used when logged in interactively. For example in the bash shell, only the .bashrc file appears to be read, whereas an interactive bash is typically configured by both .bashrc and .bash_profile.

...

No Format
titleExamples of Remote Executions of Various Commands
dos prompt>plink remoteuser@remotemachine.somecompany.com 'pwd'
dos prompt>plink remoteuser@remotemachine.somecompany.com 'ls'
dos prompt>plink remoteuser@remotemachine.somecompany.com 'echo ${PATH}'
dos prompt>plink remoteuser@remotemachine.somecompany.com 'unzip --help'

Cygwin and OpenSSH

As you can now see, any attempt to deploy to a windows server must make the maven wagon-ssh implementation think the remote server is a unix box. Therefore, just using a simple to install ssh server such as FreeSSHd isn't sufficient, as it doesn't provide a shell which provides mkdir, unzip and rm. Logging into to windows server running FreeSSHd is just like being in a dos shell, and dos shells don't support unix commands. Consequently, the easiest thing to do is to simply get openSSH running via Cygwin, making sure the required commands are in the PATH of the relevant user's non-interactive ssh shell.

A discussion of setting up openSSH via Cygwin is beyond the scope of this document. With a quick search on google for "openSSH cygwin" I quickly found the following how-to document: http://pigtail.net/LRP/printsrv/cygwin-sshd.html. By following this document along with a bit of poking around, the reader will hopefully quickly get openSSH up and running.

Example Snipts from settings.xml and pom.xml

No Format
titlesettings.xml snipt
    <servers>

        <server>
            <id>website</id>
            <username>remoteuser</username>
            <password>remotepass</password>
        </server>
        <!--password and key file based auth both appear to work with the wagon-ssh implementation
        <server>
            <id>website</id>
            <passphrase>somepassphrase</passphrase>
            <privateKey>C:/sshkeys/id_rsa</privateKey>
        </server>
        -->
    </servers>
No Format
titlepom.xml snipt
  <distributionManagement>
        <repository>
            <id>custom-repository</id>
            <url>ftp://somemachine.somecompany.com</url>
        </repository>
        <site>
            <id>website</id>
            <url>scp://somemachine.somecompany.com/cygdrive/c/Apps/Tomcat5.5/webapps/ROOT/mvnsites/mymodule/${project.version}</url>
            <!--<url>scp<url>sftp://somemachine.somecompany.com/cygdrive/c/Apps/Tomcat5.5/webapps/ROOT/mvnsites/mymodule/${project.version}</url>-->
        </site>
    </distributionManagement>