普通web项目转化为maven web项目
2023-09-14 09:00:23 时间
1..configure - Convert to Maven Project
2..maven添加jetty支持 ,并且修改webAppSourceDirectory
!-- 添加jetty支持,Jetty 8 必须 Jdk 1.6+,Servlet 3.0,类似于 Tomcat 7--
plugin
groupId org.mortbay.jetty /groupId
artifactId jetty-maven-plugin /artifactId
version 8.1.16.v20140903 /version
configuration
webAppSourceDirectory ${basedir}/WebContent /webAppSourceDirectory
/configuration
/plugin
重要:maven项目webAppSourceDirectory默认为src/main/webapp对应于普通web项目的webcontent目录
mvn jetty:run-war 先打包,然后再部署(只打成war包的话也可以用mvn package命令)
mvn jetty:run -Djetty.port=80 默认端口也为8080
3.转换为maven项目jetty运行乱码问题(maven打包时候系统默认编码为 gbk)
pom.xml添加下面两个plugin
plugin
groupId org.apache.maven.plugins /groupId
artifactId maven-resources-plugin /artifactId
configuration
encoding UTF-8 /encoding
/configuration
/plugin
plugin
artifactId maven-compiler-plugin /artifactId
configuration
encoding UTF-8 /encoding
/configuration
/plugin
${basedir} represents the directory containing pom.xml
4.添加junit依赖
dependencies
dependency
groupId junit /groupId
artifactId junit /artifactId
version 4.11 /version
/dependency
/dependencies
5.添加服务器相关jar包
dependency
groupId javax.servlet /groupId
artifactId servlet-api /artifactId
version 2.5 /version
scope provided /scope
/dependency
6.添加json所需依赖(Jackson三个主要的模块:缺少这些jar包无法将对象转成json)
fasterxml为2.x(新版spring用的是这个) 1.x版本的包名是codehaus
!--对象转json所需jar包 --
dependency
groupId com.fasterxml.jackson.core /groupId
artifactId jackson-core /artifactId
version 2.1.0 /version
/dependency
dependency
groupId com.fasterxml.jackson.core /groupId
artifactId jackson-databind /artifactId
version 2.1.0 /version
/dependency
dependency
groupId com.fasterxml.jackson.core /groupId
artifactId jackson-annotations /artifactId
version 2.1.0 /version
/dependency
7.依赖jar包放在WebContent/WEB-INF/lib等目录下的情况
配置编译参数 compilerArguments ,添加extdirs将目录下的jar包相对路径添加到配置中,如下:
build
plugins
plugin
artifactId maven-compiler-plugin /artifactId
configuration
source 1.7 /source
target 1.7 /target
encoding UTF-8 /encoding
compilerArguments
extdirs WebContent\WEB-INF\lib /extdirs
/compilerArguments
/configuration
/plugin
/plugins
/build
2..maven添加jetty支持 ,并且修改webAppSourceDirectory
!-- 添加jetty支持,Jetty 8 必须 Jdk 1.6+,Servlet 3.0,类似于 Tomcat 7--
plugin
groupId org.mortbay.jetty /groupId
artifactId jetty-maven-plugin /artifactId
version 8.1.16.v20140903 /version
configuration
webAppSourceDirectory ${basedir}/WebContent /webAppSourceDirectory
/configuration
/plugin
重要:maven项目webAppSourceDirectory默认为src/main/webapp对应于普通web项目的webcontent目录
mvn jetty:run-war 先打包,然后再部署(只打成war包的话也可以用mvn package命令)
mvn jetty:run -Djetty.port=80 默认端口也为8080
3.转换为maven项目jetty运行乱码问题(maven打包时候系统默认编码为 gbk)
pom.xml添加下面两个plugin
plugin
groupId org.apache.maven.plugins /groupId
artifactId maven-resources-plugin /artifactId
configuration
encoding UTF-8 /encoding
/configuration
/plugin
plugin
artifactId maven-compiler-plugin /artifactId
configuration
encoding UTF-8 /encoding
/configuration
/plugin
${basedir} represents the directory containing pom.xml
4.添加junit依赖
dependencies
dependency
groupId junit /groupId
artifactId junit /artifactId
version 4.11 /version
/dependency
/dependencies
5.添加服务器相关jar包
dependency
groupId javax.servlet /groupId
artifactId servlet-api /artifactId
version 2.5 /version
scope provided /scope
/dependency
6.添加json所需依赖(Jackson三个主要的模块:缺少这些jar包无法将对象转成json)
fasterxml为2.x(新版spring用的是这个) 1.x版本的包名是codehaus
!--对象转json所需jar包 --
dependency
groupId com.fasterxml.jackson.core /groupId
artifactId jackson-core /artifactId
version 2.1.0 /version
/dependency
dependency
groupId com.fasterxml.jackson.core /groupId
artifactId jackson-databind /artifactId
version 2.1.0 /version
/dependency
dependency
groupId com.fasterxml.jackson.core /groupId
artifactId jackson-annotations /artifactId
version 2.1.0 /version
/dependency
7.依赖jar包放在WebContent/WEB-INF/lib等目录下的情况
配置编译参数 compilerArguments ,添加extdirs将目录下的jar包相对路径添加到配置中,如下:
build
plugins
plugin
artifactId maven-compiler-plugin /artifactId
configuration
source 1.7 /source
target 1.7 /target
encoding UTF-8 /encoding
compilerArguments
extdirs WebContent\WEB-INF\lib /extdirs
/compilerArguments
/configuration
/plugin
/plugins
/build
相关文章
- Eclipse使用Maven创建Web时错误:Could not resolve archetype org.apache.maven.archetypes:maven-archetype-webap
- IDEA运行web项目需要的一些配置(tomcat,maven)
- webstorm 使用git_idea使用maven创建web项目
- Maven 菜鸟教程 3 怎样启动web项目
- java中的maven_maven创建web项目
- eclipse引入jar包_eclipse导入maven项目
- idea创建Java web项目_idea导入maven项目
- Maven
- maven本地仓库配置了不起作用_maven指定远程仓库地址
- Maven项目报错:“ SLF4J: Failed to load class “org.slf4j.impl.StaticLoggerBinder ”解决办法「建议收藏」
- windows系统中安装maven用来编译项目
- 在idea中打开maven项目pom.xml未识别详解程序员
- 分享一个快的飞起的maven的settings.xml文件详解程序员
- eclipse中启动调试maven构建的javaweb项目详解程序员
- ubuntu中maven建的web项目不能将project facet设置为 dynamic web module 3.0详解程序员
- Maven学习— 搭建多模块企业级项目详解编程语言
- maven 项目中使用 jstl标签详解编程语言
- Eclipse导入Maven项目
- 使用MyEclipse建立maven项目
- 快速部署Linux环境下Web项目(linux部署web项目)
- 的依赖Maven中添加MySQL依赖的操作步骤(maven添加mysql)
- 使用Maven搭建Oracle数据库环境(maven oracle)
- Web项目下使用Redis加速优化(web项目 redis)