简体   繁体   中英

Unable to Build using MAVEN with ERROR - Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:2.3.2:compile

I have been trying to build a code using maven. But I am stuck with an error. My system configurations as shown by maven is followning:

Apache Maven 3.0.2 (r1056850; 2011-01-09 07:58:10+0700)
Java version: 1.7.0_05, vendor: Oracle Corporation
Java home: /home/bhphuc/soft/jdk1.7.0_05/jre
Default locale: en_US, platform encoding: UTF-8
OS name: "linux", version: "3.11.0-15-generic", arch: "amd64", family: "unix"

Following is the Maven trace for the error:

[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:2.3.2:compile (default-compile) on project SpringExample: Compilation failure: Compilation failure:
[ERROR] /home/bhphuc/Axs/SpringHibernateAnnotationExample/src/main/java/com/mkyong/stock/model/Stock.java:[3,24] error: package javax.persistence does not exist
[ERROR] /home/bhphuc/Axs/SpringHibernateAnnotationExample/src/main/java/com/mkyong/stock/model/Stock.java:[4,24] error: package javax.persistence does not exist
[ERROR] /home/bhphuc/Axs/SpringHibernateAnnotationExample/src/main/java/com/mkyong/stock/model/Stock.java:[5,24] error: package javax.persistence does not exist
[ERROR] /home/bhphuc/Axs/SpringHibernateAnnotationExample/src/main/java/com/mkyong/stock/model/Stock.java:[6,31] error: package javax.persistence does not exist
[ERROR] /home/bhphuc/Axs/SpringHibernateAnnotationExample/src/main/java/com/mkyong/stock/model/Stock.java:[6,0] error: static import only from classes and interfaces
[ERROR] /home/bhphuc/Axs/SpringHibernateAnnotationExample/src/main/java/com/mkyong/stock/model/Stock.java:[7,24] error: package javax.persistence does not exist
[ERROR] /home/bhphuc/Axs/SpringHibernateAnnotationExample/src/main/java/com/mkyong/stock/model/Stock.java:[8,24] error: package javax.persistence does not exist
[ERROR] /home/bhphuc/Axs/SpringHibernateAnnotationExample/src/main/java/com/mkyong/stock/model/Stock.java:[9,24] error: package javax.persistence does not exist
[ERROR] /home/bhphuc/Axs/SpringHibernateAnnotationExample/src/main/java/com/mkyong/stock/model/Stock.java:[11,1] error: cannot find symbol
[ERROR] class Entity
[ERROR] /home/bhphuc/Axs/SpringHibernateAnnotationExample/src/main/java/com/mkyong/stock/model/Stock.java:[12,1] error: cannot find symbol
[ERROR] class Table
[ERROR] /home/bhphuc/Axs/SpringHibernateAnnotationExample/src/main/java/com/mkyong/stock/model/Stock.java:[29,2] error: cannot find symbol
[ERROR] class Stock
[ERROR] /home/bhphuc/Axs/SpringHibernateAnnotationExample/src/main/java/com/mkyong/stock/model/Stock.java:[30,2] error: cannot find symbol
[ERROR] class Stock
[ERROR] /home/bhphuc/Axs/SpringHibernateAnnotationExample/src/main/java/com/mkyong/stock/model/Stock.java:[31,2] error: cannot find symbol
[ERROR] class Stock
[ERROR] /home/bhphuc/Axs/SpringHibernateAnnotationExample/src/main/java/com/mkyong/stock/model/Stock.java:[40,2] error: cannot find symbol
[ERROR] class Stock
[ERROR] /home/bhphuc/Axs/SpringHibernateAnnotationExample/src/main/java/com/mkyong/stock/model/Stock.java:[49,2] error: cannot find symbol
[ERROR] -> [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/MojoFailureException

the pom.xml file.

<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.mkyong.common</groupId>
    <artifactId>SpringExample</artifactId>
    <packaging>jar</packaging>
    <version>1.0-SNAPSHOT</version>
    <name>SpringExample</name>
    <url>http://maven.apache.org</url>

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

    <dependencies>

        <!-- JUnit testing framework -->
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>3.8.1</version>
            <scope>test</scope>
        </dependency>

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

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

        <!-- Spring AOP dependency -->
        <dependency>
            <groupId>cglib</groupId>
            <artifactId>cglib</artifactId>
            <version>2.2</version>
        </dependency>

        <!-- MySQL database driver -->
        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <version>5.1.9</version>
        </dependency>

        <!-- Hibernate framework -->
        <dependency>
            <groupId>hibernate</groupId>
            <artifactId>hibernate3</artifactId>
            <version>3.2.3.GA</version>
        </dependency>

        <!-- Hibernate annotation -->
        <dependency>
            <groupId>hibernate-annotations</groupId>
            <artifactId>hibernate-annotations</artifactId>
            <version>3.3.0.GA</version>
        </dependency>

        <dependency>
            <groupId>hibernate-commons-annotations</groupId>
            <artifactId>hibernate-commons-annotations</artifactId>
            <version>3.0.0.GA</version>
        </dependency>

        <!-- Hibernate library dependecy start -->
        <dependency>
            <groupId>dom4j</groupId>
            <artifactId>dom4j</artifactId>
            <version>1.6.1</version>
        </dependency>

        <dependency>
            <groupId>commons-logging</groupId>
            <artifactId>commons-logging</artifactId>
            <version>1.1.1</version>
        </dependency>

        <dependency>
            <groupId>commons-collections</groupId>
            <artifactId>commons-collections</artifactId>
            <version>3.2.1</version>
        </dependency>

        <dependency>
            <groupId>antlr</groupId>
            <artifactId>antlr</artifactId>
            <version>2.7.7</version>
        </dependency>
        <!-- Hibernate library dependecy end -->

    </dependencies>
</project>

the pom.xml fail ???

<dependency>
    <groupId>javax.persistence</groupId>
    <artifactId>persistence-api</artifactId>
    <version>1.0</version>
</dependency>

try to add this dependency in your pom file. Also had you noticed the error

[ERROR] /home/bhphuc/Axs/SpringHibernateAnnotationExample/src/main/java/com/mkyong/stock/model/Stock.java:[6,0] error: static import only from classes and interface

Did you used any static imports there (in Stock class) ?? Also please check your JDK version.

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