我正在使用 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>
最佳答案
尝试添加此依赖项:
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context-support</artifactId>
</dependency>
关于java - 使用 Maven 时出现 "package does not exist"错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34853326/