文章目录

  • maven功能
  • 配置maven
  • mvn compile 如下报错:
  • 解决方案:
  • 十分感谢坤爷帮助
  • 修改本地仓库
  • maven的配置文件
  • 修改local_repository指定你的目录(不要使用中文目录)
  • 仓库
  • 仓库的定义
  • 仓库的分类
  • 仓库的使用
  • IDEA中设置maven
  • 配置入口
  • maven项(配置当前工程的设置)
  • Maven/Runner
  • maven项(配置以后新建工程的设置)
  • 使用模版创建项目
  • 报错解决
  • 报错1
  • 报错2
  • 删除导入的jar包和modules


maven功能

  1. maven可以管理jar文件
  2. 自动下载jar和他的文档,源代码
  3. 管理jar直接的依赖, a.jar需要b.jar , maven会自动下载b.jar
  4. 管理你需要的jar版本
  5. 帮你编译程序,把java编译为class
  6. 帮你测试你的代码是否正确。
  7. 帮你打包文件,形成jar文件,或者war文件
  8. 帮你部署项目

配置maven

  1. 需要从maven的官网下载maven的安装包,我的版本是apache-maven-3.6.3
  2. 解压安装包,解压到一个目录,非中文目录
  3. 配置环境变量;在系统的环境变量中,指定一个M2_HOME的名称, 指定它的值是maven工具安装目录,bin之前的目录M2_HOME=D:\apache-maven-3.6.3-bin\apache-maven-3.6.3
  4. 再把M2_HOME加入到path之中,在所有路径之前加入 %M2_HOME%\bin;(注意:需要配置JAVA_HOME ,指定jdk路径)
  5. 验证,新的命令行中,执行mvn -v

maven添加Apache Commons CSV maven add library to classpath_java

tree +  文件

maven添加Apache Commons CSV maven add library to classpath_maven_02


maven添加Apache Commons CSV maven add library to classpath_maven_03

执行mvn compile ,结果是在项目的根目录下生成target目录(结果目录),maven编译的java程序,最后的class文件都放在target目录中

默认仓库:

C:\Users\ASUS\.m2\repository

maven添加Apache Commons CSV maven add library to classpath_maven_04


maven添加Apache Commons CSV maven add library to classpath_ide_05


注意,执行java命令,必须在相应的包名文件路径之前

mvn compile 如下报错:

maven添加Apache Commons CSV maven add library to classpath_ide_06

解决方案:

打开pom.xml的文件,在project标签中加上如下代码:

<properties>
  	<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
 	 <maven.compiler.source>10</maven.compiler.source>
 	 <maven.compiler.target>10</maven.compiler.target>
</properties>

这里的10需要换成对应jdk版本,直接java -version

maven添加Apache Commons CSV maven add library to classpath_ide_07


如下这种,把10全部换成1.8即可

十分感谢坤爷帮助

修改本地仓库

maven的配置文件

maven安装目录/conf/settings.xml,先备份

修改local_repository指定你的目录(不要使用中文目录)

把注释内标签移动到下面,修改标签内容即可

D:\apache-maven-3.6.3-bin\maven_repository

maven添加Apache Commons CSV maven add library to classpath_java_08

仓库

仓库的定义

  1. 存放maven使用的jar和我们项目使用的jar(maven使用的插件(各种jar);项目使用的jar(第三方工具))

仓库的分类

  1. 本地仓库:个人计算机上的文件夹,存放各种jar
  2. 远程仓库:在互联网上的,使用网络才能使用的仓库(中央仓库:最权威的, 所有的开发人员都共享使用的一个集中的仓库,https://repo.maven.apache.org;中央仓库的镜像:就是中央仓库的备份, 在各大洲,重要的城市都是镜像;私服,在公司内部,在局域网中使用的, 不是对外使用的。)

仓库的使用

maven仓库的使用不需要人为参与
开发人员需要使用mysql驱动—>maven首先查本地仓库—>私服—>镜像—>中央仓库

IDEA中设置maven

  1. 在idea中设置maven ,让idea和maven结合使用( idea中内置了maven ,一般不使用内置的, 因为用内置修改maven的设置不方便。)

配置入口

maven项(配置当前工程的设置)
  1. 配置的入口 ①:配置当前工程的设置,file--settings ---Build, Excution,Deployment--Build Tools --Maven 改之前:
  2. maven添加Apache Commons CSV maven add library to classpath_ide_09

Maven Home directory: maven的安装目录
  1. User Settings File : 就是maven安装目录conf/setting.xml配置文件
  2. Local Repository : 本机仓库的目录位置
    改之后:
  3. maven添加Apache Commons CSV maven add library to classpath_ide_10

Maven/Runner
  1. VM Options : archetypeCatalog=internal
  2. JRE: 你项目的jdk

maven项目创建时,会联网下载模版文件, 比较大, VM Options使用-DarchetypeCatalog=internal,不用下载, 创建maven项目速度快。(新版本的idea用-DarchetypeCatalog=internal,版本较低的用archetypeCatalog=internal

maven添加Apache Commons CSV maven add library to classpath_java_11

maven项(配置以后新建工程的设置)

配置以后新建工程的设置,file--other settings--Settings for New Project

使用模版创建项目

  1. maven-archetype-quickstart : 普通的java项目

maven添加Apache Commons CSV maven add library to classpath_ide_12

  1. maven-archetype-webapp : web工程

maven添加Apache Commons CSV maven add library to classpath_java_13


maven添加Apache Commons CSV maven add library to classpath_java_14


maven添加Apache Commons CSV maven add library to classpath_maven_15


然后点击Enable-Auto-Import

maven添加Apache Commons CSV maven add library to classpath_java_16

报错解决

报错1

maven添加Apache Commons CSV maven add library to classpath_java_17

maven添加Apache Commons CSV maven add library to classpath_ide_18


maven自动导入依赖失败

maven添加Apache Commons CSV maven add library to classpath_java_19


maven添加Apache Commons CSV maven add library to classpath_java_20

2 errors
	at com.google.inject.internal.Errors.throwCreationExceptionIfErrorsExist(Errors.java:543)
	at com.google.inject.internal.InternalInjectorCreator.initializeStatically(InternalInjectorCreator.java:159)
	at com.google.inject.internal.InternalInjectorCreator.build(InternalInjectorCreator.java:106)
	at com.google.inject.Guice.createInjector(Guice.java:87)
	at com.google.inject.Guice.createInjector(Guice.java:69)
	at com.google.inject.Guice.createInjector(Guice.java:59)
	at org.codehaus.plexus.DefaultPlexusContainer.addComponent(DefaultPlexusContainer.java:344)
	at org.codehaus.plexus.DefaultPlexusContainer.addComponent(DefaultPlexusContainer.java:332)
	at org.jetbrains.idea.maven.server.Maven3ServerEmbedderImpl.customizeComponents(Maven3ServerEmbedderImpl.java:557)
	at org.jetbrains.idea.maven.server.Maven3ServerEmbedderImpl.customize(Maven3ServerEmbedderImpl.java:527)
	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:346)
	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)
	at sun.rmi.transport.StreamRemoteCall.exceptionReceivedFromServer(StreamRemoteCall.java:276)
	at sun.rmi.transport.StreamRemoteCall.executeCall(StreamRemoteCall.java:253)
	at sun.rmi.server.UnicastRef.invoke(UnicastRef.java:162)
	at java.rmi.server.RemoteObjectInvocationHandler.invokeRemoteMethod(RemoteObjectInvocationHandler.java:227)
	at java.rmi.server.RemoteObjectInvocationHandler.invoke(RemoteObjectInvocationHandler.java:179)
	at com.sun.proxy.$Proxy198.customize(Unknown Source)
	at sun.reflect.GeneratedMethodAccessor1581.invoke(Unknown Source)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:498)
	at com.intellij.execution.rmi.RemoteUtil.invokeRemote(RemoteUtil.java:179)
	at com.intellij.execution.rmi.RemoteUtil.access$300(RemoteUtil.java:39)
	at com.intellij.execution.rmi.RemoteUtil$2$1$1.compute(RemoteUtil.java:160)
	at com.intellij.openapi.util.ClassLoaderUtil.runWithClassLoader(ClassLoaderUtil.java:66)
	at com.intellij.execution.rmi.RemoteUtil.executeWithClassLoader(RemoteUtil.java:231)
	at com.intellij.execution.rmi.RemoteUtil$2$1.invoke(RemoteUtil.java:157)
	at com.sun.proxy.$Proxy198.customize(Unknown Source)
	at org.jetbrains.idea.maven.server.MavenEmbedderWrapper.doCustomize(MavenEmbedderWrapper.java:96)
	at org.jetbrains.idea.maven.server.MavenEmbedderWrapper.lambda$customizeForResolve$1(MavenEmbedderWrapper.java:69)
	at org.jetbrains.idea.maven.server.RemoteObjectWrapper.perform(RemoteObjectWrapper.java:76)
	at org.jetbrains.idea.maven.server.MavenEmbedderWrapper.customizeForResolve(MavenEmbedderWrapper.java:68)
	at org.jetbrains.idea.maven.project.MavenProjectsTree.resolve(MavenProjectsTree.java:1264)
	at org.jetbrains.idea.maven.project.MavenProjectsProcessorResolvingTask.perform(MavenProjectsProcessorResolvingTask.java:45)
	at org.jetbrains.idea.maven.project.MavenProjectsProcessor.doProcessPendingTasks(MavenProjectsProcessor.java:134)
	at org.jetbrains.idea.maven.project.MavenProjectsProcessor.access$000(MavenProjectsProcessor.java:32)
	at org.jetbrains.idea.maven.project.MavenProjectsProcessor$2.run(MavenProjectsProcessor.java:109)
	at org.jetbrains.idea.maven.utils.MavenUtil.lambda$runInBackground$5(MavenUtil.java:451)
	at com.intellij.openapi.application.impl.ApplicationImpl$1.run(ApplicationImpl.java:314)
	at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
	at java.util.concurrent.FutureTask.run(FutureTask.java:266)
	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)
2021-06-10 22:17:13,176 [8188941]  ERROR -      #org.jetbrains.idea.maven - IntelliJ IDEA 2018.3.2  Build #IU-183.4886.37 
2021-06-10 22:17:13,176 [8188941]  ERROR -      #org.jetbrains.idea.maven - JDK: 1.8.0_152-release; VM: OpenJDK 64-Bit Server VM; Vendor: JetBrains s.r.o 
2021-06-10 22:17:13,176 [8188941]  ERROR -      #org.jetbrains.idea.maven - OS: Windows 10 
2021-06-10 22:19:58,325 [8354090]   INFO - ide.actions.ShowFilePathAction - 
Exit code 1

这个报错是属于maven版本问题,不兼容,回退到3.6.1重新安装配置问题解决

报错2

2019-09-24 15:54:53,177 [79997751]  ERROR -      #org.jetbrains.idea.maven - IntelliJ IDEA 2018.3  Build #IU-183.4284.148 
2019-09-24 15:54:53,177 [79997751]  ERROR -      #org.jetbrains.idea.maven - JDK: 1.8.0_152-release; VM: OpenJDK 64-Bit Server VM; Vendor: JetBrains s.r.o 
2019-09-24 15:54:53,177 [79997751]  ERROR -      #org.jetbrains.idea.maven - OS: Windows 10 
2019-09-24 15:54:54,060 [79998634]   INFO - .diagnostic.PerformanceWatcher - Reindexing refreshed files took 1279ms; general responsiveness: ok; EDT responsiveness: ok 
2019-09-24 15:54:54,187 [79998761]   INFO - g.FileBasedIndexProjectHandler - Reindexing refreshed files: 0 to update, calculated in 0ms 
2019-09-24 15:55:31,582 [80036156]  ERROR - .httpclient.HttpMethodDirector - Received redirect response 302 but no location header 
2019-09-24 16:02:39,691 [80464265]  ERROR - .httpclient.HttpMethodDirector - Received redirect response 302 but no location header 
2019-09-24 16:02:44,386 [80468960]  ERROR - .httpclient.HttpMethodDirector - Received redirect response 302 but no location header 
2019-09-24 16:03:24,203 [80508777]  ERROR - .httpclient.HttpMethodDirector - Received redirect response 302 but no location header 
2019-09-24 16:03:31,740 [80516314]  ERROR - .httpclient.HttpMethodDirector - Received redirect response 302 but no location header 
2019-09-24 16:05:31,587 [80636161]  ERROR - .httpclient.HttpMethodDirector - Received redirect response 302 but no location header 
2019-09-24 16:12:39,637 [81064211]  ERROR - .httpclient.HttpMethodDirector - Received redirect response 302 but no location header 
2019-09-24 16:12:44,454 [81069028]  ERROR - .httpclient.HttpMethodDirector - Received redirect response 302 but no location header 
2019-09-24 16:13:24,083 [81108657]  ERROR - .httpclient.HttpMethodDirector - Received redirect response 302 but no location header 
2019-09-24 16:13:31,845 [81116419]  ERROR - .httpclient.HttpMethodDirector - Received redirect response 302 but no location header 
2019-09-24 16:15:31,596 [81236170]  ERROR - .httpclient.HttpMethodDirector - Received redirect response 302 but no location header 
2019-09-24 16:22:39,644 [81664218]  ERROR - .httpclient.HttpMethodDirector - Received redirect response 302 but no location header 
2019-09-24 16:22:44,358 [81668932]  ERROR - .httpclient.HttpMethodDirector - Received redirect response 302 but no location header 
2019-09-24 16:23:24,097 [81708671]  ERROR - .httpclient.HttpMethodDirector - Received redirect response 302 but no location header 
2019-09-24 16:23:31,756 [81716330]  ERROR - .httpclient.HttpMethodDirector - Received redirect response 302 but no location header 
2019-09-24 16:24:34,611 [81779185]   INFO - atisticsWhiteListGroupsService - Request failed with status code 404 
com.intellij.util.io.HttpRequests$HttpStatusException: Request failed with status code 404. Status=404, Url=https://download.jetbrains.com/fus/whitelist/bear/groups/IU.json
	at com.intellij.util.io.HttpRequests.throwHttpStatusError(HttpRequests.java:643)
	at com.intellij.util.io.HttpRequests.openConnection(HttpRequests.java:624)
	at com.intellij.util.io.HttpRequests.access$300(HttpRequests.java:59)
	at com.intellij.util.io.HttpRequests$RequestImpl.getConnection(HttpRequests.java:378)
	at com.intellij.util.io.HttpRequests$RequestImpl.getInputStream(HttpRequests.java:387)
	at com.intellij.util.io.HttpRequests$RequestImpl.readString(HttpRequests.java:442)
	at com.intellij.util.io.RequestBuilder.lambda$readString$3(RequestBuilder.java:85)
	at com.intellij.util.io.HttpRequests.doProcess(HttpRequests.java:523)
	at com.intellij.util.io.HttpRequests.process(HttpRequests.java:499)
	at com.intellij.util.io.HttpRequests.access$100(HttpRequests.java:59)
	at com.intellij.util.io.HttpRequests$RequestBuilderImpl.connect(HttpRequests.java:352)
	at com.intellij.util.io.RequestBuilder.readString(RequestBuilder.java:85)
	at com.intellij.internal.statistic.service.fus.FUStatisticsWhiteListGroupsService.getApprovedGroups(FUStatisticsWhiteListGroupsService.java:46)
	at com.intellij.internal.statistic.service.fus.FUStatisticsSettingsService.getApprovedGroups(FUStatisticsSettingsService.java:43)
	at com.intellij.internal.statistic.service.fus.collectors.FUStatisticsPersistence.persistProjectUsages(FUStatisticsPersistence.java:49)
	at com.intellij.internal.statistic.updater.StatisticsJobsScheduler$2.lambda$projectOpened$0(StatisticsJobsScheduler.java:110)
	at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
	at java.util.concurrent.FutureTask.runAndReset(FutureTask.java:308)
	at com.intellij.util.concurrency.SchedulingWrapper$MyScheduledFutureTask.run(SchedulingWrapper.java:230)
	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)

修改 MAVEN的 Importing和Runner的JDK一致:

maven添加Apache Commons CSV maven add library to classpath_java_21


maven添加Apache Commons CSV maven add library to classpath_maven_22

删除导入的jar包和modules

右上角

maven添加Apache Commons CSV maven add library to classpath_maven_23


maven添加Apache Commons CSV maven add library to classpath_ide_24


maven添加Apache Commons CSV maven add library to classpath_java_25


点击减号即可