Archive for January, 2006

Corporate https maven2 repositories

Thursday, January 26th, 2006

So you started using maven / maven2 in your organization. Now you need a place to deploy your company specific artifacts. You also don’t want to depend on an external repository to perform your build.

So setting up a corporate repository is a natural step. Unfortunately, I’ve found that the information describing how to do this is scattered around several places. So here’s a single page version that works for us.

The following short guideline explains how to deploy artifacts to a remote server using scp and retrieve them using https.

Note: I am using apache 2.0.55 under Linux on the server and maven 2.0.2 and SDK 1.5 under Linux on the client. In this example, the serve’s named dev.domaine.com. There are some variations for Windows.

Note2: it is possible to setup your system differently. maven2 is flexible. This just describe one way to make it work, which was I believe, the simplest and most flexible way for us to achieve our goal.

Deploying artifacts on your server

Most of this information comes from this page. My preferred setup is to use scp and an ssh agent for handling my keys.

  • on your server, create a place where to put your artifacts. E.g. /home/m2/public_html
  • use suitable permissions for developers to be able to deploy artifacts there and for your web server to be able to serve the files later on
  • 2 cases:
    • If you have control over the pom.xml of the project you are trying to deploy, deploying your artifact is easy. Just add the following information to your project’s pom.xml:
      <distributionmanagement>
        <!-- use the following if you're not using a snapshot version. -->
        <repository>
          <id>ssh-repo</id>
          <name>Repository Name</name>
          <url>scp://host/path/to/repo</url>
        </repository>
        <!-- use the following if you ARE using a snapshot version. -->
        <snapshotrepository>
          <id>ssh-repo</id>
          <name>Repository Name</name>
          <url>scp://host/path/to/repo</url>
        </snapshotrepository>
      </distributionmanagement>
      

      Then add an entry in your ~/.m2/settings.xml:

      <settings>
        ...
        <servers>
          ...
          <server>
            <id>ssh-repo</id>
            <username>...</username>
            ...
          </server>
        </servers>
        ...
      </settings>
      

      And finally, deploy doing mvn deploy.

    • When you don’t have control over the pom, you will need to specify the repository related information on the command line. You will use the deploy:deploy-file goal.
      • If you already have a pom for your artifact, it is best to instruct the plugin to pick the information from the pom. You will end up doing something like:
        mvn deploy:deploy-file -Durl=scpexe://dev.domaine.com/home/m2/public_html -DrepositoryId=ssh-repo pomFile=pom.xml -Dfile=the.jar
      • If you don’t have a pom, you will have to specify all the other arguments:
        mvn deploy:deploy-file -DgroupId=... -DartifactId=... -Dversion=... .... -Durl=scpexe://dev.domaine.com/home/m2/public_html -DrepositoryId=ssh-repo pomFile=pom.xml -Dfile=the.jar
    • In both cases you will need to add a <server> entry to your settings.xml file, as specified above.

Make these artifacts accessible from your client

  • Generate/sign an ssl certificate for your server. On Linux, it will probably be stored somewhere like /etc/ssl/apache2/server.crt
  • Make sure your repository directory is available under apache. E.g.
    Alias /m2 /home/m2/public_html
    <directory /home/m2/public_html>
      AllowOverride None
      Options Indexes FollowSymLinks
      Order allow,deny
      ....
    </directory>
    
  • Protect this directory using usual Apache access rights management tools
  • Test. Point your browser to https://dev.domaine.com/m2. The browser should ask for username/password. You may or not need to prepend a slash to your url depending on your apache configuration.

Let’s make this work with maven2!

  • Import your server ssl certificate into your JVM keystorre. As root:
    keytool -keystore $JAVA_HOME/jre/lib/security/cacerts -import -file server.crt. You will need the keystore password to modify it. By default this password is ‘changeit‘. Note: If you change SDK, you will need to redo this operation. Note: if you already have a certificate under the “mykey” alias, you may have the following error:
    keytool error: java.lang.Exception: Certificate not imported, alias already exists

    In that case, import the other one under a new alias (-alias newalias) or remove your old certificate (keytool -keystore $JAVA_HOME/jre/lib/security/cacerts -delete -alias mykey).
  • on your project: add a repository to your pom:
        <repository>
          <id>https-repo</id>
          <name>My Company Repository</name>
          <url>https://dev.domaine.com/m2</name>
        </repository>
    
  • if you host plugins on your corporate repository, you may also need to add something like:
      <pluginRepositories>
        ...
        <pluginRepository>
          <id>https-repo</id>
          <url>https://dev.domaine.com/m2</url>
        </pluginRepository>
    
      </pluginRepositories>
    
  • Modify your ~/.m2/settings.xml. That’s where you will add your personnal authentication information:
    <settings>
      ...
      <servers>
        ...
        <server>
          <id>https-repo</id>
          <username>...</username>
          <password>...</password>
        </server>
      </servers>
      ...
    </settings>
    
  • clean up your local maven repository to test downloading from the remote one. E.g. rm ~/.m2/repository/com/domaine/...
  • Test building your project. e.g. m2 install.
  • If you have any issue and you think it might be ssl related, enable debugging using the javax.net.https unsupported option. You might want to try m2 -Djavax.net.https=ssl install. -Djavax.net.https=all for more info and -Djavax.net.https=help for usage information.

Troubleshooting and common mistakes

  • Note: trying to use a a full basic auth url (https://user:password@dev.domaine.com/m2), either in the pom or on the command line won’t work. You have to externalize your login/password into an external file
  • if you are deploying a multi-project, and one module is not deployed and you get a generic error that says something like:
    
    Failed to configure plugin parameters for: org.apache.maven.plugins:maven-deploy-plugin:2.1
    
    check that the following section of the pom.xml is present and correct:
    
    <distributionManagement>
      <!-- use the following if you're not using a snapshot version. -->
      <repository>
        <id>repo</id>
        <name>Repository Name</name>
        <url>scp://host/path/to/repo</url>
      </repository>
      <!-- use the following if you ARE using a snapshot version. -->
      <snapshotRepository>
        <id>repo</id>
        <name>Repository Name</name>
        <url>scp://host/path/to/repo</url>
      </snapshotRepository>
    </distributionManagement>
    
    Cause: Class 'org.apache.maven.artifact.repository.ArtifactRepository' cannot be instantiated
    [INFO] ----------------------------------------------------------------------------
    [...]
    Caused by: java.lang.InstantiationException: org.apache.maven.artifact.repository.ArtifactRepository
            at java.lang.Class.newInstance0(Class.java:335)
            at java.lang.Class.newInstance(Class.java:303)
            at org.codehaus.plexus.component.configurator.converters.AbstractConfigurationConverter.instantiateObject(AbstractConfigurationConverter.java:111 )
            ... 24 more
    

    then be sure to follow the recommendations in the error log. A classical mistake is to have forgotten to inherit the module’s pom from the parent pom where this information was stored.

  • when deploying a module, maven searches the repositories referenced in the pom for the dependencies of the module. I think the idea is to identify whether the required dependency versions are already deployed. If you try to deploy a multi project whose modules depend on each other, you will probably have to make sure that the target repository is listed in the <repositories> section of your pom, otherwise the deploy operation might fail, not finding a suitable version for your module, even though the dependency might just have been uploaded there. Maven has no way to know that fact (especially as you refer to a repository differently when you upload or retrieve information from it, and also because each module deployment is treated independently of the others, even in the case of a multi-project).

Last advice: you might want to have one repository for snapshots and one for releases. That might simplify backing up operations on the server if you only want to backup your releases.

Voila! m2 should now download your artifacts from new your shiny corporate repository. Good luck!

update: added information on how to update the imported certificate.

What happened to the java.net pack200 ant tasks project?

Friday, January 13th, 2006

I am getting more and more fed up with Sun and the java.net project.

When I started writting the Maven2 webstart plugin, I reused functionality from both mustang (the jnlp-servlet) and the java.net pack200 ant tasks.

First my request to create a java.net project to put the jnlp-servlet BSD code is stalled. I’ve created my project 2 months ago and I am still waiting. I sent mails, added a note to a related BUG parade issue, and created an issue in the java.net issue tracker. Not a single feedback.

Now the advanced search page doesn’t work.

Now I have been unable to reach the pack200 ant tasks web site for some time and I just discovered that its link seems to have disappeared from the listing. As it is the unique project on that page without a link to the home page, I am wondering if something fuzzy is going on.

Unfortunately I’ve suffered 2 hardware failures in the past month (RAM leading to disk corruption on master disk + dropped external backup disk…), so if i’ve lost the original code for the project (apparently under the SDL license).

So can someone please tell me where to get this code, and if not, let me know why the project was removed from java.net without an explanation?

update: forgot some links. The pack200 ant tasks project was here and the author was probably Kumar Srinivasan.

update (26/01/2006): seems like the project page appeared again. It is still not part of the listing thus. And I am still waiting for the jnlp-servlet to be created… What time does the Sun raise in the sky?

NetBeans 5.0 beta2

Friday, January 6th, 2006

I’ve been giving NetBeans 5.0 beta2 a try in the past 2 weeks. After reading so much praise on the web, I will have to say I am a little bit disappointed. It’s a major improvement over the previous version, for sure and it has a bunch of features I will definitively use (the J2ME application editor, the profiler, and maybe Matisse the GUI editor), but some things just don’t make it. E.g. why do I have to chose between CVS and subversion?

So for my core needs, I will stick to IDEA which today bring me a better set of refactoring tools, very good scm support (even though I prefer command line, some of my customers do prefer the GUI), a much more integrated editor and very slick shortcuts all over the place, making me much more productive.

And it’s not just by habit. As an example of producitivity and usability issues, here’s a quick list of the things I am used to do in IDEA which I can’t seem to do easily in NetBeans:

  • full and simple keyboard navigation. Open your Windows meny and compare the Alt+n IDEA has vs the Ctrl-n/Shift+Ctrl+n/ options NetBeans gives
  • expand the source browser to full screen (Yes it’s possible in NetBeans. Just that it takes sometimes 2 key combinations, Ctrl-0 then Shift-Esc. Do they want to kill my hands?)
  • menus with the same mnemonic for different entries (try ‘i’ in Window)
  • duplicate a line or selection
  • increasingly select a block of code (from word to line, block, method, class, etc…)
  • reexecute an debugged/ran program.
  • Why are the debugger shortcuts on the code window while my output, variables etc… is down?
  • add a method where my cursor is, not at the end of the file
  • correctly support implement/override in anonymous classes (probably a NB bug, this ought to work)
  • Propose to terminate a process when closing a window
  • dependency management for self made projects was far from being perfect (You have to add the same jars to both the source and test sources in order to have correct IDE support)
  • UI doesn’t distinguish well between editable and non editable elements in panels. E.g. the Label of a Source Folder can be changed, not it’s location. Both have the same visual rendering.
  • the IDE is not completely stable (still many little issues, in particular with the GUI editor, e.g. when you drag & drop elements in a panel) but to be fair, it is still a beta after all.

And there are so many many little things that do not make the experience as enjoyable as with my current editor.
And please please please. Don’t tell me: just reconfigure your shortcuts. What’s the advantage? Funny pair-programming sessions. Defaults should be well chosen. Point. Maybe the defaults are well chosen to a professional typist, which I am not. Could it be that American developers usually type much better than European ones?

A positive side is that the NetBeans colors are less agressive than IDEA’s. This will probably kill my eyes a little bit slower :)

And a suggestion: NetBeans should have a “Did you know” popup present at startup. The one present in IDEA was the best I ever found in an application and made me learn quickly all the power features present/shortcuts in IDEA.

As with eclipse, used by most of the people I know, I’ve tried it and until now it just doesn’t feel good enough for the more or less the same reasons. The huge number of plugins available may make me change my mind. Unfortunately the quality is not always there.

It looks like I will still be an IDEA user for the forthcoming quarter… And to those who will tell me “it’s not cheap” listen to this: I’ve been using Linux most of the time since 1999, and apart from the software licenses I was forced to buy directly (various Windows OEM, aka the Microsoft tax) or indirectly (vmware), in the past 7 years, Intellij IDEA is the first and only software I paid for willingly.

JavaPolis 2005 Highlights

Wednesday, January 4th, 2006

Better late than never!

JavaPolis 2005 was great. Now that the hype has faded and the dust settled, I think it’s appropriate to make a little summary.

To all those who, back from your winter holidays the stomach full of heavy things, need some early 2006 kick to start the year full speed, here’s my highlight of the best parts of the conference.

  • It’s in Antwerp! It’s in Belgium! It’s Cheap! It’s Dense! It’s Excellent! It’s Fun! It’s Huge! No: it’s Gigantic! It’s Interesting! It’s Java! 5 days, 300€. I don’t think you can get better price/value these days! My only advise to the steering committee: get rid off the too many free sodas, and give us some more real food. It’s time to kill the pizza/coke Jurassic Park nerd image. And get a better deal for the Internet. Can’t Google get us a free WiFi there?
  • The conference format: 2 University days (3h- sessions) 3 conference days (1h- sessions), a RAD race, a Movie, BOFes, quickies, etc…
  • My CruiseControl BOF… OK I experienced the worse demo effect of my life (and but for Sun, I would probably have merited the Demo Effect Award of the conference). So the projector, which I had successfully tried 2 hours before my BOF never went up. I lost a lot of time trying to fix the ubuntu X server config. In the end everybody sat behind my laptop… Notes to self: don’t let unlocked beverages on the table, don’t sign for the last BOF of the day… So thanks to all those who came, hope that you got something out of the things I managed to present. Little hi to Jeffrey Fredrick who couldn’t make it to the BOF, busy he was touring Europe talking about his continuous agitation techniques and tools.

The content I liked the most, in more or less chronological order:

Before I close this little thread, I would like to send a thank you to all those who helped make the Fun part of the conference. In no particular order: Stephan Janssen “I can’t count you all anymore”, Robin Mulkers “Surfin’ Blegia”, Francois Le Droff “It’s so good I can pay for the JavaPolis shoot myself”, Douglas “Cast Away” and Vincent Massol “Maven Heaven”. A little hi to Ross (from Mule fame) with who I couldn’t find a time to share a beer. Too bad! Special thanks to Elliotte Rusty Harold “Mr Cafe au Lait”, Dennis Sosnoski “I digest XML for breakfast”, Scott Ambler “Block those bureaucrats!” and Fabiane Bizinella Nardon “Use Technology for a purpose”.

And a special thanks to all those nice ladies who accepted to get interviewed by Robin. Too bad we couldn’t get the final sequence in…

Can’t wait for JP 2006!

updated: broken link
updated: bis repetita placent