首页 > 解决方案 > Maven 无法创建本地存储库

问题描述

这是一个问题。我在 .m2 文件夹所在的 Windows 中重命名了我的用户文件夹。所以现在我在idea和eclipse中都遇到了这个错误:

[ERROR] Could not create local repository at C:\Users\Олег\.m2\repository -> [Help 1]
[ERROR] 
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR] 
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/LocalRepositoryNotAccessibleException

这是老路

C:\Users\Олег\.m2\repository

这是新的

C:\Users\Oleg\.m2\repository

我什么都试过了。删除行家。删除所有缓存文件夹。更改了 Maven 中设置文件中的路径。更改了idea和eclipse中插件的路径。重新安装idea和eclipse。

但我仍然无法运行任何 spring 应用程序我得到了这个错误:

java.lang.ClassNotFoundException:org.springframework.web.servlet.DispatcherServlet

或者当我在部署程序集中添加 Maven 依赖项时,我遇到了上面提到的错误。

也许有人遇到过这个问题。

谢谢

更新:我的错。我必须更好地解释。我以适当的方式更改了用户名。在管理员用户中并更改注册表和其他内容

pom.xml 文件

<?xml version="1.0" encoding="UTF-8"?>

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>

  <groupId>com.example</groupId>
  <artifactId>Websystems</artifactId>
  <version>0.0.1-SNAPSHOT</version>
  <packaging>war</packaging>

  <name>Websystems Maven Webapp</name>
  <!-- FIXME change it to the project's website -->
  <url>http://www.example.com</url>

  <properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <maven.compiler.source>1.7</maven.compiler.source>
    <maven.compiler.target>1.7</maven.compiler.target>
    <springCoreVersion>3.2.4.RELEASE</springCoreVersion>
  </properties>

  <dependencies>
    <!-- https://mvnrepository.com/artifact/org.springframework/spring-web -->
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-web</artifactId>
        <version>${springCoreVersion}</version>
    </dependency>
    <!-- https://mvnrepository.com/artifact/org.springframework/spring-webmvc -->
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-webmvc</artifactId>
        <version>${springCoreVersion}</version>
    </dependency>
    <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-context-support</artifactId>
            <version>${springCoreVersion}</version>
    </dependency>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-core</artifactId>
        <version>${springCoreVersion}</version>
    </dependency>
    <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-context</artifactId>
            <version>${springCoreVersion}</version>
                <exclusions>
                    <exclusion>
                        <groupId>commons-logging</groupId>
                        <artifactId>commons-logging</artifactId>
                    </exclusion>
                </exclusions>
    </dependency>
    <dependency>
        <groupId>javax.servlet</groupId>
        <artifactId>javax.servlet-api</artifactId>
        <version>4.0.0</version>
        <scope>provided</scope>
    </dependency>

    <dependency>
        <groupId>javax.servlet.jsp</groupId>    
        <artifactId>javax.servlet.jsp-api</artifactId>
        <version>2.3.1</version>
        <scope>provided</scope>
    </dependency>
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>4.11</version>
      <scope>test</scope>
    </dependency>
    <!-- https://mvnrepository.com/artifact/org.slf4j/jcl-over-slf4j -->
    <dependency>
        <groupId>org.slf4j</groupId>
        <artifactId>jcl-over-slf4j</artifactId>
        <version>1.7.21</version>
    </dependency>
    <!-- https://mvnrepository.com/artifact/ch.qos.logback/logback-classic -->
    <dependency>
        <groupId>ch.qos.logback</groupId>
        <artifactId>logback-classic</artifactId>
        <version>1.1.7</version>
        <scope>test</scope>
    </dependency>

  </dependencies>

  <build>
    <finalName>Websystems</finalName>
    <pluginManagement><!-- lock down plugins versions to avoid using Maven defaults (may be moved to parent pom) -->
      <plugins>
        <plugin>
          <artifactId>maven-clean-plugin</artifactId>
          <version>3.1.0</version>
        </plugin>
        <!-- see http://maven.apache.org/ref/current/maven-core/default-bindings.html#Plugin_bindings_for_war_packaging -->
        <plugin>
          <artifactId>maven-resources-plugin</artifactId>
          <version>3.0.2</version>
        </plugin>
        <plugin>
          <artifactId>maven-compiler-plugin</artifactId>
          <version>3.8.0</version>
        </plugin>
        <plugin>
          <artifactId>maven-surefire-plugin</artifactId>
          <version>2.22.1</version>
        </plugin>
        <plugin>
          <artifactId>maven-war-plugin</artifactId>
          <version>3.2.2</version>
        </plugin>
        <plugin>
          <artifactId>maven-install-plugin</artifactId>
          <version>2.5.2</version>
        </plugin>
        <plugin>
          <artifactId>maven-deploy-plugin</artifactId>
          <version>2.8.2</version>
        </plugin>
      </plugins>
    </pluginManagement>
  </build>
</project>

标签: javaspringmaven

解决方案


手动重命名您的用户文件夹(不重命名用户)我认为这是一个“大胆的想法”,但为了解决这个特定问题,我认为这(替代方案)可以提供帮助:

  1. %USERPROFILE%cmd中的“黑客” :

    SET USERPROFILE=C:\Users\Oleg
    

    在命令行中,在每次mvn调用之前。(需要在每个 new 上执行cmd,也可以通过 永久执行SETX,但可能会导致很多副作用。)

  2. 重命名您的用户...(更干净但可能导致次要问题...)

  3. 使用以下元素创建一个settings.xml文件:C:\Users\Олег\.m2

    <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
                  https://maven.apache.org/xsd/settings-1.0.0.xsd">
        <localRepository>C:\Users\Oleg\.m2\repository</localRepository>
    
        ...
     </settings>
    
  4. 备选方案 3. 也可以全局应用(相同的内容):在%MAVEN_HOME%/conf/settings.xml(这可能是对您来说最好和最少干扰的选择。)

  5. ..

如果这可以修复您的 Maven,我会很高兴,但我预见到“其他/更多问题”并强烈建议不要“破解(=手动重命名)您的用户目录”(在没有操作系统中)。


推荐阅读