简体   繁体   中英

pom.xml error while creating a maven project

I am a beginner in developing with spring framework

I'm trying to create a webapp with spring MVC with a login form.

The problem is that when i create a new maven project eclipse show me an error in pom.xml which is so weird. could you help me please .

ERROR: Cannot read lifecycle mapping metadata for artifact org.apache.maven.plugins:maven-surefire-plugin:maven-plugin:2.12.4:runtime Cause: invalid END header (bad central directory offset)

error of pom.xml

It is because of one or more jar files are corrupted, so it will be difficult to find out which jar is the problem.

So just delete the .m2 repository and restart the eclipse .

If you are using window OS then location of .m2 directory is C:\\Users\\{username}\\.m2

It will work..!!

**this is my code of pom.xml** 

<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/maven-v4_0_0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>SpringMvcHibernate</groupId>
    <artifactId>SpringMvcHibernate</artifactId>
    <packaging>war</packaging>
    <version>0.0.1-SNAPSHOT</version>
    <name>SpringMvcHibernate Maven Webapp</name>
    <url>http://maven.apache.org</url>
    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    </properties>
    <dependencies>
        <!-- spring dependency -->
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-webmvc</artifactId>
            <version>5.0.5.RELEASE</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-orm</artifactId>
            <version>5.0.5.RELEASE</version>
        </dependency>
        <!-- jstl dependency -->
        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>jstl</artifactId>
            <version>1.2</version>
        </dependency>
        <!-- javax servlet api -->
        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>servlet-api</artifactId>
            <version>3.0-alpha-1</version>
        </dependency>
        <!-- hibernate dependency -->
        <dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-core</artifactId>
            <version>5.2.13.Final</version>
        </dependency>
        <!-- mysql connector dependency -->
        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <version>5.1.21</version>
        </dependency>
        <!-- log4j dependency -->
        <dependency>
            <groupId>log4j</groupId>
            <artifactId>log4j</artifactId>
            <version>1.2.17</version>
        </dependency>
    </dependencies>
    <build>
        <finalName>${project.artifactId}</finalName>
    </build>
</project>

See this is complete simple pom.xml of sample project which is correct and perfect working.

<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/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.irfan.sample</groupId>
<artifactId>SampleSpringMaven</artifactId>
<packaging>war</packaging>
<version>1.0-SNAPSHOT</version>
<name>SampleSpringMaven Maven Webapp</name>
<url>http://maven.apache.org</url>

<properties>
    <spring.version>3.0.5.RELEASE</spring.version>
    <jdk.version>1.8</jdk.version>
</properties>

<dependencies>

    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-core</artifactId>
        <version>${spring.version}</version>
    </dependency>

    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-web</artifactId>
        <version>${spring.version}</version>
    </dependency>

    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-webmvc</artifactId>
        <version>${spring.version}</version>
    </dependency>

    <dependency>
        <groupId>junit</groupId>
        <artifactId>junit</artifactId>
        <version>3.8.1</version>
        <scope>test</scope>
    </dependency>
</dependencies>

<build>
    <finalName>SampleSpringMaven</finalName>
    <plugins>
        <plugin>
            <groupId>org.apache.tomcat.maven</groupId>
            <artifactId>tomcat7-maven-plugin</artifactId>
            <version>2.1</version>
            <configuration>
                <url>http://localhost:8080/manager/text</url>
                <server>my-tomcat</server>
                <path>/SampleSpringMaven</path>
            </configuration>
        </plugin>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>3.0</version>
            <configuration>
                <source>${jdk.version}</source>
                <target>${jdk.version}</target>
            </configuration>
        </plugin>
    </plugins>
</build>

see if this can help you.

  • Removed the directory containing the different versions of the maven-war-plugin
  • After this Start the build with mvn install -U to update all the plugins the error will go.

我被更改为父版本,并且可以正常工作

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM