maven坐标
Maven坐标:简称为GAV坐标,确定当前项目打成的Jar包在本地仓库的位置。
<groupId>com.weilinyang.maven</groupId>
<artifactId>Hello</artifactId>
<version>0.0.1-SNAPSHOT</version>
groupId:公司域名反写.项目名
artifactId:项目名_模块名|模块名
version: 0.0.1-SNAPSHOT
maven坐标和依赖的区别
Maven坐标:用来确定当前项目打成的Jar包在本地仓库的位置的。一个项目只有一个坐标
<groupId>com.weilinyang.maven</groupId>
<artifactId>Hello</artifactId>
<version>0.0.1-SNAPSHOT</version>
Maven的依赖:用来引入当前项目所需要的Jar包,一个项目可以引入多个依赖信息
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.0</version>
<scope>test</scope>
</dependency>
根据maven坐标找jar包
确定Jar所在目录: groupId+ artifactId+ version
com/weilinyang/maven/ Hello/0.0.1-SNAPSHOT/
确定Jar包名称:artifactId- version
Hello-0.0.1-SNAPSHOT.jar
由jar包写出maven坐标
寻找jar的依赖 https://mvnrepository.com/
maven项目类型
jar工程:当一个项目A需要被其它项目依赖的时候,项目A就打成Jar包,
pom工程: 当一个工程是父工程或者聚合工程,就打成pom包
war工程:当项目需要部署到tomcat服务器运行的时候,就打成war包
sourceFolder是在maven项目中保存配置文件的文件夹
省略的话就是jar包
Pom工程的目录只有src,但是pom工程需要的只有pom文件
maven创建项目中遇到的常见问题
问题一web.xml is missing and is set to true
缺少web.xml文件
解决方案:右键项目—JavaEE tools-Generate Deployment Descriptor Stub
问题二:
The superclass “javax.servlet.http.HttpServlet” was not found on the Java Build Path
解决方案:在项目的pom.xml文件中加入如下依赖
jsp-api
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jsp-api</artifactId>
<version>2.0</version>
<scope>provided</scope>
</dependency>
servlet-api
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>3.1.0</version>
<scope>provided</scope>
</dependency>
问题三:Jdk问题
第一种:
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.5.1</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
<encoding>UTF-8</encoding>
</configuration>
</plugin>
</plugins>
</build>
第二种方式:在maven安装目录的conf/settings.xml文件中配置:
<profile>
<id>jdk-1.7</id>
<activation>
<activeByDefault>true</activeByDefault>
<jdk>1.7</jdk>
</activation>
<properties>
<maven.compiler.source>1.7</maven.compiler.source>
<maven.compiler.target>1.7</maven.compiler.target>
<maven.compiler.compilerVersion>1.7</maven.compiler.compilerVersion>
</properties>
</profile>
重启eclipse,再次创建项目的时候,就默认使用Jdk1.8
问题四: JDK问题
错误:on a JRE rather than a JDK
Eclipse中的JDK配置有问题,配置成了JRE的目录,改成JDK目录
问题五:
-Dmaven.multiModuleProjectDirectory system property is not set.
Check $M2_HOME environment variable and mvn script match.
Windows系统maven环境变量的键:M2_HOME
tomcat插件配置
<build>
<plugins>
<plugin>
<groupId>org.apache.tomcat.maven</groupId>
<artifactId>tomcat7-maven-plugin</artifactId>
<version>2.2</version>
<configuration>
<path>/ssm</path>
<port>8888</port>
</configuration>
</plugin>
</plugins>
</build>
tomcat插件暂时只有6和7,没有8
path配置的是当前项目的访问路径名
port是访问端口