Thursday, 6 March 2014

Import a Maven project in Eclipse

In order to import a Maven project into Eclipse, go to the project directory and type the following in Terminal.

mvn eclipse:eclipse

This command creates the following configuration files :

.classpath - Detailed information can be read here about it.

.project - Detailed information can be read here.

Describe a plugin in Maven

If you're using Maven for building projects, occasionally you might come across situation where you wonder what version of a certain plugin you're using. You might also wonder what goals are available.

In order to identify the plugin's version and goals, type the following in terminal.

Eg : 

mvn -Dplugin=install help:describe

This will describe the details of the "install" plugin. Note that this will also describe the plugin's available goals.

Wednesday, 5 March 2014

Artifactory on Mac OS X

Recently, while trying to install Artifactory on my Mac OS X machine, I encountered a weird error. Finding a solution was a bit tricky and took some time to figure it out.

Artifactory is basically an open source repository manager. I downloaded the latest current version v3.1.1.1. In this tutorial, we'll cover the easy method using hot deployment on servlet container.

Note that Artifactory comes pre-bundled with it's war file which we can deploy onto Tomcat. Although it does come pre-loaded with it's own container, I wanted to deploy the war using Tomcat 7. Since I already have Tomcat 7 installed on my machine.

When I logged on to Tomcat manager and tried to deploy the Artifactory war, I got the generic looking error : FAIL - application at context path could not be started.

So I fired up the terminal and looked into the Tomcat Catalina logs and here's what I came across :




The error "Setting property 'disableURLRewriting' to 'true' did not find a matching property." was looking really strange. So I googled a bit and realised that Artifactory needs JDK 1.7 to run. Refer this forum for some insights.

Now since Mac machines come pre-loaded with Apple supplied Java 6, I was in a kind of a fix. I wondered what to do. Should I download and install Java 7 & uninstall Java 6?

However I was skeptical of uninstalling Java 6. Also, I was not quite sure about what overall impact it would have by uninstalling Java 6 altogether. Since I mentioned previously that Google Chrome does not work with 64-bit Java 7. I spent some time doing impact analysis but didn't quite reach a conclusive decision. A little bit of coffee did the trick :)

Now, here's the workaround. Download the JDK 1.7 for Mac from this link. Now luckily I had the Eclipse IDE with Tomcat plugin ready. If you don't have this setup yet, I highly recommend working with the Eclipse IDE. Lots of customizations are possible.

Open Tomcat Preferences and and expand Java > Installed JRE from the left menu. Click Add. Now browse to /Library/Java/JavaVirtualMachines/jdk1.7.0_51.jdk/Contents/Home. Describe it with some name like Jdk 1.7. Apply settings and don't exit the preferences as yet.

Make sure you only mention the path till Home. If you mention path further like .../Contents/Home/bin/java, you will see an error like "Target is not a JDK root. Java executable not found."

Check the screenshot for reference.




Now, scroll down the preferences' left pane and expand Tomcat > JVM Settings. From the drop down, select Jdk 1.7 that just defined above. So henceforth, Tomcat container will only be invoked using Jdk 1.7. If for any reasons, you have to invoke using Java 6, you can always choose Apple supplied Java 6 from this list. Check the screenshot for reference.




Now simply hit the Start Tomcat button. Bingo. Wait and watch the console till you see that Artifactory has started. Something like this : 

###########################################################
### Artifactory successfully started (29.031 seconds)   ###
###########################################################

Now, all you have to do is open browser to localhost:<listener-port-no>/artifactory. By default, tomcat's listener port is 8080. You can modify it if you want to.




In my next tutorial, I'll post about working with Artifactory & Maven repositories. Stay tuned folks.

Tuesday, 4 March 2014

Manual Installation of 3rd party jars in Maven

Occasionally, while using Apache Maven, we may come across scenarios when we would have to manually install 3rd party dependency jars. This might occur when a certain dependency jar does not exist on your local repository or Maven Central. Let's discuss how to manually install such jars.

The first obvious step would be to download the 3rd party jar. For instance Kaptcha or Gin. Now our next job would be to install this jar into our local repository, so that Maven detects it. Open terminal and browse to your local Maven repository.

For installing the jar, we provide a goal to the maven-install-plugin. Use the goal install:install-file and pass parameters as shown in the below example :

mvn install:install-file -Dfile=path-to-3rd-party.jar -DgroupId=com.example-plugin.code -DartifactId=example-plugin-name -Dversion=version-of-the-jar -Dpackaging=jar

The Output would start with something like this. You'll see the Build Success message once the plugin is installed successfully.



The entire list of paramaters that can be passed to the goal install:install-file can be found here.

Note that once such 3rd party jars are installed, you may have to use the sha1 or md5 utility to create MD5 checksums of the jar and pom that got created within the repository. Refer my previous post on using the MD5 utility.

Also, correct me if am wrong, in older Maven 1 versions, once the plugin is installed, you had to manually edit the generated pom to include details like groupId, artifactId and version. However in Maven 2+ versions, the pom gets auto-populated with these details.

Using MD5 checksum utility on Mac OS X

If you might be aware, every Linux distribution comes with the MD5 checksum utility - md5sum. Similarly UNIX flavors like Mac OS X, come pre-bundled with utility called md5

The OS X md5 utility can be found at /sbin/md5

I'll quickly show some steps on how to use it :

  • Open Terminal
  • Create a blank empty file anywhere on the system (I mean just anywhere) using touch


Eg : touch test.xml
  • Now type the following to generate the md5 checksum of this file 
Eg : md5 test.xml > test.xml.md5

That's it. Now open the test.xml.md5 using TextEdit or Text Wrangler and you'll see the file's equivalent md5 checksum. 

If you want to change the format of the output similar to Linux's md5sum use the -r switch 

Eg : md5 -r test.xml > test.xml.md5

Note that MD5 checksums are used to verify the integrity of a file. Even a single new character added to the file will change the equivalent md5 output. Check for yourself. Modify the test.xml by adding some content to it. Now run the md5 utility again as shown above. The md5 equivalent of the file will now be different. The checksums are important to verify that the files / resources are intact throughout and ensure that they are not corrupt or tampered.

You can use this method to verify the integrity of zip or tar files that you download from the internet.

A free utility Checksum Validator is also available. At the heart of it's gui, it uses this md5 command.

This information can come particularly handy while using Maven as well. Suppose for some odd reason, you have to manually create md5 checksums of the dependency jar's - then this method tells you how to do it.

Sunday, 2 March 2014

Average Internet Speeds - World Chart

I just stumbled across this beautiful site which lists the average internet speeds across all the countries of the world. So, which place do you think has the highest average internet speed. Take a wild guess folks.

You'd be surprised - it's Hong Kong. The noted average speed for month Feb '14 is 72.58 Mbps. That's quite a high figure, considering it's an AVERAGE. Just shows how the high speed broadband has uniformly penetrated across the region. The link is Ookla Net Index Explorer map. Good thing about this link is you can pretty much check the varying speeds month-wise.




Happy number crunching guys.

How to Wrap & Tie Macbook Pro Charger Cord

I've seen a lot of naive & experienced Macbook Pro & Air users struggle with tying and wrapping the Magsafe power adapter cord. This is a quick tutorial on how to wrap it the right way in order to carry it in the backpack with ease.

Apple has really put a lot of thought into the charger's wire management. The charger happens to be the most portable one among all laptop chargers. Good job, Apple. So, here are the steps.

Step 1 : Raise the 2 side hooks of the square box of the battery charger.

Step 2 : First take the thick wire side and roll it vertically around the square box. Don't stretch it too much on the first roll.

Step 3 : Now hold the rolled thick wire with your left hand so that it doesn't unwind. With your right hand, take the thin wire side (the side which you connect to the laptop). Roll this thin wire horizontally around the 2 raised hooks of the box. Make sure you don't stretch the thin wire. Just tie it around naturally, without stressing it out. The thin wire side is the most susceptible to wear and tear. So, make sure you don't put pressure on the thin side, so that it lasts longer.

The thin wire which is horizontally wound helps keep the vertically wound thick wire in check.

Take a look at the picture for reference.




Oh and just in case you need a new Magsafe power adapter, check Apple store which sells it USD 79 & Amazon which sells it for USD 73.99. You have a good day, guys. Ciao for now. 
Related Posts Plugin for WordPress, Blogger...
eXTReMe Tracker