maven web项目的创建
2021/12/23 23:07:18
本文主要是介绍maven web项目的创建,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!
方式一
1.先创建一个maven jar项目 再添加web
1.1添加web 选择project structure->moudules,选择点击项目 ->点击加号-> 选择web
1.2 配置deployment descriptors 和 web resources directories 选择 点击修改 如下图
1.3修改成功
方式二
2.直接创建maven web项目 缺点:创建完成后会缺少包
2.1创建开始,勾选下图选项 填写选项 并配置maven引用
2.2如图 缺少 main下的java包和resources包 src下的test包以及test包下的java包
2.3 添加缺少的包
右键点击main创建java包和resources包 右键点击java包选择 mark directory as ->sources root 右键点击java包选择 mark directory as ->resources root
右键点击src 创建 test包 再右键点击test创建 java包
再右键点击test包下的java包 选择 marking directory as -> test sources root
2.4 创建成功如下
2.5 配置web.xml
<?xml version="1.0" encoding="UTF-8"?> <web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_4_0.xsd" version="4.0"> </web-app> 2.6 配置pom.xml
<?xml version="1.0" encoding="UTF-8"?> <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.javasm</groupId> <artifactId>maven-web-demo6</artifactId> <version>1.0-SNAPSHOT</version> <!--默认jar项目 可以不写--> <!--<packaging>jar</packaging>--> <!--聚合项目--> <!--<packaging>pom</packaging>--> <!--web项目--> <packaging>war</packaging> <name>maven-web-demo6 Maven Webapp</name> <!-- FIXME change it to the project's website --> <url>http://www.example.com</url> <!--环境变量的配置--> <!--方式一 解决编译 1.7 设置成 1.8--> <properties> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <maven.compiler.encoding>UTF-8</maven.compiler.encoding> <java.version>1.8</java.version> <maven.compiler.source>1.8</maven.compiler.source> <maven.compiler.target>1.8</maven.compiler.target> </properties> <!--<!– 方式二:解决编译 1.5 设置成 1.8 –>--> <!--<build>--> <!--<plugins>--> <!--<plugin>--> <!--<groupId>org.apache.maven.plugins</groupId>--> <!--<artifactId>maven-compiler-plugin</artifactId>--> <!--<configuration>--> <!--<source>1.8</source>--> <!--<target>1.8</target>--> <!--<encoding>UTF-8</encoding>--> <!--</configuration>--> <!--</plugin>--> <!--</plugins>--> <!--</build>--> <!--<!– 配置tomcat7插件–>--> <!--<build>--> <!--<plugins>--> <!--<!–在pom文件中 添加comcat7插件 –>--> <!--<plugin>--> <!--<groupId>org.apache.tomcat.maven</groupId>--> <!--<artifactId>tomcat7-maven-plugin</artifactId>--> <!--<version>2.2</version>--> <!--<configuration>--> <!--<!– 项目访问路径 本例:localhost:9090, 如果配置的aa,则访问路径为localhost:9090/aa –>--> <!--<path>/</path>--> <!--<port>9090</port>--> <!--<uriEncoding>UTF-8</uriEncoding><!– 非必需项 –>--> <!--</configuration>--> <!--</plugin>--> <!--</plugins>--> <!--</build>--> <!--<!–jetty 插件–>--> <!--<build>--> <!--<plugins>--> <!--<plugin>--> <!--<groupId>org.eclipse.jetty</groupId>--> <!--<artifactId>jetty-maven-plugin</artifactId>--> <!--<!–<version>9.3.0.M2</version>–>--> <!--<configuration>--> <!--<webAppConfig>--> <!--<!–配置根路径–>--> <!--<contextPath>/</contextPath>--> <!--</webAppConfig>--> <!--<httpConnector>--> <!--<!–配置端口–>--> <!--<port>10000</port>--> <!--</httpConnector>--> <!--</configuration>--> <!--</plugin>--> <!--</plugins>--> <!--</build>--> <!--配置 Junit版本 配置spring 依赖--> <dependencies> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>4.12</version> <scope>test</scope> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-webmvc</artifactId> <version>5.1.9.RELEASE</version> </dependency> </dependencies> <!--不使用Tomcat的情况下 使用 jetty 插件--> <build> <plugins> <plugin> <groupId>org.eclipse.jetty</groupId> <artifactId>jetty-maven-plugin</artifactId> <version>9.3.0.M2</version> <configuration> <webAppConfig> <!--配置根路径--> <contextPath>/</contextPath> </webAppConfig> <httpConnector> <!--配置端口--> <port>10000</port> </httpConnector> </configuration> </plugin> </plugins> </build> </project>
这篇关于maven web项目的创建的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!
- 2024-10-05小米13T Pro系统合集:性能与摄影的极致融合,值得你升级的系统ROM
- 2024-10-01基于Python+Vue开发的医院门诊预约挂号系统
- 2024-10-01基于Python+Vue开发的旅游景区管理系统
- 2024-10-01RestfulAPI入门指南:打造简单易懂的API接口
- 2024-10-01初学者指南:了解和使用Server Action
- 2024-10-01Server Component入门指南:搭建与配置详解
- 2024-10-01React 中使用 useRequest 实现数据请求
- 2024-10-01使用 golang 将ETH账户的资产平均分散到其他账户
- 2024-10-01JWT用户校验课程:从入门到实践
- 2024-10-01Server Component课程入门指南