14

I have a dynamic web project in SpringToolSuite. It is converted into a Maven project.

I am getting the issue:

Mising artifact org.springframework:spring.jar:4.2.6

I already tried to clean, rebuild and run the project. It gives:

Error reading file C:\Users\jublikon.m2\repository\org\springframework\spring\4.2.6\spring-4.2.6.jar C:\Users\jublikon.m2\repository\org\springframework\spring\4.2.6\spring-4.2.6.jar (The system cannot find the specified file)

I do not understand why it is asking for jar files while I am using Maven?

pom.xml

    <?xml version="1.0"?>
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <modelVersion>4.0.0</modelVersion>
  <groupId>HelloWeb</groupId>
  <artifactId>HelloWeb</artifactId>
  <version>0.0.1-SNAPSHOT</version>
  <packaging>war</packaging>
  <dependencies>
    <dependency>
      <groupId>org.springframework</groupId>
      <artifactId>spring-context</artifactId>
      <scope>compile</scope>
    </dependency>
    <dependency>
      <groupId>org.springframework</groupId>
      <artifactId>spring-core</artifactId>
      <scope>compile</scope>
    </dependency>
    <dependency>
      <groupId>org.springframework</groupId>
      <artifactId>spring-web</artifactId>
      <scope>compile</scope>
    </dependency>
    <dependency>
      <groupId>org.springframework</groupId>
      <artifactId>spring-webmvc</artifactId>
      <scope>compile</scope>
    </dependency>
    <dependency>
      <groupId>org.springframework</groupId>
      <artifactId>spring-aspects</artifactId>
      <scope>compile</scope>
    </dependency>
  </dependencies>
  <repositories>
    <repository>
      <snapshots>
        <enabled>false</enabled>
      </snapshots>
      <id>central</id>
      <name>Central Repository</name>
      <url>https://repo.maven.apache.org/maven2</url>
    </repository>
  </repositories>
  <pluginRepositories>
    <pluginRepository>
      <releases>
        <updatePolicy>never</updatePolicy>
      </releases>
      <snapshots>
        <enabled>false</enabled>
      </snapshots>
      <id>central</id>
      <name>Central Repository</name>
      <url>https://repo.maven.apache.org/maven2</url>
    </pluginRepository>
  </pluginRepositories>
  <build>
    <sourceDirectory>C:\Users\name\Development\Spring\Projects\HelloWeb\src\main\java</sourceDirectory>
    <scriptSourceDirectory>C:\Users\name\Development\Spring\Projects\HelloWeb\src\main\scripts</scriptSourceDirectory>
    <testSourceDirectory>C:\Users\name\Development\Spring\Projects\HelloWeb\src\test\java</testSourceDirectory>
    <outputDirectory>C:\Users\name\Development\Spring\Projects\HelloWeb\target\classes</outputDirectory>
    <testOutputDirectory>C:\Users\jublikon\Development\Spring\Projects\HelloWeb\target\test-classes</testOutputDirectory>
    <resources>
      <resource>
        <directory>C:\Users\jublikon\Development\Spring\Projects\HelloWeb\src\main\resources</directory>
      </resource>
    </resources>
    <testResources>
      <testResource>
        <directory>C:\Users\jublikon\Development\Spring\Projects\HelloWeb\src\test\resources</directory>
      </testResource>
    </testResources>
    <directory>C:\Users\jublikon\Development\Spring\Projects\HelloWeb\target</directory>
    <finalName>HelloWeb-0.0.1-SNAPSHOT</finalName>
    <pluginManagement>
      <plugins>
        <plugin>
          <artifactId>maven-antrun-plugin</artifactId>
          <version>1.3</version>
        </plugin>
        <plugin>
          <artifactId>maven-assembly-plugin</artifactId>
          <version>2.2-beta-5</version>
        </plugin>
        <plugin>
          <artifactId>maven-dependency-plugin</artifactId>
          <version>2.8</version>
        </plugin>
        <plugin>
          <artifactId>maven-release-plugin</artifactId>
          <version>2.3.2</version>
        </plugin>
      </plugins>
    </pluginManagement>
    <plugins>
      <plugin>
        <artifactId>maven-compiler-plugin</artifactId>
        <version>3.3</version>
        <executions>
          <execution>
            <id>default-compile</id>
            <phase>compile</phase>
            <goals>
              <goal>compile</goal>
            </goals>
            <configuration>
              <source>1.8</source>
              <target>1.8</target>
            </configuration>
          </execution>
          <execution>
            <id>default-testCompile</id>
            <phase>test-compile</phase>
            <goals>
              <goal>testCompile</goal>
            </goals>
            <configuration>
              <source>1.8</source>
              <target>1.8</target>
            </configuration>
          </execution>
        </executions>
        <configuration>
          <source>1.8</source>
          <target>1.8</target>
        </configuration>
      </plugin>
      <plugin>
        <artifactId>maven-war-plugin</artifactId>
        <version>2.6</version>
        <executions>
          <execution>
            <id>default-war</id>
            <phase>package</phase>
            <goals>
              <goal>war</goal>
            </goals>
            <configuration>
              <warSourceDirectory>WebContent</warSourceDirectory>
              <failOnMissingWebXml>false</failOnMissingWebXml>
            </configuration>
          </execution>
        </executions>
        <configuration>
          <warSourceDirectory>WebContent</warSourceDirectory>
          <failOnMissingWebXml>false</failOnMissingWebXml>
        </configuration>
      </plugin>
      <plugin>
        <artifactId>maven-clean-plugin</artifactId>
        <version>2.5</version>
        <executions>
          <execution>
            <id>default-clean</id>
            <phase>clean</phase>
            <goals>
              <goal>clean</goal>
            </goals>
          </execution>
        </executions>
      </plugin>
      <plugin>
        <artifactId>maven-resources-plugin</artifactId>
        <version>2.6</version>
        <executions>
          <execution>
            <id>default-testResources</id>
            <phase>process-test-resources</phase>
            <goals>
              <goal>testResources</goal>
            </goals>
          </execution>
          <execution>
            <id>default-resources</id>
            <phase>process-resources</phase>
            <goals>
              <goal>resources</goal>
            </goals>
          </execution>
        </executions>
      </plugin>
      <plugin>
        <artifactId>maven-surefire-plugin</artifactId>
        <version>2.12.4</version>
        <executions>
          <execution>
            <id>default-test</id>
            <phase>test</phase>
            <goals>
              <goal>test</goal>
            </goals>
          </execution>
        </executions>
      </plugin>
      <plugin>
        <artifactId>maven-install-plugin</artifactId>
        <version>2.4</version>
        <executions>
          <execution>
            <id>default-install</id>
            <phase>install</phase>
            <goals>
              <goal>install</goal>
            </goals>
          </execution>
        </executions>
      </plugin>
      <plugin>
        <artifactId>maven-deploy-plugin</artifactId>
        <version>2.7</version>
        <executions>
          <execution>
            <id>default-deploy</id>
            <phase>deploy</phase>
            <goals>
              <goal>deploy</goal>
            </goals>
          </execution>
        </executions>
      </plugin>
      <plugin>
        <artifactId>maven-site-plugin</artifactId>
        <version>3.3</version>
        <executions>
          <execution>
            <id>default-site</id>
            <phase>site</phase>
            <goals>
              <goal>site</goal>
            </goals>
            <configuration>
              <outputDirectory>C:\Users\jublikon\Development\Spring\Projects\HelloWeb\target\site</outputDirectory>
              <reportPlugins>
                <reportPlugin>
                  <groupId>org.apache.maven.plugins</groupId>
                  <artifactId>maven-project-info-reports-plugin</artifactId>
                </reportPlugin>
              </reportPlugins>
            </configuration>
          </execution>
          <execution>
            <id>default-deploy</id>
            <phase>site-deploy</phase>
            <goals>
              <goal>deploy</goal>
            </goals>
            <configuration>
              <outputDirectory>C:\Users\jublikon\Development\Spring\Projects\HelloWeb\target\site</outputDirectory>
              <reportPlugins>
                <reportPlugin>
                  <groupId>org.apache.maven.plugins</groupId>
                  <artifactId>maven-project-info-reports-plugin</artifactId>
                </reportPlugin>
              </reportPlugins>
            </configuration>
          </execution>
        </executions>
        <configuration>
          <outputDirectory>C:\Users\jublikon\Development\Spring\Projects\HelloWeb\target\site</outputDirectory>
          <reportPlugins>
            <reportPlugin>
              <groupId>org.apache.maven.plugins</groupId>
              <artifactId>maven-project-info-reports-plugin</artifactId>
            </reportPlugin>
          </reportPlugins>
        </configuration>
      </plugin>
    </plugins>
  </build>
  <reporting>
    <outputDirectory>C:\Users\jublikon\Development\Spring\Projects\HelloWeb\target\site</outputDirectory>
  </reporting>
</project>

I have already seen this post but somehow I am not able to solve my problem.

enter image description here

When I execute

mvn clean install

in the root directory of the project I get:

>mvn clean install
[INFO] Scanning for projects...
Downloading: https://repo.maven.apache.org/maven2/org/springframework/spring-framework-bom/$%7Bspring.version%7D/spring-framework-bom-$%7Bspring.version%7D.pom
[ERROR] [ERROR] Some problems were encountered while processing the POMs:
[ERROR] Non-resolvable import POM: Could not find artifact org.springframework:spring-framework-bom:pom:${spring.version} in central (https://repo.maven.apache.org/maven2) @ line 29, column 21
[ERROR] 'dependencies.dependency.version' for org.springframework:spring-context:jar is missing. @ line 40, column 17
[ERROR] 'dependencies.dependency.version' for org.springframework:spring-core:jar is missing. @ line 44, column 17
[ERROR] 'dependencies.dependency.version' for org.springframework:spring-web:jar is missing. @ line 48, column 17
[ERROR] 'dependencies.dependency.version' for org.springframework:spring-webmvc:jar is missing. @ line 52, column 17
[ERROR] 'dependencies.dependency.version' for org.springframework:spring-aspects:jar is missing. @ line 56, column 17
 @
[ERROR] The build could not read 1 project -> [Help 1]
[ERROR]
[ERROR]   The project HelloWeb:HelloWeb:0.0.1-SNAPSHOT (C:\Users\jublikon\Development\Spring\Projects\HelloWeb\pom.xml) has 6 errors
[ERROR]     Non-resolvable import POM: Could not find artifact org.springframework:spring-framework-bom:pom:${spring.version} in central (https://repo.maven.apache.org/maven2) @ line 29, column 21 -> [Help 2]
[ERROR]     'dependencies.dependency.version' for org.springframework:spring-context:jar is missing. @ line 40, column 17
[ERROR]     'dependencies.dependency.version' for org.springframework:spring-core:jar is missing. @ line 44, column 17
[ERROR]     'dependencies.dependency.version' for org.springframework:spring-web:jar is missing. @ line 48, column 17
[ERROR]     'dependencies.dependency.version' for org.springframework:spring-webmvc:jar is missing. @ line 52, column 17
[ERROR]     'dependencies.dependency.version' for org.springframework:spring-aspects:jar is missing. @ line 56, column 17
[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/ProjectBuildingException
[ERROR] [Help 2] http://cwiki.apache.org/confluence/display/MAVEN/UnresolvableModelException

I have also checked my proxy settings. The active provider in eclipse is set to 'native' and I am not connected through a proxy

In the directory

~/.m2/settings.xml

main is org.apache.maven.cli.MavenCli from plexus.core

set maven.home default ${user.home}/m2

[plexus.core]
optionally ${maven.home}/lib/ext/*.jar
load       ${maven.home}/lib/*.jar
load       ${maven.home}/conf/logging
Community
  • 1
  • 1
jublikon
  • 3,427
  • 10
  • 44
  • 82

6 Answers6

9

I'm quite sure there is no artifact called "spring"

<dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring</artifactId>           <!-- *** spring doesn't *** exist  -->
    <version>4.2.6</version>
</dependency>

Depending on the Spring components you need, you should basically include these dependencies:

    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-context</artifactId>
        <version>4.2.6.RELEASE</version>
    </dependency>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-core</artifactId>
        <version>4.2.6.RELEASE</version>
    </dependency>

In my Spring project, I include the Spring artifacts via a BOM (Bill of Materials):

<properties>
    <spring.version>4.2.6.RELEASE</spring.version>
</properties>

<dependencyManagement>
    <dependencies>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-framework-bom</artifactId>
            <version>${spring.version}</version>
            <type>pom</type>
            <scope>import</scope>
        </dependency>
    </dependencies>
</dependencyManagement>

<dependencies>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-context</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-core</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-web</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-webmvc</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-aspects</artifactId>
    </dependency>
<!-- more -->
</dependencies>
JimHawkins
  • 4,843
  • 8
  • 35
  • 55
  • For some reason I am getting again the same issue although I am using your code.. I have update my question. Could you please have a look at it? – jublikon May 17 '16 at 13:16
  • @jublikon there are some things you can try... first: close `eclipse`, open a command line window, go to project directory (same where `pom.xml` is located) and execute `mvn clean install`. What happens? – JimHawkins May 17 '16 at 13:22
  • @jublikon second: check your proxy settings in eclipse, and in maven's `~/.m2/settings.xml` – JimHawkins May 17 '16 at 13:25
  • Thank you for your answer. I have checked your suggestions and updated my previous post. – jublikon May 17 '16 at 14:13
  • @jublikon there's something wrong in your `pom.xml`. Please show complete `pom.xml` ... I'll update my answer, please look at `` – JimHawkins May 17 '16 at 14:15
  • I have updated my pom.xml, so my mistake is the missing header ? – jublikon May 17 '16 at 14:21
  • the error message you've posted shows `Could not find artifact org.springframework:spring-framework-bom:pom:${spring.version}` . But the POM you've posted doesn't contain a reference to that... I think you mixed up something... I will follow this topic tomorrow. Have a nice evening – JimHawkins May 17 '16 at 14:34
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/112233/discussion-between-jublikon-and-ulrich). – jublikon May 18 '16 at 07:22
  • Referencing the `spring-framework-bom` artifact with an `import` scope does not work in Maven 2 when you don't have access to Maven Central. See http://stackoverflow.com/a/41752289/1743551 – Sandro Jan 19 '17 at 21:51
9

What worked for me is that I deleted

/Users/username/.m2/repository/org/springframework/spring/ directory

and then run mvn clean install command in my project.

That way Maven downloaded the real .jar file that was previously I guees not recognized.

user9347049
  • 1,927
  • 3
  • 27
  • 66
  • 2
    For me deleting ```/Users/username/.m2/repository/org/springframework``` directory and following latter solution by you has worked. – user3626720 Oct 18 '21 at 12:04
0

Maven by default downloads the required dependencies to your local repository so they can be accesses faster next time. Maybe the dependency is either corrupted, or removed from your local disk? Did you check that C:\Users\jublikon.m2\repository\org\springframework\spring\4.2.6\spring-4.2.6.jar actually exists and is a valid spring jar file?

Nadir
  • 1,369
  • 1
  • 15
  • 28
  • I see there two files: spring-4.2.6.jar.lastUpdated and spring-4.2.6.pom.lastUpdated. Is taht 'lastUpdated' file a valid jar file? – jublikon May 17 '16 at 12:28
  • No, so your maven did not fetched the required dependency. Try to run mvn clean install on your project and check if it is downloading any artifacts - if not, you should get an error saying what is the problem. Or take a look at the @Ulrich answer, most probably that is your problem - invalid dependecy description – Nadir May 17 '16 at 12:30
  • 1
    I think you have hit on an Eclipse oddity. Delete the C:\Users\jublikon.m2\repository\org\springframework\spring\4.2.6 directory and run mvn clean install on the project. This will force maven to download the real jar, rather than saying "I tried earlier and it didn't work". – kiwiron May 18 '16 at 09:58
0

What worked for me was I downloaded the jar files from mvnrepository I added them from build path and then I did clean compile install in Maven build and then validate the project and then update the project and the errors are gone.

0

For spring framework, I was using the following dependency in my pom.xml file

<dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-test</artifactId>
    <version>4.3.2RELEASE</version>
    <scope>test</scope>
</dependency>

But it was giving me the error

Missing artifact org.springframework.boot:spring-boot-starter-test:jar:4.3.2.RELEASE

But when I changed the version to the latest one, the error was removed.

<dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-test</artifactId>
    <version>5.2.1.RELEASE</version>
    <scope>test</scope>
</dependency>

So try using the latest version.

Akshay Chopra
  • 1,035
  • 14
  • 10
0

This issue is because of the required .jar files are not available in .m2 repo .

  1. Right click the project ->Maven ->project Update .

  2. If you are using settings.xml provided in working organization , then remove that settings.xml and repeat the step 1. when you place the settings.xml , it always tries to download the required .jar files from the organization repo.

Tek Nath Acharya
  • 1,676
  • 2
  • 20
  • 35