4. Servlet注解开发
package com.shangguan.servlet;
import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebInitParam;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
/**
* @ClassName: FirstServlet
* @Description:
* @Author: 一尘
* @Date: 2020 年 09 月 01 9:28
* @Version 1.0
*/
//@WebServlet(name = "firstServlet",urlPatterns = "/first")
@WebServlet(urlPatterns = "/first",
loadOnStartup = 1 ,`
initParams = {
@WebInitParam(name="encoding",value = "UTF-8")
}
)
//initParam
public class FirstServlet extends HttpServlet {
ServletConfig servletConfig = null;
@Override
public void init(ServletConfig config) throws ServletException {
System.out.println("-------------init--------------");
servletConfig = config;
}
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException {
System.out.println("----------处理请求----------------");
// System.out.println(this.getServletContext().getInitParameter("encoding"));
System.out.println(servletConfig.getInitParameter("encoding"));
}
@Override
protected void doPost(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException {
doGet(req,resp);
}
}
5. MAVEN
5.1 Maven使用环境
- jar包版本依赖问题
- 项目怎么打包(jar,war)
- 公司中项目之间怎么依赖
- 项目怎么整合
5.2 下载
https://mirrors.bfsu.edu.cn/apache/maven/maven-3/3.5.4/binaries/
5.3 环境变量配置
Path中添加
5.4 查看版本
5.5 maven构建项目
MavenDeml
| src
|main
| java
| resources
| test
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.shangguan.maven</groupId>
<artifactId>MavenDemo</artifactId>
<version>1.0-SNAPSHOT</version>
<properties>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>
E:\MavenDemo
λ mvn compile
[INFO] Scanning for projects...
[INFO]
[INFO] -------------------< com.shangguan.maven:MavenDemo >--------------------
[INFO] Building MavenDemo 1.0-SNAPSHOT
[INFO] --------------------------------[ jar ]---------------------------------
[INFO]
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ MavenDemo ---
[WARNING] Using platform encoding (GBK actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] Copying 0 resource
[INFO]
[INFO] --- maven-compiler-plugin:3.1:compile (default-compile) @ MavenDemo ---
[INFO] Changes detected - recompiling the module!
[WARNING] File encoding has not been set, using platform encoding GBK, i.e. build is platform dependent!
[INFO] Compiling 1 source file to E:\MavenDemo\target\classes
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 2.115 s
[INFO] Finished at: 2020-09-02T11:22:58+08:00
[INFO] ------------------------------------------------------------------------
E:\MavenDemo
λ mvn package
[INFO] Scanning for projects...
[INFO]
[INFO] -------------------< com.shangguan.maven:MavenDemo >--------------------
[INFO] Building MavenDemo 1.0-SNAPSHOT
[INFO] --------------------------------[ jar ]---------------------------------
[INFO]
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ MavenDemo ---
[WARNING] Using platform encoding (GBK actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] Copying 0 resource
[INFO]
[INFO] --- maven-compiler-plugin:3.1:compile (default-compile) @ MavenDemo ---
[INFO] Nothing to compile - all classes are up to date
[INFO]
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ MavenDemo ---
[WARNING] Using platform encoding (GBK actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] skip non existing resourceDirectory E:\MavenDemo\src\test\resources
[INFO]
[INFO] --- maven-compiler-plugin:3.1:testCompile (default-testCompile) @ MavenDemo ---
[INFO] No sources to compile
[INFO]
[INFO] --- maven-surefire-plugin:2.12.4:test (default-test) @ MavenDemo ---
[INFO] No tests to run.
[INFO]
[INFO] --- maven-jar-plugin:2.4:jar (default-jar) @ MavenDemo ---
[INFO] Building jar: E:\MavenDemo\target\MavenDemo-1.0-SNAPSHOT.jar
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 2.609 s
[INFO] Finished at: 2020-09-02T11:24:38+08:00
[INFO] ------------------------------------------------------------------------
E:\MavenDemo
λ maven clean
'maven' 不是内部或外部命令,也不是可运行的程序
或批处理文件。
E:\MavenDemo
λ mvn clean
[INFO] Scanning for projects...
[INFO]
[INFO] -------------------< com.shangguan.maven:MavenDemo >--------------------
[INFO] Building MavenDemo 1.0-SNAPSHOT
[INFO] --------------------------------[ jar ]---------------------------------
[INFO]
[INFO] --- maven-clean-plugin:2.5:clean (default-clean) @ MavenDemo ---
[INFO] Deleting E:\MavenDemo\target
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 0.599 s
[INFO] Finished at: 2020-09-02T11:25:19+08:00
[INFO] ------------------------------------------------------------------------
E:\MavenDemo
λ mvn install
[INFO] Scanning for projects...
[INFO]
[INFO] -------------------< com.shangguan.maven:MavenDemo >--------------------
[INFO] Building MavenDemo 1.0-SNAPSHOT
[INFO] --------------------------------[ jar ]---------------------------------
[INFO]
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ MavenDemo ---
[WARNING] Using platform encoding (GBK actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] Copying 0 resource
[INFO]
[INFO] --- maven-compiler-plugin:3.1:compile (default-compile) @ MavenDemo ---
[INFO] Changes detected - recompiling the module!
[WARNING] File encoding has not been set, using platform encoding GBK, i.e. build is platform dependent!
[INFO] Compiling 1 source file to E:\MavenDemo\target\classes
[INFO]
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ MavenDemo ---
[WARNING] Using platform encoding (GBK actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] skip non existing resourceDirectory E:\MavenDemo\src\test\resources
[INFO]
[INFO] --- maven-compiler-plugin:3.1:testCompile (default-testCompile) @ MavenDemo ---
[INFO] No sources to compile
[INFO]
[INFO] --- maven-surefire-plugin:2.12.4:test (default-test) @ MavenDemo ---
[INFO] No tests to run.
[INFO]
[INFO] --- maven-jar-plugin:2.4:jar (default-jar) @ MavenDemo ---
[INFO] Building jar: E:\MavenDemo\target\MavenDemo-1.0-SNAPSHOT.jar
[INFO]
[INFO] --- maven-install-plugin:2.4:install (default-install) @ MavenDemo ---
[INFO] Installing E:\MavenDemo\target\MavenDemo-1.0-SNAPSHOT.jar to F:\MavenResposity\com\shangguan\maven\MavenDemo\1.0-SNAPSHOT\MavenDemo-1.0-SNAPSHOT.jar
[INFO] Installing E:\MavenDemo\pom.xml to F:\MavenResposity\com\shangguan\maven\MavenDemo\1.0-SNAPSHOT\MavenDemo-1.0-SNAPSHOT.pom
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 3.650 s
[INFO] Finished at: 2020-09-02T11:26:03+08:00
[INFO] ------------------------------------------------------------------------
E:\MavenDemo
λ mvn packag
[INFO] Scanning for projects...
[INFO]
[INFO] -------------------< com.shangguan.maven:MavenDemo >--------------------
[INFO] Building MavenDemo 1.0-SNAPSHOT
[INFO] --------------------------------[ jar ]---------------------------------
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 0.308 s
[INFO] Finished at: 2020-09-02T11:31:50+08:00
[INFO] ------------------------------------------------------------------------
[ERROR] Unknown lifecycle phase "packag". You must specify a valid lifecycle phase or a goal in the format <plugin-prefix>:<goal> or <plugin-group-id>:<plugin-artifact-id>[:<plugin-version>]:<goal>. Available lifecycle phases are: validate, initialize, generate-sources, process-sources, generate-resources, process-resources, compile, process-classes, generate-test-sources, process-test-sources, generate-test-resources, process-test-resources, test-compile, process-test-classes, test, prepare-package, package, pre-integration-test, integration-test, post-integration-test, verify, install, deploy, pre-clean, clean, post-clean, pre-site, site, post-site, site-deploy. -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/LifecyclePhaseNotFoundException
修改本地的maven仓库位置:
maven仓库
maven镜像加速
settings.xml
<mirrors>
<!-- mirror
| Specifies a repository mirror site to use instead of a given repository. The repository that
| this mirror serves has an ID that matches the mirrorOf element of this mirror. IDs are used
| for inheritance and direct lookup purposes, and must be unique across the set of mirrors.
|
<mirror>
<id>mirrorId</id>
<mirrorOf>repositoryId</mirrorOf>
<name>Human Readable Name for this Mirror.</name>
<url>http://my.repository.com/repo/path</url>
</mirror>
-->
<mirror>
<id>alimaven</id>
<mirrorOf>central</mirrorOf>
<name>aliyun maven</name>
<url>http://maven.aliyun.com/nexus/content/repositories/central/</url>
</mirror>
<mirror>
<id>jboss-public-repository-group</id>
<mirrorOf>central</mirrorOf>
<name>JBoss Public Repository Group</name>
<url>http://repository.jboss.org/nexus/content/groups/public</url>
</mirror>
</mirrors>
5.6 IDEA配置maven
完整的maven目录:
|src
| main
| java 源码
| resources 依赖文件
| test 测试
|pom.xml 核心配置文件