Java、maven、tomcat、idea的安装、配置以及各种常见错误

本篇文章的适用人群:

初衷是给小白或刚入门的人员写的,有些常见的软件安装步骤省略了,还算比较全

一. java的下载、安装、配置和验证

1. 下载:

官网:https://www.oracle.com/java/technologies/downloads/

注:下载时如需要账号登陆,自行登录或注册后登录,然后下载

百度云:https://pan.baidu.com/share/init?surl=LGf3PodzAT1R-7ET1DEOdQ

提取码:s6mg

CSDN:

Java系列8u311
Java_8u311_windows

2. 安装

1. 点击“更改目录”,将安装目录设置在自己喜欢的地方(建议),或者直接点击下一步(此时默认装到C盘)

在这里插入图片描述

2. 这里选择安装:点击确定,会出现安装jre的提示,点击下一步即可

在这里插入图片描述
注:有时候装完JDK后会跳出安装JRE的窗口,可以直接关闭或安装,JRE若自定义安装,则要将JRE安装到一个空目录下,不然会报错
在这里插入图片描述

3. 点击关闭即可

在这里插入图片描述

3. 配置环境变量

1. 确定JDK和JRE的安装位置
2. 右键我的电脑,点击最下面的属性,之后在弹框里点击高级系统设置,再点击环境变量
3. 变量设置参数如下(用户变量、系统变量自己选):
  • 变量名:JAVA_HOME
    变量值:G:\code\path\java\ // 要根据自己的实际路径配置
  • 变量名:CLASSPATH
    变量值:.;%JAVA_HOME%\lib\dt.jar;%JAVA_HOME%\lib\tools.jar; //记得前面有个"."
  • 变量名:Path
    变量值:%JAVA_HOME%\bin;%JAVA_HOME%\jre\bin;

系统间不同的配置方法:

  1. win10的话直接新建后添加%JAVA_HOME%\bin和%JAVA_HOME%\jre\bin(win10末尾不用添加分号“;”)
  2. win7的话在末尾添加%JAVA_HOME%\bin;%JAVA_HOME%\jre\bin;若path变量最末尾的变量无分号,则添加;%JAVA_HOME%\bin;%JAVA_HOME%\jre\bin;
4. 使用快捷键,(win+r),输入cmd按Enter键
  1. 输入 java ,按Enter键,查看java运行环境是否正常,出现下面的信息则配置成功。
    在这里插入图片描述

  2. 输入java -version,按Enter键可查看当前安装的的jdk版本。
    在这里插入图片描述

  3. 输入javac,按Enter键,查看java编译环境是否正常。出现下面的信息则配置成功。
    在这里插入图片描述

Java的众多问题

1. java不是内部命令,javac不是内部命令报错的解决办法

重新配置Path, JAVA_HOME, CLASSPATH 的环境变量
(这三个环境,其中一个出错,都会产生上面的报错,不行就多复制粘贴几次)

变量设置参数如下:

变量名:JAVA_HOME
变量值:G:\code\path\java\ // 要根据自己的实际路径配置
变量名:CLASSPATH
变量值:.;%JAVA_HOME%\lib\dt.jar;%JAVA_HOME%\lib\tools.jar; //记得前面有个"."
变量名:Path

变量值:%JAVA_HOME%\bin;%JAVA_HOME%\jre\bin;

(注:在重新配置完这三个环境变量后,将前面窗口都点击确定,然后一定要等待10s左右后,再

重新打开dos窗口输入java, java -version, javac这三个命令,不然环境变量配置正确了,也可能报错)

若多次重新配置Path, JAVA_HOME, CLASSPATH 的环境变量仍然不行,,将这些变量值 ”\“ 前面的部分改成绝对地址

(注: 在配置java环境时,我还遇到过一个比较少见的BUG。因为JDK中已经包含了JRE,在同时安装JDK和JRE时,配置环境变量时这两个JRE有可能会冲突,此时,将Path中有关JRE环境配置的删去,等待10s后去命令行验证即可。即:若在安装JDK时安装了JRE,则可以不在Path中配置JRE的环境变量,若冲突,则去掉JRE的环境变量)

2. jdk1.8以上的版本(jdk9,jdk11,jdk17等)没有jre的问题
前提条件

已经设置完毕了jdk运行的环境,java、javac相关的命令已经是可用状态。

解决问题
  1. 打开windows的命令行工具
    打开Windows powerShell(管理员),切记是管理员权限的 Windows powerShell ,这一步很重要!

  2. 进入jdk安装目录
    执行 :

cd "C:\Program Files\Java\jdk-17"
  1. 本篇针对的版本是17,自己可以根据jdk安装路径进入对应的安装目录
    生成所需的jre
    执行命令:
bin\jlink.exe --module-path jmods --add-modules java.desktop --output jre
可能的问题

有的小伙伴执行完:C:\Program Files\Java\jdk-17>bin\jlink.exe --module-path jmods --add-modules java.desktop --output jre

出现错误提示:错误: C:\Program Files\Java\jdk-17\jre

原因是:Windows powerShell 并没有使用管理员身份打开。

二、 maven的下载和配置

1. 下载

Maven版本历史页:http://maven.apache.org/docs/history.html
Maven3的集合页:https://archive.apache.org/dist/maven/maven-3/

这里下载的版本:

3.8.7版本

下载完成后,我们在某个盘(例如D盘)的根目录(随便什么目录都行,但要注意路径最好不要出现中文或者空格),新建一个名为maven的文件夹,然后把压缩包解压后的文件夹放在里面,我们还要新建一个maven本地仓库文件夹,名字随便但是一般叫做repository即可(代表仓库的意思)。以上文件夹绝对路径保持全是英文名,文件夹名称不要为中文,例如E:\maven\repository。综上所述,目录结构可参考如下:

D:
├─maven
    ├─apache-maven-3.8.7
    └─repository

在这里插入图片描述

2. 修改Maven配置文件settings.xml

1. 配置maven镜像源(下载专用)
简介❓(是什么、为什么)

这一步是配置maven中央仓库的位置,也就是要去哪里下载项目依赖的本地没有的jar包,我们需要改成阿里云的镜像,因为默认maven中央仓库的服务器在国外,下载依赖的速度会比较慢,改成阿里云镜像速度会很快。

步骤❗(怎么做)

首先在maven文件夹的conf目录下找到settings.xml👈,用vscode等编辑器打开,定位到159-165行左右(不同版本行数可能会有出入,以实际行数为准)
在这里插入图片描述
在这里插入图片描述
将红色框框的这一段代码:

<mirror>
  <id>maven-default-http-blocker</id>
  <mirrorOf>external:http:*</mirrorOf>
  <name>Pseudo repository to mirror external repositories initially using HTTP.</name>
  <url>http://0.0.0.0/</url>
  <blocked>true</blocked>
</mirror>

替换为以下代码,保存即可,这里要注意❗标签有没有闭合,不要弄混mirrors和mirror标签

<mirror>
  <id>aliyunmaven</id>
  <mirrorOf>*</mirrorOf>
  <name>阿里云公共仓库</name>
  <url>https://maven.aliyun.com/repository/public</url>
</mirror>

注:此段配置来源于阿里云官方指南 https://developer.aliyun.com/mvn/guide
在这里插入图片描述
修改后的代码:
在这里插入图片描述

2. 配置maven本地库

本地仓库就是我们自己新建的一个文件夹,所有从中央仓库下载的jar包会放在这里面
在这里插入图片描述
在下方增加这段配置即可

<localRepository>D:\maven\repository</localRepository>

在这里插入图片描述
下载完成解压,改本地仓库和远程仓库即可
建议使用新阿里云仓库:

<!-- 阿里云仓库 -->
    <mirror>  
      <id>alimaven</id>  
      <name>aliyun maven</name>  
      <url>https://maven.aliyun.com/nexus/content/groups/public/</url>  
      <mirrorOf>central</mirrorOf>          
    </mirror>  

这里分享一下个人的settings.xml配置文件

<?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.0.0"
          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
          xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.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:/Java/MavenRepository</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>alimaven</id>  
      <name>aliyun maven</name>  
      <url>https://maven.aliyun.com/nexus/content/groups/public/</url>  
      <mirrorOf>central</mirrorOf>          
    </mirror>  
    <mirror>
      <id>alimaven</id>
      <mirrorOf>central</mirrorOf>
      <name>aliyun maven</name>
      <url>http://maven.aliyun.com/nexus/content/repositories/central/</url>
    </mirror>
	
  <!-- maven运营的中央仓库2 -->
    <mirror>
     <id>repo2</id>
     <mirrorOf>central</mirrorOf>
     <name>Human Readable Name for this Mirror.</name>
     <url>http://repo2.maven.org/maven2/</url>
    </mirror>
     
	<!-- maven在UK架设的仓库(有时候速度会比官方2号仓库快) -->
	<mirror> 
		<id>ui</id> 
		<name>Mirror from UK</name> 
		<url>http://uk.maven.org/maven2/</url> 
		<mirrorOf>central</mirrorOf> 
	</mirror> 
	
	<!-- JBoss的仓库 -->
	<mirror> 
		<id>jboss-public-repository-group</id> 
		<mirrorOf>central</mirrorOf> 
		<name>JBoss Public Repository Group</name> 
		<url>http://repository.jboss.org/nexus/content/groups/public</url> 
	</mirror> 
	
	<mirror>    
      <id>ibiblio</id>    
      <mirrorOf>central</mirrorOf>    
      <name>Human Readable Name for this Mirror.</name>    
      <url>http://mirrors.ibiblio.org/pub/mirrors/maven2/</url>    
    </mirror>  
	
	<!-- maven运营的中央仓库1 -->
     <mirror>
     <id>repo1</id>
     <mirrorOf>central</mirrorOf>
     <name>Human Readable Name for this Mirror.</name>
     <url>http://repo1.maven.org/maven2/</url>
    </mirror>

  
    <mirror>    
      <id>CN</id>  
      <name>OSChina Central</name>         
      <url>http://maven.oschina.net/content/groups/public/</url>  
      <mirrorOf>central</mirrorOf>    
    </mirror>
   
   <mirror>    
      <id>net-cn</id>    
      <mirrorOf>central</mirrorOf>    
      <name>Human Readable Name for this Mirror.</name>    
      <url>http://maven.net.cn/content/groups/public/</url>     
    </mirror> 
	
   
	
<mirror>
        <id>aliyun-central</id>
        <mirrorOf>*</mirrorOf>
        <name>aliyun central</name>
        <url>https://maven.aliyun.com/repository/central</url>
    </mirror>

    <mirror>
        <id>aliyun-spring</id>
        <mirrorOf>*</mirrorOf>
        <name>aliyun spring</name>
        <url>https://maven.aliyun.com/repository/spring</url>
    </mirror>

    <mirror>
        <id>aliyun-spring-plugin</id>
        <mirrorOf>*</mirrorOf>
        <name>aliyun spring-plugin</name>
        <url>https://maven.aliyun.com/repository/spring-plugin</url>
    </mirror>

    <mirror>
        <id>aliyun-apache-snapshots</id>
        <mirrorOf>*</mirrorOf>
        <name>aliyun apache-snapshots</name>
        <url>https://maven.aliyun.com/repository/apache-snapshots</url>
    </mirror>

    <mirror>
        <id>aliyun-google</id>
        <mirrorOf>*</mirrorOf>
        <name>aliyun google</name>
        <url>https://maven.aliyun.com/repository/google</url>
    </mirror>

    <mirror>
        <id>aliyun-gradle-plugin</id>
        <mirrorOf>*</mirrorOf>
        <name>aliyun gradle-plugin</name>
        <url>https://maven.aliyun.com/repository/gradle-plugin</url>
    </mirror>

    <mirror>
        <id>aliyun-jcenter</id>
        <mirrorOf>*</mirrorOf>
        <name>aliyun jcenter</name>
        <url>https://maven.aliyun.com/repository/jcenter</url>
    </mirror>

    <mirror>
        <id>aliyun-releases</id>
        <mirrorOf>*</mirrorOf>
        <name>aliyun releases</name>
        <url>https://maven.aliyun.com/repository/releases</url>
    </mirror>

    <mirror>
        <id>aliyun-snapshots</id>
        <mirrorOf>*</mirrorOf>
        <name>aliyun snapshots</name>
        <url>https://maven.aliyun.com/repository/snapshots</url>
    </mirror>

    <mirror>
        <id>aliyun-grails-core</id>
        <mirrorOf>*</mirrorOf>
        <name>aliyun grails-core</name>
        <url>https://maven.aliyun.com/repository/grails-core</url>
    </mirror>

    <mirror>
        <id>aliyun-mapr-public</id>
        <mirrorOf>*</mirrorOf>
        <name>aliyun mapr-public</name>
        <url>https://maven.aliyun.com/repository/mapr-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>
      <id>jdk-1.8</id> 
      <activation>
	    <activeByDefault>true</activeByDefault> 
      	    <jdk>1.8</jdk>
      </activation>
 
      <properties>    
    	<maven.compiler.source>1.8</maven.compiler.source>    
    	<maven.compiler.target>1.8</maven.compiler.target>    
    	<maven.compiler.compilerVersion>1.8</maven.compiler.compilerVersion> 
	<encoding>UTF-8</encoding>   
      </properties> 
    </profile>

    <!-- 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>

三 、tomcat的下载、配置

一、下载、解压安装包

已安装了1.8版本的JDK, 对应的是Java 8, 所以下载tomcat 9即可

tomcat版本支持java版本
https://tomcat.apache.org/whichversion.html
在这里插入图片描述
下载地址:https://tomcat.apache.org/download-90.cgi
在这里插入图片描述
下载后,解压到指定目录。

二、环境变量配置(选择性配置)

“桌面” -> “此电脑” -> “高级系统设置” -> “环境变量”
变量值是解压解压安装包根目录,根目录文件夹里就是bin、lib、conf等文件

  • 系统变量 CATALINA_BASE
    变量名:CATALINA_BASE
    变量值:C:\Program Files\apache-tomcat-9.0.62-windows-x64\apache-tomcat-9.0.62
  • 系统变量 CATALINA_HOME
    变量名:CATALINA_HOME
    变量值:C:\Program Files\apache-tomcat-9.0.62-windows-x64\apache-tomcat-9.0.62
  • 系统变量 编辑Path值(新建Path的两个值)
    • %CATALINA_HOME%\lib
    • %CATALINA_HOME%\bin

三 、 启动Tomcat(选择性测试,一般官方下载的都没问题)

1. 先检查8080端口是否被占用(CMD以管理员运行)

查看特定端口号占用进程

  1. 查询端口号占用的进程: 查询端口号:8080

    netstat -ano | findstr 8080
    
  2. 查询进程: 查询进程id:12504

    tasklist | findstr 12504
    
  3. 强制关闭进程:taskkill /pid 12504 /f

    在这里插入图片描述

  4. 目录来到tomcat的bin目录

2. tomcat启动和停止

如果CMD未使用管理员身份运行,可能会出现异常闪退

启动:startup.bat

停止: shutdown.bat 或 关闭startup.bat运行的窗口

浏览器访问:http://localhost:8080/

在这里插入图片描述
至此Tomcat启动成功

3. tomcat启动后,日志乱码问题

在这里插入图片描述

打开tomcat根目录 -> conf -> logging.properties

java.util.logging.ConsoleHandler.encoding 的值 UTF-8 修改成 GBK

 java.util.logging.ConsoleHandler.encoding = GBK

重启tomcat服务即可

三 、Tomcat目录结构

在这里插入图片描述

四 、 idea下载、安装

一. idea的下载

IDEA官网中文版:IntelliJ IDEA
其他版本:https://www.jetbrains.com/zh-cn/idea/download/other.html
在这里插入图片描述

下载社区版,社区版是免费的,相比于收费版少了些功能,不过日常开发也够用了
注:版本、系统等根据自己喜好自行下载

二 、 idea的安装

1. 点击Browse可选择自定义目录,最好自定义目录,默认安装目录C:\Program Files\JetBrains\IntelliJ IDEA 2020.3.3,博主自定义了一个IDEA文件夹。

在这里插入图片描述

2. 默认什么都不选,点击Next下一步。(可以根据自己的需求酌情选择)

在这里插入图片描述

三 、 idea的初次使用

1. 默认选择OK就好

在这里插入图片描述
在这里插入图片描述

2. 接着上面的选择Evaluate for free,然后选择Evaluate

在这里插入图片描述

3. 之后就随便创建一个项目,点击New Project。

在这里插入图片描述

4. 选择建个maven项目,然后选择Next

在这里插入图片描述

5. 直接Finish就好。

在这里插入图片描述

五 、 idea的配置

一 、 maven配置

1. 打开设置找到Maven,设置Maven主路径、用户设置文件、本地仓库的地址:

在这里插入图片描述

细节注意

修改完成后记得点击应用(Apply) 或者 确定(OK),不要直接右上角关闭了
在这里插入图片描述

2. 配置运行程序虚拟机参数
简介❓(为什么要配置,了解即可)

然后还有一个问题,使用IDEA创建maven项目时,idea会根据maven archetype的配置,执行 mvn archetype:generate 命令,并且需要指定一个archetype-catalog.xml文件。

该命令的参数-DarchetypeCatalog,可选值为[remote, internal, local],用来指定archetype-catalog.xml文件从哪里获取。

默认为remote,即从 https://repo1.maven.org/maven2/archetype-catalog.xml 下载archetype-catalog.xml文件。体积约为10M,就会导致下载速度很慢,从而创建过程经常会被卡住。

步骤❗(怎么做)

这里解决的方法一般有三种,感兴趣的可以从其他博客了解,这里我只选择最方便快捷一劳永逸的一种👈,就是修改maven的VM Options参数配置。

-DarchetypeCatalog=internal

在这里插入图片描述
修改完记得点击应用(Apply) 或者 确定(OK)

3. 重启IDEA

点击确定或应用,然后关闭IDEA
重新打开IDEA,查看刚刚的设置有没有生效❗
如果刚刚的设置又变回默认设置了,就再配一次,直到重启打开设置生效
IDEA高版本经常出现此类问题,如果不行重试几次即可。

二 、 配置Tomcat

1. 添加tomcat

在这里插入图片描述

2. 点击Edit Configurations后打开如下界面

在这里插入图片描述

3. 点击加号

在这里插入图片描述

4. 点击configuration,点击+号,在接下来的Tomcat Home: 中选择自己的tomcat目录

在这里插入图片描述
在这里插入图片描述

5. 配置JRE环境(选择真实的JDK环境)、tomcat端口号(也可以默认)、默认浏览器(url可以默认 http://localhost:8080/)

在这里插入图片描述

六 、idea的错误

一、 idea因为版本问题产生的错误Process terminated

错误信息:
SLF4J: Failed to load classorg.slf4j.impl.StaticLoggerBinder. SLF4J: Defaulting to no-operation (NOP) logger implementation SLF4J: See 		http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.
解决办法:

idea和maven之间的适配(兼容)问题

​注意:针对一些老项目 还是尽量采用 3.6.3版本,针对idea各个版本的兼容性就很兼容​​

​ ​0.IDEA 2022 兼容maven 3.8.1及之前的所用版本
​​
​ ​1.IDEA 2021 兼容maven 3.8.1及之前的所用版本​​

​ ​2.IDEA 2020 兼容Maven 3.6.3及之前所有版本​​

​ ​3.IDEA 2018 兼容Maven3.6.1及之前所有版本​

二 、 IDEA中的Tomcat服务器控制台乱码

问题描述:

当我们使用idea部署web程序到tomcat服务器上,当我们运行tomcat时控制台出现服务器输出内容乱码的情况,这个问题可能是由于编码不一致引起的。在IDEA中,如果项目的编码方式与Tomcat服务器的编码方式不一致,就可能出现服务器输出内容乱码的情况。

这个问题可能会给开发和调试带来不便,因为输出的乱码很难读懂,无法直观地了解服务器的运行情况。同时,如果乱码问题未能及时处理,就可能会对系统的正常运行产生影响,从而增加开发和维护的难度。

解决方法;

我们可以通过修改idea 的相关配置来解决。

设置项目编码方式:在IDEA中,可以在项目的设置中设置编码方式,保证与Tomcat服务器的编码方式一致。

设置Tomcat编码方式:在Tomcat的配置文件中,也可以设置服务器的编码方式,保证与项目的编码方式一致。

修改IDEA控制台编码方式:如果以上两个方法无法解决问题,可以尝试修改IDEA控制台的编码方式,使其能够正确地显示服务器输出的内容。

修改输出内容编码方式:如果服务器输出的内容是乱码,可以尝试修改输出内容的编码方式,将其转换为正确的编码方式。

1. 修改 Settings -->Editor 里面的编码方式为utf-8

在这里插入图片描述

在这里插入图片描述
在这里插入图片描述

2. 修改 VM 虚拟机配置

具体步骤 如下: 在 idea64.exe.vmoptions 下添加-Dfile.encoding=UTF-8
在这里插入图片描述

在这里插入图片描述

3. 将-Dfile.encoding=UTF-8添加到tomcat服务器VM配置中

在这里插入图片描述
在这里插入图片描述
注意: 在以上所有步骤中 记得先点击 Apply(应用) ,然后点击 OK(确定) 保存你的配置

三 、 IDEA 2021 整合 SSM 配置离线 Maven 3.8.1 报错大全 Since Maven 3.8.1 http repositories are blocked.

在这里插入图片描述

核心配置
<localRepository>D:\Java\MavenRepository</localRepository>
问题:如何才能在无网络环境下开发呢?
  1. 设置好maven的本地仓库地址

  2. 把镜像地址也指向本地的maven仓库地址

    修改好之后的setting.xml文件如下(主要配置是加上下面加粗字体部分):

    <?xml version="1.0" encoding="UTF-8"?>
    <settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
          xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd"
    
    <mirrors>
    <mirror>
        	<id>central</id>
        	<name>central</name>
        	<url>file://E:\wokesoftware\maven-repository</url>
        	<mirrorOf>*</mirrorOf>
    	</mirror>
    </mirrors>
    

备注 jar 包来源,拷贝同事的老项目jar 包 ,自定义 依赖 ,一直不能导入 jar包,研究了一早上,得到最终方案~~

免费送上一份 maven 3.8 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 http://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:\Java\MavenRepository</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>maven-default-http-blocker</id>
      <mirrorOf>external:http:*</mirrorOf>
      <name>Pseudo repository to mirror external repositories initially using HTTP.</name>
      <url>http://0.0.0.0/</url>
      <blocked>true</blocked>
    </mirror>


      <mirror>
          <id>central</id>
          <name>central</name>
          <url>file://D:\Java\MavenRepository</url>
          <mirrorOf>*</mirrorOf>
      </mirror>

      <mirror>
          <id>alimaven</id>
          <name>aliyun maven</name>
          <url>https://maven.aliyun.com/nexus/content/groups/public/</url>
          <mirrorOf>*</mirrorOf>
      </mirror>
      <mirror>
          <id>alimaven</id>
          <mirrorOf>*</mirrorOf>
          <name>aliyun maven</name>
          <url>http://maven.aliyun.com/nexus/content/repositories/central/</url>
      </mirror>

   
   <mirror>
       <id>aliyun-central</id>
       <mirrorOf>*</mirrorOf>
       <name>aliyun central</name>
       <url>https://maven.aliyun.com/repository/central</url>
   </mirror>

 
 <mirror>
            <id>alimaven</id>
            <name>aliyun maven</name>
            <url>http://maven.aliyun.com/nexus/content/groups/public/</url>
            <mirrorOf>central</mirrorOf>
        </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>
        <id>nexusProfile</id>
        <repositories>
            <repository>
                <id>nccloud-snapshots</id>
                <name>nccloud Snapshots Repository</name>
                <url>http://maven.yonyou.com/nexus/content/repositories/nccloud-snapshots/</url>
                <releases>
                    <enabled>true</enabled>
                </releases>
                <snapshots>
                    <enabled>true</enabled>
                </snapshots>
            </repository>
        </repositories>
    </profile>






    <!-- 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>
<activeProfile>nexusProfile</activeProfile>
</activeProfiles>
  <!-- activeProfiles
   | List of profiles that are active for all builds.
   |
  <activeProfiles>
    <activeProfile>alwaysActiveProfile</activeProfile>
    <activeProfile>anotherAlwaysActiveProfile</activeProfile>
  </activeProfiles>
  -->
</settings>

七 、 问题排查

Q:为什么我看了博主的教程还是不行

A:也许你没有完全仔细认真按照我的教程一步步配置,如果按我的教程配置的话,是100%成功的,再仔细检查看看是哪一步出了错误。如果已经新建了项目,则退出项目,把上述流程再仔仔细细重新走一遍,然后重新创建一个新项目测试效果。这里我也给出几种新手常见的错误操作:

  1. 白嫖文章,没有给博主点赞收藏加关注🚫😫
  2. IDEA版本低于最高支持的Maven版本,2021最好选择3.6.3稳定版,2022可以选择3.8.7版本
  3. 进行全局配置maven的时候没有退出到欢迎界面,这一步非常重要,不然你配置的就只是针对这个项目的
  4. 忘记配置vm选项 -DarchetypeCatalog=internal 或者重启IDEA之后检查设置的时候遗漏了,请多仔细检查,
  5. IDEA就是这么蛋疼,有时候明明配置了重启后又发现没配置
  6. 在已有的项目中测试失败了,改好配置后没有新建一个项目测试而是继续在这个项目测试效果

八 、本篇文章没有涉及到自己遇到的问题?

欢迎评论底下留言或私信博主,博主有时间帮你解决、共同解决或自己去查相关资料

  • 2
    点赞
  • 12
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

坦笑&&life

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值