赞
踩
目录
(2)在自动生成的pom.xml文件中。引入Servlet API依赖的jar包。
不使用tomcat也可以打开html页面,但是通过打开本地文件的形式打开的,一旦换了别的主机,没有本地文件就无法正常打开。
但是我们平时上网看到的html网址一般都是: http://12306.com/index.html 这样的形式,在任何主机都可以打开,这是因为有web服务器的存在
Tomcat是常见的免费的web服务器。本地文件部署在了这个web服务器上,所以就可以随意访问了。
官方下载链接:
这里我们假设下载tomcat8
点击zip下载
下载后解压到一个目录,就能使用,这里我解压到了D盘自己创建的文件夹(目录最好不要有中文)
启动:打开bin文件--->双击startup.bat
出现如下乱码无需担心,表示启动成功
-------------------------------------------------------------------------------------------------------------------------------
如果双击startup.bat会闪退,使用下面两个方法
方法1:tomcat默认占用两个端口号:8080(监听http响应),8005(主要用来监听进程关闭)
查看端口是否被占用--->若被占用--->关闭占用这两个端口号的进程
win+R---输入cmd
输入:netstat -ano(这个命令可以显示本机所有端口占用) 或
netstat -ano | findstr 8080 ( 显示目标端口号为8080的)
记住8080对应的13112,然后在控制栏右键选择任务管理器
点击详细信息--->点击pid进行排序,更方便找到目标pid--->右键结束任务
再次尝试双击startup.bat,若还是失败,尝试方法二
方法二:右键startup.bat,点击编辑,在文件的最后一行加上pause(保证不会闪退)
startup.bat拖到cmd窗口查看失败原因,查看这个博客修改【全网最全解决办法】The CATALINA_HOME environment variable is not defined correctly_Summer-Dream的博客-CSDN博客
Maven是一个跨平台的项目管理工具。作为Apache组织的一个颇为成功的开源项目,其主要服务于基于Java平台的项目创建,依赖管理和项目信息管理,它是一个项目管理的工具,maven自身是纯java开发的,可以使用maven对java项目进行构建、依赖管理。
将setting.xml文件放入.m文件下。一般都没有setting文件,有的话这一步跳过
.m文件一般在这个路径下
可以自己创建一个文件,把下面的内容贴进去
完整的setting文件的内容:
- <?xml version="1.0" encoding="UTF-8"?>
-
- <!--
- Licensed to the Apache Software Foundation (ASF) under one
- or more contributor license agreements. See the NOTICE file
- distributed with this work for additional information
- regarding copyright ownership. The ASF licenses this file
- to you under the Apache License, Version 2.0 (the
- "License"); you may not use this file except in compliance
- with the License. You may obtain a copy of the License at
- http://www.apache.org/licenses/LICENSE-2.0
- Unless required by applicable law or agreed to in writing,
- software distributed under the License is distributed on an
- "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- KIND, either express or implied. See the License for the
- specific language governing permissions and limitations
- under the License.
- -->
-
- <!--
- | This is the configuration file for Maven. It can be specified at two levels:
- |
- | 1. User Level. This settings.xml file provides configuration for a single user,
- | and is normally provided in ${user.home}/.m2/settings.xml.
- |
- | NOTE: This location can be overridden with the CLI option:
- |
- | -s /path/to/user/settings.xml
- |
- | 2. Global Level. This settings.xml file provides configuration for all Maven
- | users on a machine (assuming they're all using the same Maven
- | installation). It's normally provided in
- | ${maven.conf}/settings.xml.
- |
- | NOTE: This location can be overridden with the CLI option:
- |
- | -gs /path/to/global/settings.xml
- |
- | The sections in this sample file are intended to give you a running start at
- | getting the most out of your Maven installation. Where appropriate, the default
- | values (values used when the setting is not specified) are provided.
- |
- |-->
- <settings xmlns="http://maven.apache.org/SETTINGS/1.2.0"
- xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.2.0 https://maven.apache.org/xsd/settings-1.2.0.xsd">
- <!-- localRepository
- | The path to the local repository maven will use to store artifacts.
- |
- | Default: ${user.home}/.m2/repository
- <localRepository>/path/to/local/repo</localRepository>
- -->
-
- <!-- interactiveMode
- | This will determine whether maven prompts you when it needs input. If set to false,
- | maven will use a sensible default value, perhaps based on some other setting, for
- | the parameter in question.
- |
- | Default: true
- <interactiveMode>true</interactiveMode>
- -->
-
- <!-- offline
- | Determines whether maven should attempt to connect to the network when executing a build.
- | This will have an effect on artifact downloads, artifact deployment, and others.
- |
- | Default: false
- <offline>false</offline>
- -->
-
- <!-- pluginGroups
- | This is a list of additional group identifiers that will be searched when resolving plugins by their prefix, i.e.
- | when invoking a command line like "mvn prefix:goal". Maven will automatically add the group identifiers
- | "org.apache.maven.plugins" and "org.codehaus.mojo" if these are not already contained in the list.
- |-->
- <pluginGroups>
- <!-- pluginGroup
- | Specifies a further group identifier to use for plugin lookup.
- <pluginGroup>com.your.plugins</pluginGroup>
- -->
- </pluginGroups>
-
- <!-- proxies
- | This is a list of proxies which can be used on this machine to connect to the network.
- | Unless otherwise specified (by system property or command-line switch), the first proxy
- | specification in this list marked as active will be used.
- |-->
- <proxies>
- <!-- proxy
- | Specification for one proxy, to be used in connecting to the network.
- |
- <proxy>
- <id>optional</id>
- <active>true</active>
- <protocol>http</protocol>
- <username>proxyuser</username>
- <password>proxypass</password>
- <host>proxy.host.net</host>
- <port>80</port>
- <nonProxyHosts>local.net|some.host.com</nonProxyHosts>
- </proxy>
- -->
- </proxies>
-
- <!-- servers
- | This is a list of authentication profiles, keyed by the server-id used within the system.
- | Authentication profiles can be used whenever maven must make a connection to a remote server.
- |-->
- <servers>
- <!-- server
- | Specifies the authentication information to use when connecting to a particular server, identified by
- | a unique name within the system (referred to by the 'id' attribute below).
- |
- | NOTE: You should either specify username/password OR privateKey/passphrase, since these pairings are
- | used together.
- |
- <server>
- <id>deploymentRepo</id>
- <username>repouser</username>
- <password>repopwd</password>
- </server>
- -->
-
- <!-- Another sample, using keys to authenticate.
- <server>
- <id>siteServer</id>
- <privateKey>/path/to/private/key</privateKey>
- <passphrase>optional; leave empty if not used.</passphrase>
- </server>
- -->
- </servers>
-
- <!-- mirrors
- | This is a list of mirrors to be used in downloading artifacts from remote repositories.
- |
- | It works like this: a POM may declare a repository to use in resolving certain artifacts.
- | However, this repository may have problems with heavy traffic at times, so people have mirrored
- | it to several places.
- |
- | That repository definition will have a unique id, so we can create a mirror reference for that
- | repository, to be used as an alternate download site. The mirror site will be the preferred
- | server for that repository.
- |-->
- <mirrors>
- <!-- mirror
- | Specifies a repository mirror site to use instead of a given repository. The repository that
- | this mirror serves has an ID that matches the mirrorOf element of this mirror. IDs are used
- | for inheritance and direct lookup purposes, and must be unique across the set of mirrors.
- |
- <mirror>
- <id>mirrorId</id>
- <mirrorOf>repositoryId</mirrorOf>
- <name>Human Readable Name for this Mirror.</name>
- <url>http://my.repository.com/repo/path</url>
- </mirror>
- -->
- <mirror>
- <id>aliyunmaven</id>
- <mirrorOf>*</mirrorOf>
- <name>阿里云公共仓库</name>
- <url>https://maven.aliyun.com/repository/public</url>
- </mirror>
- </mirrors>
-
- <!-- profiles
- | This is a list of profiles which can be activated in a variety of ways, and which can modify
- | the build process. Profiles provided in the settings.xml are intended to provide local machine-
- | specific paths and repository locations which allow the build to work in the local environment.
- |
- | For example, if you have an integration testing plugin - like cactus - that needs to know where
- | your Tomcat instance is installed, you can provide a variable here such that the variable is
- | dereferenced during the build process to configure the cactus plugin.
- |
- | As noted above, profiles can be activated in a variety of ways. One way - the activeProfiles
- | section of this document (settings.xml) - will be discussed later. Another way essentially
- | relies on the detection of a system property, either matching a particular value for the property,
- | or merely testing its existence. Profiles can also be activated by JDK version prefix, where a
- | value of '1.4' might activate a profile when the build is executed on a JDK version of '1.4.2_07'.
- | Finally, the list of active profiles can be specified directly from the command line.
- |
- | NOTE: For profiles defined in the settings.xml, you are restricted to specifying only artifact
- | repositories, plugin repositories, and free-form properties to be used as configuration
- | variables for plugins in the POM.
- |
- |-->
- <profiles>
- <!-- profile
- | Specifies a set of introductions to the build process, to be activated using one or more of the
- | mechanisms described above. For inheritance purposes, and to activate profiles via <activatedProfiles/>
- | or the command line, profiles have to have an ID that is unique.
- |
- | An encouraged best practice for profile identification is to use a consistent naming convention
- | for profiles, such as 'env-dev', 'env-test', 'env-production', 'user-jdcasey', 'user-brett', etc.
- | This will make it more intuitive to understand what the set of introduced profiles is attempting
- | to accomplish, particularly when you only have a list of profile id's for debug.
- |
- | This profile example uses the JDK version to trigger activation, and provides a JDK-specific repo.
- <profile>
- <id>jdk-1.4</id>
- <activation>
- <jdk>1.4</jdk>
- </activation>
- <repositories>
- <repository>
- <id>jdk14</id>
- <name>Repository for JDK 1.4 builds</name>
- <url>http://www.myhost.com/maven/jdk14</url>
- <layout>default</layout>
- <snapshotPolicy>always</snapshotPolicy>
- </repository>
- </repositories>
- </profile>
- -->
-
- <!--
- | Here is another profile, activated by the system property 'target-env' with a value of 'dev',
- | which provides a specific path to the Tomcat instance. To use this, your plugin configuration
- | might hypothetically look like:
- |
- | ...
- | <plugin>
- | <groupId>org.myco.myplugins</groupId>
- | <artifactId>myplugin</artifactId>
- |
- | <configuration>
- | <tomcatLocation>${tomcatPath}</tomcatLocation>
- | </configuration>
- | </plugin>
- | ...
- |
- | NOTE: If you just wanted to inject this configuration whenever someone set 'target-env' to
- | anything, you could just leave off the <value/> inside the activation-property.
- |
- <profile>
- <id>env-dev</id>
- <activation>
- <property>
- <name>target-env</name>
- <value>dev</value>
- </property>
- </activation>
- <properties>
- <tomcatPath>/path/to/tomcat/instance</tomcatPath>
- </properties>
- </profile>
- -->
- </profiles>
-
- <!-- activeProfiles
- | List of profiles that are active for all builds.
- |
- <activeProfiles>
- <activeProfile>alwaysActiveProfile</activeProfile>
- <activeProfile>anotherAlwaysActiveProfile</activeProfile>
- </activeProfiles>
- -->
- </settings>
两次配置一样,但一定要配置两次
然后再弹出来的界面选择in this window(即在当前窗口打开刚建好的项目)
创建成功后会自动生成一系列文件
可能没有webapp,自己创建一个
创建第一个java文件,右键main--选择File---选择Directory---一定要点击Directory下的java,保证文件夹创建出来是蓝色的。
Servlet 的版本要和 Tomcat 匹配。我们用的tomcat是8.5则Servlet选择对应的3.1即可
下面是官网,要选择tomcat对应的版本下载
nullhttps://mvnrepository.com/artifact/javax.servlet/javax.servlet-api
复制框里的内容
粘贴到pom.xml中的<dependencies>标签下
配置文件完成了
动拷贝 war /jar包到 Tomcat 的过程比较麻烦。接下来安装几个插件
点击File->Settings,在黄色框中可以搜索我们要安装的插件,分别是
和
install后点击自动重启idea
选择正确的Tomcat server,这个路径就是当时安装Tomcat的路径
对应的功能:
到这里一切配置工作就完成了
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。