-
Introduction to Maven?
Apache provides a dependency management and project construction project. Based on the concept
of POM (Project Object Model), every maven project has at least one pom.xml
function:
dependency management: jar package management was originally developed to put the jar package under the lib. Now only the coordinates of the jar need to be provided to Maven management. You can
project build:
Maven provides a compilation package deployment testing and a series of command
maven
local repository: the developer's own computer folder (D: \ MavenLocal)
central warehouse: a maven team maintained mvnrepository.com
Maven's official website: maven.apache.org
writing in the pom.xml dependency label
depend
com.alibaba which comes from
fastjson jar package name
1.2.31 version number
-
Installation and configuration
1. First unzip Maven 3.6.3 Unzip and install
2. Configure environment variables
JAVA_HOME
MAVEN_HOME: maven installation directory before bin folder
PATH:%MAVEN_HOME%\bin Here is a reference to MAVEN_HOME3. 随后 cmd mvn -v 4. 配置本地仓库和镜像 此处必须配置 因为在后修IDEA中 加载的Maven的配置文件就是这里 打开conf\settings.xml 53行 复制出来 就是指定本地库位置 中间的路径就是开发人员自己创建的文件夹 <localRepository>D:\MavenLocal\repository</localRepository> <!--配置镜像--> <mirrors> <!--此处就是为了换源 换成阿里云的源--> <mirror> <id>alimaven</id> <name>aliyun maven</name> <url>http://maven.aliyun.com/nexus/content/groups/public/</url> <mirrorOf>central</mirrorOf> </mirror> </mirrors>
-
Maven's helloWorld project?
Directory structure:
project name
src
main main program
java
resources
//The following is the web project
wep-app
web-INF
lib
classes
web.xml
test
java
resources
pom.xml This file writes the dependencies of Maven management -
Common maven commands?
-
mvn compile
After using this command, the target directory will be generated -
Test mvn test
when tested here packet structure
here is the unit test test test execution unit package
unit test:
to be tested using class main method is not expressed when the cell annotation @Test testing framework needs to be tested to find it where
required The import package import org.junit.*;
@Test: means to test the method under this annotation . Give it
to Maven. First go to the central library to search for junit to find the corresponding coordinate information.
Because you need to place multiple dependencies in pom.xml, you need to use it. Write the dependencies in Inside -
mvn package packaging
This command will package the Maven directory structure
1) compile the java file under main\java\ to generate the .class file and save it in the classes folder.
A jar package will be packaged according to the pom.xml written
2) web project It will be automatically packaged into a war package. The war package will be automatically decompressed and deployed by tomcat.
com.et2010.student coordinate information
student-entity jar package name
0.0.1 jar package version number
jar specifies that the packaged format is the jar package. The default format
pom indicates the existence of parent and child. engineering -
mvn install install
Test: 1 compile -> 2 test
Package: compile -> test -> package The
following commands will be executed first- mvn clean delete target (compiled generated) This method can be used
in combination with the above methods. Before using the command, you must be connected to the Internet. The
above commands must first find the pom. Execute the command according to the pom file. The generated directory structure after the command is executed is based on the written dependency in the pom The directory structure comes from.
If you want to view the jar package, follow the directory structure in the pom to find it.
-
-
Pom.xml
writes coordinate information in it. When others use our jar package, they need to provide the coordinate information. -
Use IDEA to create a web project based on Maven
6.1 First set up the Maven environment in the tool
Select File -> settting-> Build Execution Deployment,
select Build Tools -> Maven
settings:
Maven home: point to the Maven installation directory before the bin directory
user setting file: The setting.xml in the conf under the Maven installation directory is actually the file that configures the local warehouse and mirror in the morning.
Local repository: the local library location is automatically bound6.2 Create a new Project and
select Maven -> MavenType webapp next to
set the project location and name.
Configure the MavenHome setting of this project.
Select the eniable on the right side of the local library location. Automatically load6.3 Select File -> Other Setting to set the settings when creating a new project.
Refer to 6.2. -
JDBC DataSource: The interface data source
comes from javax.sql.DataSource: the factory that obtains the connection, and is also
a tool provided by JDBC to replace DriverManager-
Method: To
obtain the connection object, it is recommended to use DataSource's standard
getConnection():
getConnection(...) -
javax.sql.DataSource is a standard (interface) to obtain a connection. The jdk does not provide an implementation. What
needs to be remembered is that the database connection pool is the most important thing to implement.
-
-
Database connection pool
is a data source implementation.
Database connection pool:
1. When the server starts, it initializes some links and puts it in the connection pool. Waiting for the client request
2. The client requests a connection, first check whether there is an available link in the connection pool.
If there is, then return.
If not, determine whether the current number of connections exceeds the maximum number of available connections.
If it exceeds the number of waiting or throwing out no available connections
If the exception is not exceeded, a new connection object is constructed and returned to the client.
After the client finishes using the connection, put the connection back into the connection pool, thus realizing connection reuse
. The biggest feature of connection pool: connection reuse -
Common connection pool components?
Mybatis is the implementation of the connection pool. The implementation is the specific implementation of the javax.sql.DataSource interface.
The addLast method of the product jar package LinkedList is to insert data at the end of the linked list.
removeFirst(): deletes from the head and returns the first element of this list
Introduction to Maven + Introduction to DataSource
Guess you like
Origin blog.csdn.net/G7581/article/details/114978282
Recommended
Ranking