版本:IntelliJIDEA2018.1.4
一、同一窗口展示多个应用(弊端:耗内存)
idea没有eclipse workspace的概念,如果想在同一窗口显示多个应用,可以按照如下方式来做:
1、新建空工程
File-->new-->Project...
2、新建Modules
CTRL+ALT+SHIFT+S:
比如新建一个静态页面模块:
新建一个纯Java应用:
左侧选择Java,右侧选择JDK,下面不要选择任何Frameworks
最后效果:
二、搭建java web工程
1、搭建
(1)新建Java Enterprise
(2)在WEB-INF下面新建两个Directory:classes和lib
2、配置web项目(CTRL+ALT+SHIFT+S)
(1)配置编译输出路径
(2)添加依赖jar包
编译之后:
(3)配置打包方式Artifacts
编译之后:
(4)Tomcat配置
Tomcat 集成原理:
为项目配置了 tomcat 后,idea 会拷贝一份配置到系统目录中,如下
(1)conf存放配置:
Tomcat 之所以可以 root 启动和热部署,原因在如下:
(2)logs目录是各项日志:
(3)work目录存放class和页面文件:
三、搭建maven工程
1、搭建简单java工程,使用模板:maven-archetype-quickstart
配置配置 groupId 和 ArtifactId:
配置 maven 构建工具信息:
配置module信息:
Finish,完成。稍等片刻,选择右下角,enable auto import:
最终效果:
2、搭建maven web工程
使用模板:maven-archetype-webapp
使用模板创建的目录没有java和resources目录,执行创建然后,修改目录属性
最终效果:
3、不使用maven模板创建工程:
maven类型工程配置tomcat与上面普通Java web应用相同。
遇到的问题:
tomcat启动后,jsp未编译。
原因:项目Artifacts配置有问题
参考:正场项目的配置:
另附上正常启动tomcat日志,和eclipse不太一样,注意几个关键点:
D:apache-tomcat-8.5.43incatalina.bat run [2019-10-11 02:19:02,554] Artifact activiti:war exploded: Waiting for server connection to start artifact deployment... Using CATALINA_BASE: "C:UsersAdministrator.IntelliJIdea2018.1system omcatUnnamed_activiti" Using CATALINA_HOME: "D:apache-tomcat-8.5.43" Using CATALINA_TMPDIR: "D:apache-tomcat-8.5.43 emp" Using JRE_HOME: "C:javajdk1.8.0_171" Using CLASSPATH: "D:apache-tomcat-8.5.43inootstrap.jar;D:apache-tomcat-8.5.43in omcat-juli.jar" Connected to the target VM, address: 'javadebug', transport: 'shared memory' 11-Oct-2019 14:19:03.683 信息 [main] org.apache.catalina.startup.VersionLoggerListener.log Server version: Apache Tomcat/8.5.43 11-Oct-2019 14:19:03.687 信息 [main] org.apache.catalina.startup.VersionLoggerListener.log Server built: Jul 4 2019 20:53:15 UTC 11-Oct-2019 14:19:03.687 信息 [main] org.apache.catalina.startup.VersionLoggerListener.log Server number: 8.5.43.0 11-Oct-2019 14:19:03.687 信息 [main] org.apache.catalina.startup.VersionLoggerListener.log OS Name: Windows 7 11-Oct-2019 14:19:03.688 信息 [main] org.apache.catalina.startup.VersionLoggerListener.log OS Version: 6.1 11-Oct-2019 14:19:03.688 信息 [main] org.apache.catalina.startup.VersionLoggerListener.log Architecture: amd64 11-Oct-2019 14:19:03.688 信息 [main] org.apache.catalina.startup.VersionLoggerListener.log Java Home: C:javajdk1.8.0_171jre 11-Oct-2019 14:19:03.688 信息 [main] org.apache.catalina.startup.VersionLoggerListener.log JVM Version: 1.8.0_171-b11 11-Oct-2019 14:19:03.688 信息 [main] org.apache.catalina.startup.VersionLoggerListener.log JVM Vendor: Oracle Corporation 11-Oct-2019 14:19:03.688 信息 [main] org.apache.catalina.startup.VersionLoggerListener.log CATALINA_BASE: C:UsersAdministrator.IntelliJIdea2018.1system omcatUnnamed_activiti 11-Oct-2019 14:19:03.689 信息 [main] org.apache.catalina.startup.VersionLoggerListener.log CATALINA_HOME: D:apache-tomcat-8.5.43 11-Oct-2019 14:19:03.689 信息 [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Djava.util.logging.config.file=C:UsersAdministrator.IntelliJIdea2018.1system omcatUnnamed_activiticonflogging.properties 11-Oct-2019 14:19:03.690 信息 [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager 11-Oct-2019 14:19:03.690 信息 [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Dvisualvm.id=23258637664006 11-Oct-2019 14:19:03.690 信息 [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -agentlib:jdwp=transport=dt_shmem,address=javadebug,suspend=y,server=n 11-Oct-2019 14:19:03.690 信息 [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -javaagent:D:JetBrainsIntelliJIDEA2018.1.4lib tdebugger-agent.jar=file:/C:/Users/Administrator/AppData/Local/Temp/capture4739.props 11-Oct-2019 14:19:03.690 信息 [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Dfile.encoding=UTF-8 11-Oct-2019 14:19:03.690 信息 [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Dcom.sun.management.jmxremote= 11-Oct-2019 14:19:03.690 信息 [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Dcom.sun.management.jmxremote.port=1099 11-Oct-2019 14:19:03.690 信息 [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Dcom.sun.management.jmxremote.ssl=false 11-Oct-2019 14:19:03.690 信息 [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Dcom.sun.management.jmxremote.authenticate=false 11-Oct-2019 14:19:03.691 信息 [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Djava.rmi.server.hostname=127.0.0.1 11-Oct-2019 14:19:03.691 信息 [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Djdk.tls.ephemeralDHKeySize=2048 11-Oct-2019 14:19:03.691 信息 [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Djava.protocol.handler.pkgs=org.apache.catalina.webresources 11-Oct-2019 14:19:03.691 信息 [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Dignore.endorsed.dirs= 11-Oct-2019 14:19:03.691 信息 [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Dcatalina.base=C:UsersAdministrator.IntelliJIdea2018.1system omcatUnnamed_activiti 11-Oct-2019 14:19:03.691 信息 [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Dcatalina.home=D:apache-tomcat-8.5.43 11-Oct-2019 14:19:03.691 信息 [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Djava.io.tmpdir=D:apache-tomcat-8.5.43 emp 11-Oct-2019 14:19:03.691 信息 [main] org.apache.catalina.core.AprLifecycleListener.lifecycleEvent Loaded APR based Apache Tomcat Native library [1.2.23] using APR version [1.7.0]. 11-Oct-2019 14:19:03.691 信息 [main] org.apache.catalina.core.AprLifecycleListener.lifecycleEvent APR capabilities: IPv6 [true], sendfile [true], accept filters [false], random [true]. 11-Oct-2019 14:19:03.691 信息 [main] org.apache.catalina.core.AprLifecycleListener.lifecycleEvent APR/OpenSSL configuration: useAprConnector [false], useOpenSSL [true] 11-Oct-2019 14:19:03.702 信息 [main] org.apache.catalina.core.AprLifecycleListener.initializeSSL OpenSSL successfully initialized [OpenSSL 1.1.1c 28 May 2019] 11-Oct-2019 14:19:03.859 信息 [main] org.apache.coyote.AbstractProtocol.init Initializing ProtocolHandler ["http-nio-8080"] 11-Oct-2019 14:19:03.877 信息 [main] org.apache.tomcat.util.net.NioSelectorPool.getSharedSelector Using a shared selector for servlet write/read 11-Oct-2019 14:19:03.889 信息 [main] org.apache.coyote.AbstractProtocol.init Initializing ProtocolHandler ["ajp-nio-8009"] 11-Oct-2019 14:19:03.892 信息 [main] org.apache.tomcat.util.net.NioSelectorPool.getSharedSelector Using a shared selector for servlet write/read 11-Oct-2019 14:19:03.892 信息 [main] org.apache.catalina.startup.Catalina.load Initialization processed in 685 ms 11-Oct-2019 14:19:03.933 信息 [main] org.apache.catalina.core.StandardService.startInternal Starting service [Catalina] 11-Oct-2019 14:19:03.933 信息 [main] org.apache.catalina.core.StandardEngine.startInternal Starting Servlet Engine: Apache Tomcat/8.5.43 11-Oct-2019 14:19:03.948 信息 [main] org.apache.coyote.AbstractProtocol.start Starting ProtocolHandler ["http-nio-8080"] 11-Oct-2019 14:19:03.965 信息 [main] org.apache.coyote.AbstractProtocol.start Starting ProtocolHandler ["ajp-nio-8009"] 11-Oct-2019 14:19:03.969 信息 [main] org.apache.catalina.startup.Catalina.start Server startup in 76 ms Connected to server [2019-10-11 02:19:04,230] Artifact activiti:war exploded: Artifact is being deployed, please wait... 11-Oct-2019 14:19:07.940 信息 [RMI TCP Connection(3)-127.0.0.1] org.apache.jasper.servlet.TldScanner.scanJars At least one JAR was scanned for TLDs yet contained no TLDs. Enable debug logging for this logger for a complete list of JARs that were scanned but no TLDs were found in them. Skipping unneeded JARs during scanning can improve startup time and JSP compilation time. [INFO] [2019-10-11 14:19:08] org.springframework.web.context.ContextLoader.initWebApplicationContext(305) | Root WebApplicationContext: initialization started [INFO] [2019-10-11 14:19:08] org.springframework.context.support.AbstractApplicationContext.prepareRefresh(582) | Refreshing Root WebApplicationContext: startup date [Fri Oct 11 14:19:08 CST 2019]; root of context hierarchy [INFO] [2019-10-11 14:19:08] org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(317) | Loading XML bean definitions from class path resource [spring/springContext.xml] [INFO] [2019-10-11 14:19:08] org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(317) | Loading XML bean definitions from file [E:workspaceactiviti argetactivitiWEB-INFclassesspringspring-activiti.xml] [INFO] [2019-10-11 14:19:08] org.springframework.core.io.support.PropertiesLoaderSupport.loadProperties(172) | Loading properties file from URL [file:/E:/workspace/activiti/target/activiti/WEB-INF/classes/jdbc.properties] [INFO] [2019-10-11 14:19:08] org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.<init>(155) | JSR-330 'javax.inject.Inject' annotation found and supported for autowiring [INFO] [2019-10-11 14:19:09] org.springframework.jdbc.datasource.DriverManagerDataSource.setDriverClassName(133) | Loaded JDBC driver: com.mysql.jdbc.Driver [INFO] [2019-10-11 14:19:09] org.springframework.web.servlet.handler.AbstractHandlerMethodMapping$MappingRegistry.register(543) | Mapped "{[/index/sayhi]}" onto public java.lang.String com.wjy.controller.IndexController.sayhi(org.springframework.ui.Model) [INFO] [2019-10-11 14:19:09] org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.initControllerAdviceCache(534) | Looking for @ControllerAdvice: Root WebApplicationContext: startup date [Fri Oct 11 14:19:08 CST 2019]; root of context hierarchy [INFO] [2019-10-11 14:19:10] org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.initControllerAdviceCache(534) | Looking for @ControllerAdvice: Root WebApplicationContext: startup date [Fri Oct 11 14:19:08 CST 2019]; root of context hierarchy [INFO] [2019-10-11 14:19:10] org.springframework.web.servlet.handler.AbstractUrlHandlerMapping.registerHandler(354) | Mapped URL path [/**] onto handler 'org.springframework.web.servlet.resource.DefaultServletHttpRequestHandler#0' [INFO] [2019-10-11 14:19:10] org.springframework.web.servlet.handler.AbstractUrlHandlerMapping.registerHandler(354) | Mapped URL path [/resources/**] onto handler 'org.springframework.web.servlet.resource.ResourceHttpRequestHandler#0' [INFO] [2019-10-11 14:19:11] org.activiti.engine.impl.ProcessEngineImpl.<init>(85) | ProcessEngine default created [INFO] [2019-10-11 14:19:12] org.springframework.web.context.ContextLoader.initWebApplicationContext(345) | Root WebApplicationContext: initialization completed in 3948 ms [INFO] [2019-10-11 14:19:12] org.springframework.web.servlet.FrameworkServlet.initServletBean(489) | FrameworkServlet 'SpringMVC': initialization started [INFO] [2019-10-11 14:19:12] org.springframework.context.support.AbstractApplicationContext.prepareRefresh(582) | Refreshing WebApplicationContext for namespace 'SpringMVC-servlet': startup date [Fri Oct 11 14:19:12 CST 2019]; parent: Root WebApplicationContext [INFO] [2019-10-11 14:19:12] org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(317) | Loading XML bean definitions from class path resource [spring/springContext.xml] [INFO] [2019-10-11 14:19:12] org.springframework.core.io.support.PropertiesLoaderSupport.loadProperties(172) | Loading properties file from URL [file:/E:/workspace/activiti/target/activiti/WEB-INF/classes/jdbc.properties] [INFO] [2019-10-11 14:19:12] org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.<init>(155) | JSR-330 'javax.inject.Inject' annotation found and supported for autowiring [INFO] [2019-10-11 14:19:12] org.springframework.jdbc.datasource.DriverManagerDataSource.setDriverClassName(133) | Loaded JDBC driver: com.mysql.jdbc.Driver [INFO] [2019-10-11 14:19:12] org.springframework.web.servlet.handler.AbstractHandlerMethodMapping$MappingRegistry.register(543) | Mapped "{[/index/sayhi]}" onto public java.lang.String com.wjy.controller.IndexController.sayhi(org.springframework.ui.Model) [INFO] [2019-10-11 14:19:12] org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.initControllerAdviceCache(534) | Looking for @ControllerAdvice: WebApplicationContext for namespace 'SpringMVC-servlet': startup date [Fri Oct 11 14:19:12 CST 2019]; parent: Root WebApplicationContext [INFO] [2019-10-11 14:19:12] org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.initControllerAdviceCache(534) | Looking for @ControllerAdvice: WebApplicationContext for namespace 'SpringMVC-servlet': startup date [Fri Oct 11 14:19:12 CST 2019]; parent: Root WebApplicationContext [INFO] [2019-10-11 14:19:12] org.springframework.web.servlet.handler.AbstractUrlHandlerMapping.registerHandler(354) | Mapped URL path [/**] onto handler 'org.springframework.web.servlet.resource.DefaultServletHttpRequestHandler#0' [INFO] [2019-10-11 14:19:12] org.springframework.web.servlet.handler.AbstractUrlHandlerMapping.registerHandler(354) | Mapped URL path [/resources/**] onto handler 'org.springframework.web.servlet.resource.ResourceHttpRequestHandler#0' [INFO] [2019-10-11 14:19:12] org.springframework.web.servlet.FrameworkServlet.initServletBean(508) | FrameworkServlet 'SpringMVC': initialization completed in 499 ms [2019-10-11 02:19:12,618] Artifact activiti:war exploded: Artifact is deployed successfully [2019-10-11 02:19:12,618] Artifact activiti:war exploded: Deploy took 8,388 milliseconds 11-Oct-2019 14:19:13.949 信息 [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployDirectory Deploying web application directory [D:apache-tomcat-8.5.43webappsmanager] 11-Oct-2019 14:19:14.058 信息 [localhost-startStop-1] org.apache.jasper.servlet.TldScanner.scanJars At least one JAR was scanned for TLDs yet contained no TLDs. Enable debug logging for this logger for a complete list of JARs that were scanned but no TLDs were found in them. Skipping unneeded JARs during scanning can improve startup time and JSP compilation time. 11-Oct-2019 14:19:14.068 信息 [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployDirectory Deployment of web application directory [D:apache-tomcat-8.5.43webappsmanager] has finished in [117] ms
关闭tomcat日志:
D:apache-tomcat-8.5.43incatalina.bat stop Disconnected from the target VM, address: 'javadebug', transport: 'shared memory' Using CATALINA_BASE: "C:UsersAdministrator.IntelliJIdea2018.1system omcatUnnamed_activiti" Using CATALINA_HOME: "D:apache-tomcat-8.5.43" Using CATALINA_TMPDIR: "D:apache-tomcat-8.5.43 emp" Using JRE_HOME: "C:javajdk1.8.0_171" Using CLASSPATH: "D:apache-tomcat-8.5.43inootstrap.jar;D:apache-tomcat-8.5.43in omcat-juli.jar" 11-Oct-2019 13:02:47.620 信息 [main] org.apache.catalina.core.StandardServer.await A valid shutdown command was received via the shutdown port. Stopping the Server instance. 11-Oct-2019 13:02:47.621 信息 [main] org.apache.coyote.AbstractProtocol.pause Pausing ProtocolHandler ["http-nio-8080"] 11-Oct-2019 13:02:47.709 信息 [main] org.apache.coyote.AbstractProtocol.pause Pausing ProtocolHandler ["ajp-nio-8009"] 11-Oct-2019 13:02:47.790 信息 [main] org.apache.catalina.core.StandardService.stopInternal Stopping service [Catalina] 11-Oct-2019 13:02:47.811 信息 [main] org.apache.coyote.AbstractProtocol.stop Stopping ProtocolHandler ["http-nio-8080"] 11-Oct-2019 13:02:47.812 信息 [main] org.apache.coyote.AbstractProtocol.stop Stopping ProtocolHandler ["ajp-nio-8009"] 11-Oct-2019 13:02:47.814 信息 [main] org.apache.coyote.AbstractProtocol.destroy Destroying ProtocolHandler ["http-nio-8080"] 11-Oct-2019 13:02:47.815 信息 [main] org.apache.coyote.AbstractProtocol.destroy Destroying ProtocolHandler ["ajp-nio-8009"] Disconnected from server