我一直在尝试使用maven构建代码。但我遇到了一个错误。 我的系统配置由maven显示如下:
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"
以下是错误的Maven跟踪:
[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
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>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>
pom.xml失败???
答案 0 :(得分:1)
<dependency>
<groupId>javax.persistence</groupId>
<artifactId>persistence-api</artifactId>
<version>1.0</version>
</dependency>
尝试在pom文件中添加此依赖项。你也注意到了错误
[ERROR] /home/bhphuc/Axs/SpringHibernateAnnotationExample/src/main/java/com/mkyong/stock/model/Stock.java:[6,0] error: static import only from classes and interface
你在那里使用过任何静态导入(在Stock类中)?另请检查您的JDK版本。