Pages

Thursday, 24 July 2014

How to compare maven and ant ?


Apache Ant
  • Ant doesn’t have formal conventions like a common project directory structure or default behav- ior. You have to tell Ant exactly where to find the source and where to put the output. Informal conventions have emerged over time, but they haven’t been codified into the product.
  • Ant is procedural. You have to tell Ant exactly what to do and when to do it. You have to tell it to compile, then copy, then compress.
  • Ant doesn’t have a lifecycle. You have to define goals and goal dependencies. You have to attach a sequence of tasks to each goal manually.

Apache Maven
  • Mavenhasconventions.Itknowswhereyoursourcecodeisbecauseyoufollowedtheconvention. Maven’s Compiler plugin put the bytecode in target/classes, and it produces a JAR file in target.
  • Maven is declarative. All you had to do was create a pom.xml file and put your source in the default directory. Maven took care of the rest.
  • Maven has a lifecycle which was invoked when you executed mvn install. This command told Maven to execute a series of sequential lifecycle phases until it reached the install lifecycle phase. As a side-effect of this journey through the lifecycle, Maven executed a number of default plugin goals which did things like compile and create a JAR. 

  1. Maven has built-in intelligence about common project tasks in the form of Maven plugins. If you wanted
    to write and execute unit tests, all you would need to do is write the tests, place them in
    ${basedir}/src/test/java, addatest-scopeddependencyoneitherTestNGorJUnit,andrunmvn test.Ifyouwantedtodeploya web application and not a JAR, all you would need to do is change your project type to war and put your docroot in ${basedir}/src/main/webapp. Sure, you can do all of this with Ant, but you will be writing
    the instructions from scratch. In Ant, you would first have to figure out where the JUnit JAR file should
    be. Then you would have to create a classpath that includes the JUnit JAR file. Then you would tell
    Ant where it should look for test source code, write a goal that compiles the test source to bytecode, and execute the unit tests with JUnit. 

Without supporting technologies like antlibs and Ivy (even with these supporting technologies), Ant has the feeling of a custom procedural build. An efficient set of Maven POMs in a project which adheres to Maven’s assumed conventions has surprisingly little XML compared to the Ant alternative. Another benefit of Maven is the reliance on widely-shared Maven plugins. Everyone uses the Maven Surefire plugin for unit testing, and if someone adds support for a new unit testing framework, you can gain new capabilities in your own build by just incrementing the version of a particular Maven plugin in your project’s POM.
The decision to use Maven or Ant isn’t a binary one, and Ant still has a place in a complex build. If your current build contains some highly customized process, or if you’ve written some Ant scripts to complete a specific process in a specific way that cannot be adapted to the Maven standards, you can still use these scripts with Maven. Ant is made available as a core Maven plugin. Custom Maven plugins can be implemented in Ant, and Maven projects can be configured to execute Ant scripts within the Maven project lifecycle. 

How do we add the jars to the class path ussing maven ?

http://maven.apache.org/plugins/maven-dependency-plugin/
http://stackoverflow.com/questions/4687609/maven-not-setting-classpath-for-dependencies-properly
http://maven.apache.org/plugins/maven-dependency-plugin/



<build>
        <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-dependency-plugin</artifactId>
            <executions>
                <execution>
                    <id>copy-dependencies</id>
                    <phase>prepare-package</phase>
                    <goals>
                        <goal>copy-dependencies</goal>
                    </goals>
                    <configuration>
                        <outputDirectory>/User/sayghosh/code/CCMatching/lib/</outputDirectory>
                        <overWriteReleases>false</overWriteReleases>
                        <overWriteSnapshots>false</overWriteSnapshots>
                        <overWriteIfNewer>true</overWriteIfNewer>
                    </configuration>
                </execution>
            </executions>
        </plugin>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-jar-plugin</artifactId>
            <configuration>
                <archive>
                    <manifest>
                        <addClasspath>true</addClasspath>
                        <classpathPrefix></classpathPrefix>
                        <mainClass><com.sd.sd.sd></mainClass>
                    </manifest>
                </archive>
            </configuration>
        </plugin>
        </plugins>

        </build>

What is M2_REPO and what does mvn:eclipse eclipse do ?

First step is to be able to create a pom.xml, then you have to be able to get mvn:compile and mvn:package running. After that comes your eclipse repo the dev environment, in this page you get that running. Next how do you add jars to the classpath to get the jar running. 

  1. M2_REPO is a variable that defines where maven 2 repository is on your disk
  2. This means: add definition of M2_REPO to XML file that defines the eclipse workspace
  3. You can do the same manually if you want. That is what I personally did. Just go to Window/Preferences and then choose Java/Build Path/Classpath Variables. Once you did it you can enjoy maven integration with eclipse. Every time you add new dependency to your pom.xml, run
    mvn eclipse:eclipse
and refresh you workspace you get all new libraries into classpath of your project.
If you have a simple java project which is made up of only one module, using eclipse is very simple. To generate the eclipse project files from your POM you execute the following command:
mvn eclipse:eclipse
If you have created or checked out the project with eclipse, you only have to refresh the project in your workspace. Otherwise you have to import the project into your eclipse workspace (From the menu bar, select File >Import >Existing Projects into Workspace). In the latter case the project (directory) should not be located in your workspace, because eclipse might come into trouble, especially if you want to use eclipse as the scm client.

http://stackoverflow.com/questions/4517507/setting-up-m2-repo-classpath
http://maven.apache.org/guides/mini/guide-ide-eclipse.html

No projects found to import error in eclipse

http://stackoverflow.com/questions/2638016/why-no-projects-found-to-import

Wednesday, 23 July 2014

How would you change your git repository when your location on the server has changed ?


Introduction :
  1. What is remote ? Remote repositories are versions of your project that are hosted on the Internet or network somewhere
  2. What is origin ? If you’ve cloned your repository, you should at least see origin — that is the default name Git gives to the server you cloned from
  3. What does git remote do ? To see which remote servers you have configured, you can run the git remote command. It lists the shortnames of each remote handle you’ve specified.
How to :
  1. git remote rm origin //this will remove the previous origin
  2. git remote add origin <new url location> //this will add the new location on github as the remote
References : 

How to read a WSDL ?

Tuesday, 22 July 2014