2.1.14

Ajax + Maven + S3 = A lightweight maven repository browser that never goes down.

Heavyweight interfaces sometimes occlude the simple, platform neutral, static directory structure that made maven famous to begin with.  If your server goes down, your jars are unavailable.  S3 solves this problem by providing serverless, http accessible storage.  Adding Javascript + ajax into the mix means you can have dynamic content hosted through s3 with zero administration. 

Problem: You have a public maven repository somewhere (i.e. in the cloud) - but you want to be able to browse it in a user freindly way.

Solution 1: Use a full blown repo manager archiva/artifactory/nexus to host it.  
There are use cases for this... i.e., you are a huge company with 100s of developers and you need a scalable interface to host lots of jar artifacts with many versions in a secure manner, and you also need to provide different users different permissions to maintain different repositories, etc...  But for a simple maven repo, some might say that a heavy weight repo manager creates a new problem:  You are maintaining a server just to host a couple of jar files.  The snazzy UI to your jar files is nice - but is it really necessary?  Do you really need "roles" and hosted md5 comparisons just to share a few binaries?  Probably not.
Now, Admittedly, for big organizations with security issues, etc, a private archiva server is a nice solution.... but probably isnt required for smaller projects which need a simple landing page for their maven artifacts for end users to consume.

Solution 2:  Put the maven repo in S3 and use JQueries snazzy XML parser to host a dynamic, HTML5+jquery/javascript front-end.  Here's how: 

1) Either use an s3 publisher in your "mvn deploy" invocations, or else, just scp your maven repository into s3://yourbucket/maven/

2) Now, you can look into http://<your_bucket>.s3.amazonaws.com/maven/repositories/internal/<your_repo_path>/maven-metadata.xml", and you will see that there is a nice layout of all versions of your Jar. For example: http://repo.maven.apache.org/maven2/org/apache/pig/pigsmoke/maven-metadata.xml contains several version tags. 

3) Save the code below to s3://<your_bucket>/maven/index.html
<html>
<head>
<title>GlusterFS-Hadoop Releases</title>

<script type="text/javascript"
 src="http://code.jquery.com/jquery-1.10.2.min.js"></script>

</head>
<body>
 <p> Releases </p>
 <div id="releases">
 </div> 
 <script type="text/javascript">
  
  $(document).ready(function(){
   $("#msgid").html("--");
  });
  
  function UrlExists(url, cb){
      jQuery.ajax({
          url:      url,
          dataType: 'text',
          type:     'GET',
          complete:  function(xhr){
              if(typeof cb === 'function')
                 cb.apply(this, [xhr.status]);
          }
      });
  }
 
  $(document).ready(function(){
    $("#releases").append("<ul></ul>");
    $.ajax({
      type: "GET",
      url: " http://rhbd.s3.amazonaws.com/<PATH_TO_YOUR_REPO>/maven-metadata.xml",
      dataType: "xml",
      success: function(xml){
      $(xml).find('metadata').each(function(){
        var versioning = $(this).find('versioning').text();
        var versions = $(this).find('versions').text();
        
        $.each(versions.split("\n"),
          function(index,value ) {
           var jarlink = "http://<YOUR_BUCKET_NAME>.s3.amazonaws.com/maven/<PATH_TO_YOUR_REPO>/VERSION/<YOUR_ARTIFACT_NAME>-VERSION.jar"
           var regex = new RegExp('VERSION', 'g');
           var jarversion = jarlink.replace(regex,value.trim());
           //$("<li></li>").html(jarversion).appendTo("#releases ul");
           $("<li></li>").html("<a href=\""+jarversion+"\">"+value+"</a>").appendTo("#releases ul");
        }
        );
      });
    },
    error: function() {
      alert("An error occurred while processing XML file ");
    }
    });
  });

 </script>
 
</body>
</html>
4) Now, browsing to http://<YOUR_BUCKET>.s3.amazonaws.com/index.html , You will see a nice list of links to your maven jars.  This is super easy to modify and maintain, and if using a object store like s3, you can gaurantee that your users will always have access to your artifacts.  Moral of the story: You can easily modify your landing page to your maven jars without using a heavy weight repo manager.


Checkout our glustersf-hadoop landing page http://rhbd.s3.amazonaws.com/maven/index.html, as an example of how this works... as long as you continue to use "mvn deploy:deploy" to update your repo, the HTML page will always serve the latest contents, because the maven-metadata.xml page will be automatically updated in the publishing process.

1 comment:

  1. 聽說過“天生陽痿”嗎?

    網友:醫生你好,我有陽痿早泄威而鋼哪裡買 威而鋼 威而鋼 壯陽藥 威而鋼 犀利士哪裡買 壯陽藥品 壯陽藥 威而鋼 威而鋼哪裡買 威而鋼專賣店 威而鋼藥局 情色貼圖快兩年了,真的可以治威而鋼 犀利士 威而鋼哪裡買 犀利士 犀利士好嗎?
      醫生:有無包皮過長的情況?包皮過長易導致龜頭神經敏感,從而導致早泄。
      網友:沒有包皮過長。
      醫生:有尿頻、尿急、尿壯陽藥 壯陽藥 威而鋼 犀利士 犀利士 犀利士專賣 犀利士 犀利士5mg價格 壯陽藥品 犀利士專賣 威而鋼 壯陽藥不盡、尿等待、尿分叉的感覺嗎?
      網友:都沒有,就以前有手淫和性交過頻后來就開始了。
      醫生:以前性功能正常嗎?
      網友:正常,可現在一挺了就軟了,性交也一分鐘左右就泄了。
      醫生:有到醫院檢查過嗎?
      網友:沒有檢查過,但是有去藥店買過藥,吃了一段時間都沒有什么效果就沒有繼續吃了。
      醫生:首先治療疾病,建議還是先做檢查,確診病因后再對癥治療為佳。導致陽痿早泄的病因是多種的,如精神因素;任何可能導致犀利士 犀利士 犀利士 犀利士 犀利士 威而鋼 威而鋼 威而鋼 威而鋼哪裡買 威而鋼 威而鋼 威而鋼 威而鋼 犀利士 壯陽藥品去哪買 犀利士 犀利士 犀利士 犀利士 犀利士陰莖海綿體動脈血流減少的疾病;手術、外傷引起陰莖有關血管和神經損傷,導致勃起功能障礙;內分泌疾患、慢性病和長期服用某些藥物;前列腺炎、前列腺增生反復發作久治不愈等。
      網友:那難治療嗎?
      醫生:檢查確診后,只要你積極配合醫生對癥治療,是可以臨床治愈的。如果不是先天性的,不管是哪些疾病,只要查清楚,配合醫生都可以治療的。

    ReplyDelete