MathJax

SyntaxHighlighter

Highlight

Custom CSS

Monday, February 23, 2009

Using maven deploy:deploy-file with wagon-ftp (it's complicated!)

I recently tried to set up a Maven repository in an environment without a servlet engine (if I had one, I'd just use Nexus instead). If you want to upload an artifact that you are managing with Maven, that's one thing; however, if you are trying to use maven deploy:deploy-file with wagon-ftp, it is inexplicably difficult. Given that a Maven repository is simply a collection of directories and files with a standardized naming scheme, I can't fathom why it's so tricky.

Well anyways, I got it working, so I figured I may as well put it here. You must be using Maven 2.0.10, the version I tested this method on. If you use other versions, you'll get weird exceptions that are geared toward making you cry instead of cluing you in that you have a version mismatch.

  1. The obvious first step is to set up an FTP server.
  2. Make sure your ~/.m2/settings.xml contains information about your server. Look at this for an example:

    
    <settings>
      <servers>
        <server>
          <id>your.server.com</id>
          <username>username</username>
          <password>password</password>
        </server>
      </servers>
    </settings>
    
  3. Search Google for the following jars on repo1.maven.org:
    It must be these specific versions for Maven 2.0.10; wagon-ftp-1.0-beta-x.jar will not work, and you'll get some cryptic stack trace if you try it. Come Maven 2.1.x, you'll be able to use the beta versions of wagon-ftp.
  4. Type the ridiculously long command found on this page. Here's an example:

    mvn deploy:deploy-file \
      -DrepositoryId=your.server.com \
      -DgroupId=mygroup \
      -DartifactId=myartifact \
      -Dversion=1.0 \
      -Dpackaging=jar \
      -DgeneratePom=true \
      -Durl=ftp://your.server.com \
      -Dfile=somejar.jar
    

    Make sure the repositoryId matches the id you have set in your settings.xml or you will get a NullPointerException (instead of some sort of authentication error, of course).
  5. Pray to various gods.
  6. Hopefully, it worked!

Update

I recently had to deal with this scenario again. As it turns out, Maven 2.0.9 from the Debian repositories worked fine; I didn't have to grab any extra jars or whatnot, and I used scp instead of ftp in my settings.xml too:

<mirrors>
  <mirror>
    <id>maven.lousycoder.com</id>
    <name>LousyCoder Maven Repository</name>
    <url>scp://maven@lousycoder.com:/var/www/maven.lousycoder.com/</url>
    <mirrorOf>maven.lousycoder.com</mirrorOf>
  </mirror>
</mirrors>

On top of that, I also made a little deployment script to avoid having to type that really really long arse command.
Post a Comment