【发布时间】:2016-04-23 12:59:30
【问题描述】:
我正在使用 Maven 构建一个 HelloWorld 程序。但我失败了
mvn package
错误信息是:
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler- plugin:3.1:compile (default-compile) on project QuickStart: Compilation failure: Compilation failure:
[ERROR] /Users/xxx/java/QuickStart/src/main/java/hello/Greeting.java:[3,43] package org.hibernate does not exist
[ERROR] /Users/xxx/java/QuickStart/src/main/java/hello/Greeting.java:[8,9] cannot find symbol
[ERROR] symbol: class Session
[ERROR] location: class hello.Greeting
我发现如果我手动编译 Greeting.java,一切都会正常,这是什么原因?谢谢。
Greeting.java 就是这么简单:
package hello;
import org.hibernate.Session;
public class Greeting {
public Greeting() {
Session session;
}
}
我的 pom.xml 是从 spring.io 复制的:
<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>QuickStart</groupId>
<artifactId>QuickStart</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>
<dependencies>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
<version>5.0.7.Final</version>
</dependency>
</dependencies>
</project>
【问题讨论】: