<一>不選擇任何maven模板建立web項目java
這裏在Properties中添加一個參數archetypeCatalog=internal
,不加這個參數,在maven生成骨架的時候將會很是慢,有時候會直接卡住。web
來自網上的解釋:archetypeCatalog表示插件使用的archetype元數據,不加這個參數時默認爲remote,local,即中央倉庫archetype元數據,因爲中央倉庫的archetype太多了,因此致使很慢,指定internal來表示僅使用內部元數據。如圖:spring
填寫項目名稱,點擊finish,如圖所示:apache
idea爲咱們建立好的目錄結構如圖所示:少java文件:瀏覽器
啓動java web,打開project structure,如圖所示:tomcat
選擇Project,Project SDK是java jdk安裝選擇,Project language level是選擇語言版本,Project compileroutput 是編譯後的文件目錄,這裏咱們的使用默認,你也能夠根據須要填寫。如圖app
選擇Facets,點擊+,選擇web,如圖所示:webapp
在彈出的窗口中選擇項目,點擊ok,如圖所示;jsp
設置web.xml文件目錄,按如圖所示的步驟選擇,如圖所示:maven
選擇Web Resource 目錄,按如圖所示的步驟選擇,如圖:
選擇Artifacts,點擊+,選擇Frome Madules....,在彈出的窗口中選擇ok,點擊Apply。如圖所示:
添加java文件目錄,由於maven模板建立的web項目中少java文件目錄,因此要本身建立,回到Module->選擇項目名->Sources->main右擊->New Folder...,在彈出的文件夾中填寫java點擊ok如圖所示:
將剛纔新建的普通java文件夾變爲Sources文件夾,點擊Apply,再點擊ok。如圖所示步驟:
當集成項目,項目中引入jar包時,啓動項目若是報下面的錯誤,代表找不到jar包,咱們要手動創建lib來放jar包。
03-Dec-2016 09:37:44.044 SEVERE [RMI TCP Connection(2)-127.0.0.1] org.apache.catalina.core.StandardContext.listenerStart Error configuring application listener of class org.springframework.web.context.ContextLoaderListener java.lang.ClassNotFoundException: org.springframework.web.context.ContextLoaderListener at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1285) at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1119) at org.apache.catalina.core.DefaultInstanceManager.loadClass(DefaultInstanceManager.java:520) at org.apache.catalina.core.DefaultInstanceManager.loadClassMaybePrivileged(DefaultInstanceManager.java:501) at org.apache.catalina.core.DefaultInstanceManager.newInstance(DefaultInstanceManager.java:118) at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4649) at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5189) at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150) at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:724) at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:700) at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:734) at org.apache.catalina.startup.HostConfig.manageApp(HostConfig.java:1702) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:498) at org.apache.tomcat.util.modeler.BaseModelMBean.invoke(BaseModelMBean.java:300) at com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.invoke(DefaultMBeanServerInterceptor.java:819) at com.sun.jmx.mbeanserver.JmxMBeanServer.invoke(JmxMBeanServer.java:801) at org.apache.catalina.mbeans.MBeanFactory.createStandardContext(MBeanFactory.java:482) at org.apache.catalina.mbeans.MBeanFactory.createStandardContext(MBeanFactory.java:431) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:498) at org.apache.tomcat.util.modeler.BaseModelMBean.invoke(BaseModelMBean.java:300) at com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.invoke(DefaultMBeanServerInterceptor.java:819) at com.sun.jmx.mbeanserver.JmxMBeanServer.invoke(JmxMBeanServer.java:801) at javax.management.remote.rmi.RMIConnectionImpl.doOperation(RMIConnectionImpl.java:1468) at javax.management.remote.rmi.RMIConnectionImpl.access$300(RMIConnectionImpl.java:76) at javax.management.remote.rmi.RMIConnectionImpl$PrivilegedOperation.run(RMIConnectionImpl.java:1309) at javax.management.remote.rmi.RMIConnectionImpl.doPrivilegedOperation(RMIConnectionImpl.java:1401) at javax.management.remote.rmi.RMIConnectionImpl.invoke(RMIConnectionImpl.java:829) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:498) at sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:324) at sun.rmi.transport.Transport$1.run(Transport.java:200) at sun.rmi.transport.Transport$1.run(Transport.java:197) at java.security.AccessController.doPrivileged(Native Method) at sun.rmi.transport.Transport.serviceCall(Transport.java:196) at sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:568) at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run0(TCPTransport.java:826) at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.lambda$run$0(TCPTransport.java:683) at java.security.AccessController.doPrivileged(Native Method) at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.java:682) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) at java.lang.Thread.run(Thread.java:745) 03-Dec-2016 09:37:44.045 SEVERE [RMI TCP Connection(2)-127.0.0.1] org.apache.catalina.core.StandardContext.listenerStart Skipped installing application listeners due to previous error(s)
手動新建lib:
在WEB-INF下面新建一個lib目錄,如圖;
根據如圖所示的步驟找到剛纔所創建的lib目錄,如圖:
找到lib後在彈出的框中選擇Jar Directory點擊ok,如圖
進入Artifacts,選中右邊項目中的jar包,右擊選擇Put /WEB-INF/lib,ok,如圖
打開「Edit Configurations」,如圖所示:
按照如圖所示步驟進行選擇,如圖:
選擇Deployment->+->Artifact....,點擊應用,如圖所示:
進行熱部署,選擇server->On frame deactiveation中選擇->Update classes and resources,點擊應用,點擊ok。如圖:
點擊啓動程序,如圖所示,web項目搭建成功:
最終的目錄結構如圖所示: