maven和tomcat配置

主要是关于:maven利用阿里云的镜像setting;.m2配置依赖项下载在D盘;配置tomcat。

解决源服务器未能找到目标资源的表示或者是不愿公开一个已经存在的资源表示的问题。


目录

配置maven

修改settings.xml

idle中配置maven

配置tomcat

部署

HTTP状态 404 - 未找到

解决方法如下

tomcat中文乱码解决



先从官网下载maven

Maven – Download Apache Mavenicon-default.png?t=N7T8https://maven.apache.org/download.cgi

和Tomcat

Apache Tomcat® - Apache Tomcat 8 Software Downloadsicon-default.png?t=N7T8https://tomcat.apache.org/download-80.cgi

下载好后解压,放在D盘。


可以直接下载我的使用(配置好的settings.xml,在D盘的根目录即可,如果所放的位置不是D盘参考下面修改settings.xml修改一条信息):

包括.m2、maven、tomcat8.5.96(直接解压丢在D盘就可以)

全家桶什么都有了------>>>,直接放在D盘配置idle里的maven就可以了。

【超级会员V3】通过百度网盘分享的文件:配置把里边的放D…
链接:https://pan.baidu.com/s/1kKQ3Chl4n-lE7xC8QC87tA?pwd=ty32 
提取码:ty32
复制这段内容打开「百度网盘APP 即可获取」


配置maven


其中maven需要修改他的settings.xml

点进去

点进去


修改settings.xml


然后在maven里找到settings.xml,打开方式为记事本

<!-- 
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>
   -->
<localRepository>D:/.m2/repository</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>
<!--  TODO Since when can proxies be selected as depicted?  -->
<!--  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>nexus-aliyun</id>
<mirrorOf>central</mirrorOf>
<name>Nexus aliyun</name>
<url>http://maven.aliyun.com/nexus/content/groups/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 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 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>

其中下面代码是根据需要修改的,你的.m2放在哪就改成那个位置:

<localRepository>D:/.m2/repository</localRepository>

可以用CTRL  F快捷键找到这个代码的位置。上述修改,使用阿里云镜像,可以加快下载速度。

This XML file does not appear to have any style information associated with it. The document tree is shown below.

如果是有经验的人,之前有settings的模板,注意上边这个在settings里的一定要删掉

(第一行的)不然会严重报错


.m2是自己一般在C盘下:

自己电脑的用户下:

打开就可以找到得到的:

给他复制一下,放在D盘的根目录下。

如果首次使用idle可能没有,可以直接下载我的使用(配置好的settings.xml)。别忘了放在D的根目录里。

而tomcat不需要任何修改。


idle中配置maven


打开idle文件

选择关闭项目(没错就是关闭项目)

点击自定义中的所有设置

设置,中搜索maven

其中这三个是需要修改的。

第一个点击那三个点

找到你的maven位置即可,点击确认。

第二个第三个需要选中重写。

点击那个文件夹样式的图标,

这样选中,点击确认

D盘下的apache-maven-3.9.6里的conf文件夹中的settings.xml

第三个,D盘下的.m2文件夹中的repository

点击确认后点击应用(别点错了)

这样就配置好idle中的maven仓库了。


文件夹,新建项目

点击生成器中的Maven Archetype

名称(想一个简单的);位置(一般推荐直接放在D盘下)

jdk版本一般推荐1.8

这个Archetype要选,滑到最下边,一般就能找到这个后缀是webapp的东西了,这样选了就可以节省后面自己构建webapp,也可以避免相当多的错误

选择好后点击创建

有可能会弹出

点击自动就行,不弹出也没有任何问题。

慢慢等他下载框架就好了。

过程不要断网,不要暂停。等待下载结束。

下载结束后会是这个样子的webapp和其他的必须框架都有。

这样就完成了maven的部署了,新创项目时不需要再次配置idle中的maven。


如果你的C盘足够大的情况,不嫌弃外网下载速度慢,完全可以不下载maven的。选择这个maven框架,会默认给你再在C盘弄一个maven,其中下载的依赖都会放在主机用户名下的.m2文件下。

(若练此功必先自宫,若不自宫也可成功,哈哈哈……)

但是还是建议自己下载的,因为你能掌控他的版本和信息。


配置tomcat


点击编辑配置。

点击添加新的配置,往下滑,找到这个黄色的猫,点开点击本地。

默认出现下面的:

点击配置

 

上面两个都要找到。

找到你下载的tomcat即可:


部署


下面会飘红

点击修复,选第二个:

或者自己点部署

点加号,选第一个

然后选第二个

点击确定,然后点击应用。

点击运行

会自动蹦出来这个页面说明完成了

恭喜配置完成。


 tomcat需要自己下载,引到D盘下的,因为idle里的

这个样下载的tomcat版本一般比较低。8以上的版本不太适用(老师说的)

特别提醒如果:

HTTP状态 404 - 未找到


类型 状态报告

描述 源服务器未能找到目标资源的表示或者是不愿公开一个已经存在的资源表示。

一般是创建Maven的方式不太恰当


解决方法如下

采用下面这个webapp自动生成可以避免很多不必要的麻烦

正常的tomcat部署,应该是下面这样的war exploded

正常的pom文件是这样的:


tomcat中文乱码解决


在D盘tomcat里面找到logging.properties

用记事本的方式打开

java.util.logging.ConsoleHandler.encoding

ctrl F找到这个地方改为GBK

然后tomcat乱码日志乱码既可以解决了

猜你喜欢

转载自blog.csdn.net/m0_66722981/article/details/134939727