最近对maven进行了试探性的研究,今天对其进行总结!感谢
snowolf 同学的大力支持!基础的maven介绍与配置请参见
Maven零散笔记——常用配置,这里仅对一些容易出现问题的地方进行说明!
一、别忘了修改project文件
当我们使用maven创建一个web项目后,首先要记得修改project文件哦!
自动生成的文件:
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.maven.ide.eclipse.maven2Builder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
<nature>org.maven.ide.eclipse.maven2Nature</nature>
</natures>
需要替换的部分证实buildSpec和natures。
<buildSpec>
<buildCommand>
<name>org.eclipse.wst.jsdt.core.javascriptValidator</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.wst.common.project.facet.core.builder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.maven.ide.eclipse.maven2Builder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.wst.validation.validationbuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.springframework.ide.eclipse.core.springbuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.springframework.ide.eclipse.core.springnature</nature>
<nature>org.eclipse.jem.workbench.JavaEMFNature</nature>
<nature>org.eclipse.wst.common.modulecore.ModuleCoreNature</nature>
<nature>org.eclipse.jdt.core.javanature</nature>
<nature>org.maven.ide.eclipse.maven2Nature</nature>
<nature>org.eclipse.wst.common.project.facet.core.nature</nature>
<nature>org.eclipse.wst.jsdt.core.jsNature</nature>
</natures>
有人要问了,为什么需要改project啊?原因很简单,因为我们下一步要设置project facets。你可能发现在未修改project时,project facets在properties里是根本没有的!
二、如果项目中需要servlet-api-2.4.jar等tomcat的lib库中已有的jar包,请将jar包放在WEB-INF的lib下,而不是使用pom从maven检出,因为这样会引起tomcat启动后的异常
javax.servlet.ServletException: java.lang.NoSuchMethodError: javax.servlet.jsp.JspFactory.getJspApplicationContext(Ljavax/servlet/ServletContext;)Ljavax/servlet/jsp/JspApplicationContext;
等。
三、jsp相关jar包jstl和standard
<dependency>
<groupId>taglibs</groupId>
<artifactId>standard</artifactId>
<version>1.1.2</version>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
<version>1.2</version>
</dependency>
四、神奇的class not found!
我的项目用到了spring,在启动时遇到了神奇的 java.lang.ClassNotFoundException: org.springframework.web.context.ContextLoaderListener!而在maven Dependencies中相应的jar包已经存在了,这是为什么呢?我在.classpath文件中找到了解决办法!
原始calsspath文件
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry excluding="**|src/main/java/|src/main/java/" kind="src" output="target/classes" path="src/main/resources"/>
<classpathentry kind="src" path="com.main.java"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/J2SE-1.5"/>
<classpathentry kind="con" path="org.maven.ide.eclipse.MAVEN2_CLASSPATH_CONTAINER"/>
<classpathentry kind="con" path="org.eclipse.jst.j2ee.internal.web.container"/>
<classpathentry kind="con" path="org.eclipse.jst.j2ee.internal.module.container"/>
<classpathentry kind="output" path="target/classes"/>
</classpath>
修改后的classpath文件,对org.maven.ide.eclipse.MAVEN2_CLASSPATH_CONTAINER 添加了一个attribute,并添加了一个classpathentry!
<classpathentry kind="con" path="org.maven.ide.eclipse.MAVEN2_CLASSPATH_CONTAINER">
<attributes>
<attribute name="org.eclipse.jst.component.dependency" value="/WEB-INF/lib"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
<attributes>
<attribute name="org.eclipse.jst.component.dependency" value="/WEB-INF/lib"/>
</attributes>
</classpathentry>
刷新项目,重启!一切OK!
后记:
关于eclipse中class not found的问题
最近换了新版本的eclipse,发现这个问题只需要在项目中设置一下就OK了!
development assembly 中,添加maven dependencies 就好了!和改配置文件应该是一样的作用。
- 大小: 66.8 KB
- 大小: 144.7 KB
分享到:
相关推荐
持续集成环境maven+nexus+jenkins+svn搭建
使用Maven+SVN+Eclipse搭建可持续构建环境
SSM+MAVEN简单实现了一个查询数据库功能,导入即可使用,配有数据可以表
1、Testng+selenium+Maven+WebDriver+Java+eclipse 实现禅道登录,百度搜索。 2、eclipse需安装Testng+selenium+Maven 3、下载对应版本的WebDriver驱动。Chrome驱动下载地址...
Struts 2是Apache基金会的明星级产品,提供了对MVC的一个清晰的实现,下面就为大家介绍一下使用maven+eclipse搭建struts2开发环境的方法
eclipse下SpringMVC+Maven+Mybatis+MySQL项目搭建
一个相对简单但比较完整的基于spring+springmvc+mybatis+mysql+maven+eclipse的工程实例,适合初学者参考
maven+tomcat+eclipse配置实例
Eclipse+Maven+SSM搭建,附带项目、搭建文档,以及截图和重要文件等
详细介绍Eclipse+maven+jetty开发环境搭建
Java+MySQL+SQLyog+tomcat+maven+eclipse+mariadb 一健解压安装的软件包
Maven+Eclipse+SpringMVC+MyBatis实例,使用了dao和mapper两种方式
eclipse+maven+springmvc+spring+mybatis案例附带mysql数据库
用Maven+Eclipse Neon配置Hibernate5例子
maven+svn+eclipse插件安装及环境搭建
NULL 博文链接:https://saberhaha.iteye.com/blog/1173052
Maven+Spring+Spring MVC+MyBatis+MySQL,搭建SSM框架环境
最近读了spring-boot开发手册,spring-boot相比于spring-mvc封装了很多常用的依赖,并且内置了tomcat容器,启动生成的jar包即可启动项目,也是目前流行的微服务常用框架。本文主要用到了spring-boot,以及mybatis,...
IDEA2018+Maven+SSM 项目 一个小Demo,留作纪念。