Adding project local libraries to maven

Before moving to maven our libraries were kept in the project lib directory and shared through version control. Now we have moved to using maven I can find all my dependencies from the maven repositories.

However I have found out that it can be sometimes handy to still use the old approach for those special dependencies, especially if you don't have a repository setup in your local network. So we have a dependency for old-stuff.jar which is in the lib directory in our new-fantastic maven project.

 Directory of new-fantastic

[.]       [..]      [lib]     pom.xml   [src]               

 Directory of new-fantastic\lib

[.]             [..]            old-stuff.jar
  1. First we add the lib directory as a repository to the pom.xml
  2.   <repositories>
            <repository>
                <id>local-project-libraries</id>
                <name>Local project libraries</name>
                <url>file://${project.basedir}/lib</url>
                <layout>default</layout>
            </repository>
       </repositories>
    
  3. Then we add a depencency to the old-stuff.jar to the pom.xml
  4.   <dependencies>
        <dependency>
          <groupId>com.blogspot.pragmastic</groupId>
          <artifactId>old-stuff</artifactId>
          <version>0.9</version>
        </dependency>
      </dependencies>
  5. Now if we run maven it will helpfully tell us that the dependency cannot be found and that we should either install it or deploy it to a repository
  6. Missing:
    ----------
    1) com.blogspot.pragmastic:old-stuff:jar:0.9
    
      Try downloading the file manually from the project website.
    
      Then, install it using the command:
          mvn install:install-file -DgroupId=com.blogspot.pragmastic
    -DartifactId=old-stuff -Dversion=0.9 -Dpackaging=jar -Dfile=/path/to/file
    
      Alternatively, if you host your own repository you can deploy the file there:
          mvn deploy:deploy-file -DgroupId=com.blogspot.pragmastic
    -DartifactId=old-stuff -Dversion=0.9 -Dpackaging=jar -Dfile=/path/to/file
    -Durl=[url] -DrepositoryId=[id]
  7. Now we use the command from the message and deploy the file to our Local project libraries repository
  8. mvn deploy:deploy-file -DgroupId=com.blogspot.pragmastic -DartifactId=old-stuff -Dversion=0.9 
    -Dpackaging=jar -Dfile=lib/old-stuff.jar -Durl=file://${project.basedir}/lib 
    -DrepositoryId=local-project-libraries
  9. After this we can run maven and it will load the dependency from our local repository

Simple way for making POST request with silverlight

I came up with this way to make a post request from silverlight because I find the WebClient too cumbersome and the post requests to relative URLs didn't work. My solution is to use javascript for making the posts with Ajax and then call the javascript method from the silverlight. First we have the javascript on the page for making the post with jQuery:
<script type="text/javascript" src="http://www.google.com/jsapi"></script>
<script type="text/javascript">
google.load("jquery", "1.4");
function makeRequest(url, args) {
    $.ajax({type: 'POST', url: url, data: args});
}
</script>
Thanks to jQuery the code is really short. Then we have the helper class for making the post request from silverlight, here the trick is the ToJSDictionary-method converting the arguments dictionary to a javascript object.
public class WebHelper {  
    public static void MakeRequest(string url, 
            IDictionary<string, object> args) {
        try
        {
            HtmlPage.Window.Invoke("makeRequest",url, 
                    ToJSDictionary(args));
        }
        catch (Exception e)
        {
            // Ignored  
        }
    }

    public static object ToJSDictionary(IDictionary<string, object> args)
    {
        var jsdict = HtmlPage.Window.CreateInstance("Object");
        foreach (string key in args.Keys)
        {
            jsdict.SetProperty(key, args[key].ToString());
        }
        return jsdict;
    }
}
Now we can make post requests from our silverlight code like this:
    var args = new Dictionary<string,object>();
    args["p1"] = "test";
    args["p2"] = 1;
    WebHelper.MakeRequest("http://my.site.com/test", args); 
Of course since we are not handling the response this approach is only suitable when that is not required.