Maven Starter Series (v)--Getting Started with Maven project development in STS application

Source: Internet
Author: User

I write this introductory series just want to give those who "maven is what" to learn younger brother and learn to get a quick start help, in order to commemorate once also took a lot of detours of oneself, even if oneself also has a long way in front. Therefore, each road immortal will not say what too basic such words, have that time accompany father and mother, coax sister, play two innings DotA also than on-line spray person strong.

With a few previous blogs, MAVEN is helping us in real-world development.

The biggest help is that when we need a third-party component and framework, I don't need to find all kinds of jars in various websites and forums. Sometimes there may be dependencies between components, which we often miss. (This article originates from: http://my.oschina.net/u/1156339/blog/399311)

Let me give you an example. For example, I now want to write a reflection program that modifies the property values of the person class. I want to use beantuils to do all this.

Usually, I will open the browser, to Apache's official website to find beanutils download link. But this has become the past.

What I need to do now is to manage the resources needed in the project through the MAVEN components of the STS. I just need to beantils the GVA coordinates, OK, maybe I need to go to the MAVEN repo central repository to search for this GVA, and then copy the dependency it provides to the project Pom.xml

<project xmlns= "http://maven.apache.org/POM/4.0.0"  xmlns:xsi= "http://www.w3.org/2001/ Xmlschema-instance "  xsi:schemalocation=" http://maven.apache.org/POM/4.0.0 http:// Maven.apache.org/xsd/maven-4.0.0.xsd ">  <modelVersion>4.0.0</modelVersion>   <groupId>com.happyBKs.Maven</groupId>  <artifactId>beango</artifactId>   <version>0.0.1-SNAPSHOT</version>  <packaging>jar</packaging>   <name>beango</name>  <url>http://maven.apache.org</url>   <properties>    <project.build.sourceencoding>utf-8</ project.build.sourceencoding>  </properties>  <dependencies>     <dependency>      <groupId>junit</groupId>       <artifactid>junit</artifactid>      <version>4.10</version>       <scope>test</scope>    </dependency>    < dependency><groupid>commons-beanutils</groupid><artifactid>commons-beanutils</ artifactid><version>1.9.2</version></dependency>  </dependencies></ Project>

After that, everything will be downloaded well, and we don't need to worry about it. Even the common-logging that Beanutils needed was downloaded together. (usually I often forget to import this common-logging, now no need to worry about )

Then I set up a person class

Package Com.happybks.maven.beango;public class Person {public String getName () {return name;} public void SetName (String name) {this.name = name;} public int getage () {return age;} public void Setage (int.) {this.age = age;} String name;int age;}

Then I run in the app class Main, without junit, we understand nature.

package com.happybks.maven.beango;import java.lang.reflect.constructor;import  java.lang.reflect.invocationtargetexception;import org.apache.commons.beanutils.beanutils;/** *  Hello world! * */public class App {    public  Static void main ( String[] args )     {    try  {extracted ();}  catch  (classnotfoundexception e)  {// TODO Auto-generated catch  Blocke.printstacktrace ();}  catch  (nosuchmethodexception e)  {// TODO Auto-generated catch  Blocke.printstacktrace ();}  catch  (instantiationexception e)  {// TODO Auto-generated catch  Blocke.printstacktrace ();}  catch  (illegalaccessexception e)  {// TODO Auto-generated catch  Blocke.printstacktrace ();}  catch  (INVOCATIONTARGETEXCEPTION&NBsp;e)  {// todo auto-generated catch blocke.printstacktrace ();}     }private static void extracted ()  throws  classnotfoundexception,nosuchmethodexception, instantiationexception,illegalaccessexception,  Invocationtargetexception {class c1=class.forname ("Com.happyBKs.Maven.beango.Person");         constructor con= c1.getconstructor ();         person sw= (person)  con.newinstance ();         beanutils.setproperty (sw,  "name",  "Sword");         beanutils.setproperty (sw,  "age",  1);         System.out.println (Sw.getage ());         system.out.println (  " hello world! "  );}}

The results of the operation are as follows:

1

Hello world!

This is a reflection of Maven's core: dependency management, warehouses, and conventions better than configuration.

All right, the basics. But I would like to pass these articles, the little white at least know what Maven is probably going on. So I'll see you in the introductory chapter! Happybks and everyone together refueling!

Maven Starter Series (v)--Getting Started with Maven project development in STS application

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.