Maven超详细讲解-------maven项目的创建

目录

1.Maven项目的创建

1.1创建java项目

1.1.1 新建项目

1.2 创建web项目

1.2.1 新建项目

1.2.2 启动项目


1.Maven项目的创建

1.1创建java项目

1.1.1 新建项目

先关闭所有项目

进入新建页面 

quickstart

改路径和配置文件

点击完成进入

在test下也建一个

 将test下的resource更改图标 标记为

利用maven命令去编译这个项目

利用maven命令去打包

1.2 创建web项目

1.2.1 新建项目

新建web项目和创建java项目基本一致,区别在于选择Maven模板(web项目选择webapp),如图

1.2.2 启动项目

1.2.2.1 修改jdk的版本

在pom.xml文件里修改为1.8

<properties>
  <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
  <maven.compiler.source>1.8</maven.compiler.source>
  <maven.compiler.target>1.8</maven.compiler.target>
</properties>

1.2.2.2 设置单元测试的版本

修改为4.12

<dependencies>
  <dependency>
    <groupId>junit</groupId>
    <artifactId>junit</artifactId>
    <version>4.12</version>
    <scope>test</scope>
  </dependency>
</dependencies>

1.2.2.3 删除pluginManagement标签

<!--将这个标签以及标签中的内容全部删除-->
<pluginManagement>
  .....
</pluginManagement>

1.2.2.4添加web部署插件

在build标签中添加plugins标签

1.Jetty插件

添加到plugins下

<!-- 设置在plugins标准中 -->
<plugin>
  <groupId>org.eclipse.jetty</groupId>
  <artifactId>jetty-maven-plugin</artifactId>
  <version>9.2.11.v20150529</version>
  <configuration>
    <!--热部署,每10秒扫描一次-->
    <scanIntervalSeconds>10</scanIntervalSeconds>
    <webApp>
      <!--可指定当前项目的站点名-->
      <contextPath>/test</contextPath>
    </webApp>
    <httpConnector>
      <port>9090</port> <!--设定端口号-->
    </httpConnector>
  </configuration>
</plugin>

2.Tomcat插件

<!-- Tomcat插件 -->
<plugin>
  <groupId>org.apache.tomcat.maven</groupId>
  <artifactId>tomcat7-maven-plugin</artifactId>
  <version>2.2</version>
  <configuration>
    <!--配置端口号-->
    <port>80</port>
    <!--配置项目路径-->
    <path>/mavenWeb</path>
  </configuration>
</plugin>

刷新依赖

1.2.2.5 启动项目

点击右上角的 “Add Configurations”,打开“Run/Dedug Configurations”窗口

1.jetty启动

访问路径

在浏览器输入网址

http://localhost:9090/test/index.jsp

2.tomcat启动

访问路径

http://localhost/mavenWeb/index.jsp

可以看到浏览器中显示 Hello World即成功运行

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值