Test Development Series - a project build

learning target

  • Ant
  • Maven
  • Gradle

Project Management Tools

  • Year 2000 Apache's Ant
  • In 2004 Maven
  • In 2012 Gradle abandoned xml configuration, support language java, groovy, scala

Ant

  • java project build.xml, right-click build.xml-> Run As-> Ant Build
  • In the runtime editor of the project packaging and other processes you need to rely on ant build tool
  • ant manually between project labeled jar-build path
  • If in the implementation of java -jar helloant.jar, reported jar no master list property, you need to increase the main function entry in the jar / META-INF / MANIFEST.MF in: Main-class: com.HelloAnt

The difference between Maven and the ant

I can not say the ant is a project management tool, but a software compilation, testing, deployment and other steps to be linked to an automated tool.

Maven addition to providing automatic compilation, deployment, testing and other functions, but also provides project information management and dependency management capabilities.

Maven- Introduction

It is an Apache open source projects, mainly in the service project built on the Java platform, rely on information management and project management.

Maven- installation

step 1: decompressed after downloading apache-maven-3.5.2 File
Download: HTTP: //maven.apache.org/download.cgi
STEP 2: setting environment variables, adding MAVEN_HOME / bin system into the path to
step 3 : execute mvn -version / v to see if the installation was successful

Configuring maven eclipse

Installations
the User Settings
Warehouse:

  • Central warehouse: http: //repo2.maven.org/maven2/
  • PW Warehouse: nexus
  • Local Warehouse: The default is .m2 directory under the root directory of the
    Maven repository configuration of Ali cloud images
  • https://www.cnblogs.com/Jimc/p/10152621.html

Maven- create a maven project

step 1: File->new->Project
step 2: 选择maven project

Maven-archeType project skeleton

maven: offers a variety of project types framework for developers to choose
maven-archetype-quickstart: default project framework type
maven-archetype-webapp: generate a skeleton project website

maven directory structure

| -src
| | -main
| | | -java
| | | -resources - items stored in resource files, such as spring, hibernate configuration file
| | -test
| | -java - store all test .java files, such as JUnit test class
| | resources - test resource file
| -target - the object file output location such as .class, .jar, .war file
| -pom.xml --maven project core profile

Maven-pom file

Explanation: Project Object Model, through xml representation maven project using pom.xml to achieve.
It describes the project: including configuration files; developers need to follow the rules, defect management systems, organizational and licenses, url projects dependent projects, as well as all the relevant factors other items.

Maven-pom file node analysis

modelVersion: Description This POM file which version of the item descriptor compliance
groupId: organization ID, defines the project belongs to which organization
artifactId: Item ID, organization which item
version: the version number, the organization of the project which version

<!--本地编译JDK版本-->
<maven.compiler.source>1.8</maven.compiler.source>
<!--项目部署JDK版本-->
<maven.compiler.target>1.8</maven.compiler.target>

run as

  • maven build
    • Package Goals: package, click Run
  • maven install
  • maven clean

Maven- first package maven project

step 1: Specifies the main class, using plugin: maven-jar-plugin

<plugin>
	<!--<groupId>org.apache.maven.plugins</groupId>-->
	<artifactId>maven-jar-plugin</artifactId>
	<version>3.1.1</version>
	<configuration>
		<archive>
		<manifest>
			<mainClass>com.xxx.aa.App</mainClass>
		</manifest>
		</archive>
	</configuration>
</plugin>

Maven- common plug-ins

  • maven-clean-plugin

  • maven-resources-plugin

  • maven-compiler-plugin

  • maven-deploy-plugin

  • maven-install-plugin

     <plugin>
     	<groupId>org.apache.tomcat.maven</groupId>
     		<artifactId>tomcat7-maven-plugin</artifactId>
     		<version>2.2</version>
     		<configuration>
     			<port>9777</port>
     			<path>/mvc</path>
     			<uriEncoding>UTF-8</uriEncoding>
     		</configuration>
     </plugin>
    

Maven- dependent range

compile: compile default range, meaning compile, test, run, packed packages will be used in
test: Only pack test was used
provided: compile, test will use, when the package will not play, provided by the container
runtime: compiled when not used, only when commissioning and operation will use
system: Specifies the local file path dependence, not recommended

Maven repository

warehouse:

  • Central warehouse: http: //repo2.maven.org/maven2/
  • PW Warehouse: nexus
  • Local Warehouse: The default directory is the root directory .m2

New Eclipse Maven Web Project

The first step: File-> New-> Maven Project
Here Insert Picture Description
Step Two: Use default Workspace location in the specified Location, click Next
Here Insert Picture Description
Step 3: Select maven-archetype-webapp, click Next
Here Insert Picture Description
Step Four: Enter Group Id and after Artifact Id, click Finish
Here Insert Picture Description
step five: Maven Web project is created, but an error message.
Here Insert Picture Description
Suddenly project The superclass "javax.servlet.http.HttpServlet" was not found on the Java Build Path error appears
Here Insert Picture Description
Solution:

  1. Right-click the project -> Build Path-> Configure Build Path
  2. Select Libraries-> Add Library ...
  3. In the pop-up window, select Server Runtime, click Next
  4. Choose its own configured tomcat service, click Finish
  5. Finally, Apply and Ok

Eclipse run Maven Web project

The first step: Increase tomcat configuration in 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/maven-v4_0_0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>com.one</groupId>
  <artifactId>testMavenWeb</artifactId>
  <packaging>war</packaging>
  <version>0.0.1-SNAPSHOT</version>
  <name>testMavenWeb Maven Webapp</name>
  <url>http://maven.apache.org</url>
  <dependencies>
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>3.8.1</version>
      <scope>test</scope>
    </dependency>
  </dependencies>
  <build>
    <finalName>testMavenWeb</finalName>
    	<plugins>
       		<plugin>
   			<groupId>org.apache.tomcat.maven</groupId>
   				<artifactId>tomcat7-maven-plugin</artifactId>
   				<version>2.2</version>
   				<configuration>
   					<port>9777</port>
   					<path>/mvc</path>
   					<uriEncoding>UTF-8</uriEncoding>
   				</configuration>
   			</plugin>
   		</plugins>
  </build>
</project>

Step Two: Right-click the project -> Run As-> Maven build ...
Here Insert Picture Description
Third step:
just fill out the deployment Goals: tomcat7:deployClick Run
to deploy the server is started Goals & Fill: tomcat7:runClick on Run
Here Insert Picture Description

gradle installation and integration

  • Download and unzip: https: //gradle.org/releases/
    click binary-only downloads the zip package
    Here Insert Picture Description
    , please look for the little elephant
    Here Insert Picture Description
  • Configure the environment variables:% GRADLE_HOME% \ bin

Eclipse installation gradle

  • Open Eclipse
  • The menu bar into the Eclipse-> Help-> Eclipse Marketplace
  • Find search box to enter gradle
  • Please look for the little elephant, click Install to install
    Here Insert Picture Description

groovy language Introduction

It is based on the Java Virtual Machine dynamic languages

def name = "Guillaume"
def numArr = [1,2,3,4,5]
numArr << 13
println "第二个到第四个:${numArr[1..3]}"
//使用 each 方法遍历集合 参数默认是it
def map=[red:'#FF0000', green: '#00FF00', blue:'#0000FF']

//访问 Map 中的元素有三种方式:
map.key
map[key]
map.get(key)
Published 14 original articles · won praise 1 · views 850

Guess you like

Origin blog.csdn.net/anniewhite/article/details/104223437