两部分问题:
第一部分:需要哪个 JAR?javax.persistence-2.0.0.jar 没有所需的类,特别是 javax.persistence.*?
堆栈跟踪如下:
init:
deps-jar:
Created dir: /home/thufir/NetBeansProjects/JavaApplication12/build
Updating property file: /home/thufir/NetBeansProjects/JavaApplication12/build/built-jar.properties
Created dir: /home/thufir/NetBeansProjects/JavaApplication12/build/classes
Created dir: /home/thufir/NetBeansProjects/JavaApplication12/build/classes/META-INF
Copying 1 file to /home/thufir/NetBeansProjects/JavaApplication12/build/classes/META-INF
Created dir: /home/thufir/NetBeansProjects/JavaApplication12/build/empty
Created dir: /home/thufir/NetBeansProjects/JavaApplication12/build/generated-sources/ap-source-output
Compiling 2 source files to /home/thufir/NetBeansProjects/JavaApplication12/build/classes
/home/thufir/NetBeansProjects/JavaApplication12/src/javaapplication12/Fud30Groups.java:8: error: package javax.persistence does not exist
import javax.persistence.*;
/home/thufir/NetBeansProjects/JavaApplication12/src/javaapplication12/Fud30Groups.java:15: error: cannot find symbol
@Entity
symbol: class Entity
/home/thufir/NetBeansProjects/JavaApplication12/src/javaapplication12/Fud30Groups.java:16: error: cannot find symbol
@Table(name = "fud30_groups", catalog = "fudforum", schema = "")
symbol: class Table
/home/thufir/NetBeansProjects/JavaApplication12/src/javaapplication12/Fud30Groups.java:18: error: cannot find symbol
@NamedQueries({
symbol: class NamedQueries
/home/thufir/NetBeansProjects/JavaApplication12/src/javaapplication12/Fud30Groups.java:28: error: cannot find symbol
@Id
symbol: class Id
location: class Fud30Groups
/home/thufir/NetBeansProjects/JavaApplication12/src/javaapplication12/Fud30Groups.java:29: error: cannot find symbol
@GeneratedValue(strategy = GenerationType.IDENTITY)
symbol: class GeneratedValue
location: class Fud30Groups
/home/thufir/NetBeansProjects/JavaApplication12/src/javaapplication12/Fud30Groups.java:30: error: cannot find symbol
@Basic(optional = false)
symbol: class Basic
location: class Fud30Groups
/home/thufir/NetBeansProjects/JavaApplication12/src/javaapplication12/Fud30Groups.java:31: error: cannot find symbol
@Column(name = "id")
symbol: class Column
location: class Fud30Groups
/home/thufir/NetBeansProjects/JavaApplication12/src/javaapplication12/Fud30Groups.java:33: error: cannot find symbol
@Basic(optional = false)
symbol: class Basic
location: class Fud30Groups
/home/thufir/NetBeansProjects/JavaApplication12/src/javaapplication12/Fud30Groups.java:34: error: cannot find symbol
@Column(name = "name")
symbol: class Column
location: class Fud30Groups
/home/thufir/NetBeansProjects/JavaApplication12/src/javaapplication12/Fud30Groups.java:36: error: cannot find symbol
@Basic(optional = false)
symbol: class Basic
location: class Fud30Groups
/home/thufir/NetBeansProjects/JavaApplication12/src/javaapplication12/Fud30Groups.java:37: error: cannot find symbol
@Column(name = "inherit_id")
symbol: class Column
location: class Fud30Groups
/home/thufir/NetBeansProjects/JavaApplication12/src/javaapplication12/Fud30Groups.java:39: error: cannot find symbol
@Basic(optional = false)
symbol: class Basic
location: class Fud30Groups
/home/thufir/NetBeansProjects/JavaApplication12/src/javaapplication12/Fud30Groups.java:40: error: cannot find symbol
@Column(name = "forum_id")
symbol: class Column
location: class Fud30Groups
/home/thufir/NetBeansProjects/JavaApplication12/src/javaapplication12/Fud30Groups.java:42: error: cannot find symbol
@Basic(optional = false)
symbol: class Basic
location: class Fud30Groups
/home/thufir/NetBeansProjects/JavaApplication12/src/javaapplication12/Fud30Groups.java:43: error: cannot find symbol
@Column(name = "groups_opt")
symbol: class Column
location: class Fud30Groups
/home/thufir/NetBeansProjects/JavaApplication12/src/javaapplication12/Fud30Groups.java:45: error: cannot find symbol
@Basic(optional = false)
symbol: class Basic
location: class Fud30Groups
/home/thufir/NetBeansProjects/JavaApplication12/src/javaapplication12/Fud30Groups.java:46: error: cannot find symbol
@Column(name = "groups_opti")
symbol: class Column
location: class Fud30Groups
18 errors
/home/thufir/NetBeansProjects/JavaApplication12/nbproject/build-impl.xml:605: The following error occurred while executing this line:
/home/thufir/NetBeansProjects/JavaApplication12/nbproject/build-impl.xml:246: Compile failed; see the compiler error output for details.
BUILD FAILED (total time: 0 seconds)
问题的第二部分是,Netbeans(可能)有什么问题?直到昨天,当从现有数据库生成 @Entity 类时,IDE 似乎会自动将所需的类添加到类路径中。在这种特殊情况下,Netbeans 确实添加了 JAR。
但是,因为它们是从外部添加到项目中的,所以没有 lib 文件夹。不幸的是,我还不够熟悉,无法真正深入了解 build.xml 以了解发生了什么,但从库管理器看来,它们是这样的:
thufir@dur:~$ tree netbeans-7.1.1/java/modules/ext/eclipselink/
netbeans-7.1.1/java/modules/ext/eclipselink/
├── eclipselink-2.3.0.jar
├── eclipselink-jpa-modelgen-2.3.0.jar
├── javax.persistence-2.0.jar
└── org.eclipse.persistence.jpa.jpql_1.0.0.jar
0 directories, 4 files
thufir@dur:~$
它似乎不符合我的回忆,过去需要额外的步骤,下载缺少的 JAR。Netbeans 中的设置是否错误或损坏?