之前用Eclipse測試maven 的web工程,在eclipse內部tomcat右鍵上點一下「clean」就能夠把工做空間的web項目代碼自動發佈到「F:\IWorkspace\.metadata\.plugins\org.eclipse.wst.server.core\tmp2\wtpwebapps」這個路徑,十分的方便。若是tomcat裏部署的war包選擇的是「Add External Web Module」的話,那測試的話,就要哭了。每次測試前都要用maven命令進行從新打包,打包的過程不只十分慢,並且打包的時候要大量的寫磁盤,這個時候你的電腦基本不能幹其餘事了。 html
這一段時間,個人eclipse忽然無法用內部包了,現象是,」\WEB-INF\lib「這個路徑下只有少許maven依賴的jar包。一運行tomcat就會報ClassNotFoundException。今天把這個問題解決了。步驟以下: web
打開maven Web子模塊的.project文件,<buildSpec>這個節點內部添加以下節點: tomcat
<buildCommand> <name>org.eclipse.m2e.core.maven2Builder</name> <arguments> </arguments> </buildCommand>
<natures>節點下添加以下節點: app
<nature>org.eclipse.m2e.core.maven2Nature</nature>
再打開maven Web子模塊的.classpath文件,添加以下節點: eclipse
<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER"> <attributes> <attribute name="maven.pomderived" value="true"/> <attribute name="org.eclipse.jst.component.dependency" value="/WEB-INF/lib"/> </attributes> </classpathentry>
其實這個節點通常都是有的,可是必定要確認有沒有這個屬性<attribute name="org.eclipse.jst.component.dependency" value="/WEB-INF/lib"/>。 webapp
而後在eclipse的項目上refresh一下maven項目,不refresh一下eclipse裏的工程是沒有效果的。而後再在這個項目對應的tomcat上郵件點擊」clean「。而後去自動發佈的路徑上,就會發現,全部maven依賴的jar包都出來了。 maven