我正在使用Maven構建HelloWorld程序。但我失敗了使用Maven時「包不存在」的錯誤
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>
這是正確的方法,因爲您還有父級BOM。 –
謝謝。我將我的例子改爲使用hibernate的簡單易懂的例子。但問題依然存在。我該怎麼辦 ?手動編寫Greeting.java的工作... – Zheng