4

两部分问题:

第一部分:需要哪个 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 中的设置是否错误或损坏?

4

1 回答 1

-1

幸运数字 13,Netbeans 项目 13,与 Netbeans 项目 12 尽可能相同,构建良好(嗯,不太好,但确实构建):

清理和构建:

init:
deps-clean:
Updating property file: /home/thufir/NetBeansProjects/JavaApplication13/build/built-clean.properties
Deleting directory /home/thufir/NetBeansProjects/JavaApplication13/build
clean:
init:
deps-jar:
Created dir: /home/thufir/NetBeansProjects/JavaApplication13/build
Updating property file: /home/thufir/NetBeansProjects/JavaApplication13/build/built-jar.properties
Created dir: /home/thufir/NetBeansProjects/JavaApplication13/build/classes
Created dir: /home/thufir/NetBeansProjects/JavaApplication13/build/classes/META-INF
Copying 1 file to /home/thufir/NetBeansProjects/JavaApplication13/build/classes/META-INF
Created dir: /home/thufir/NetBeansProjects/JavaApplication13/build/empty
Created dir: /home/thufir/NetBeansProjects/JavaApplication13/build/generated-sources/ap-source-output
Compiling 2 source files to /home/thufir/NetBeansProjects/JavaApplication13/build/classes
warning: Supported source version 'RELEASE_6' from annotation processor 'org.eclipse.persistence.internal.jpa.modelgen.CanonicalModelProcessor' less than -source '1.7'
Note: Creating non-static metadata factory ...
Note: Found Option : eclipselink.canonicalmodel.use_static_factory, with value: false
Note: Optional file was not found: META-INF/orm.xml continuing with generation.
Note: Optional file was not found: META-INF/eclipselink-orm.xml continuing with generation.
Note: Found Option : eclipselink.canonicalmodel.use_static_factory, with value: false
Note: Optional file was not found: META-INF/orm.xml continuing with generation.
Note: Optional file was not found: META-INF/eclipselink-orm.xml continuing with generation.
warning: The following options were not recognized by any processor: '[eclipselink.canonicalmodel.use_static_factory]'
1 warning
Copying 2 files to /home/thufir/NetBeansProjects/JavaApplication13/build/classes
compile:
BUILD SUCCESSFUL (total time: 6 seconds)

两个项目:

thufir@dur:~/NetBeansProjects$ 
thufir@dur:~/NetBeansProjects$ tree JavaApplication12
JavaApplication12
├── build
│   ├── built-jar.properties
│   ├── classes
│   │   └── META-INF
│   │       └── persistence.xml
│   ├── empty
│   └── generated-sources
│       └── ap-source-output
├── build.xml
├── manifest.mf
├── nbproject
│   ├── build-impl.xml
│   ├── genfiles.properties
│   ├── private
│   │   └── private.properties
│   ├── project.properties
│   └── project.xml
└── src
    ├── javaapplication12
    │   ├── Fud30Groups.java
    │   └── JavaApplication12.java
    └── META-INF
        └── persistence.xml

11 directories, 12 files
thufir@dur:~/NetBeansProjects$ 
thufir@dur:~/NetBeansProjects$ tree JavaApplication13
JavaApplication13
├── build
│   ├── built-jar.properties
│   ├── classes
│   │   ├── javaapplication13
│   │   │   ├── Fud30Groups_.class
│   │   │   ├── Fud30Groups.class
│   │   │   ├── Fud30Groups.java
│   │   │   ├── JavaApplication13.class
│   │   │   └── JavaApplication13.java
│   │   └── META-INF
│   │       └── persistence.xml
│   ├── empty
│   └── generated-sources
│       └── ap-source-output
│           └── javaapplication13
│               └── Fud30Groups_.java
├── build.xml
├── lib
│   ├── CopyLibs
│   │   └── org-netbeans-modules-java-j2seproject-copylibstask.jar
│   ├── eclipselink
│   │   ├── eclipselink-2.3.0.jar
│   │   ├── javax.persistence-2.0.jar
│   │   └── org.eclipse.persistence.jpa.jpql_1.0.0.jar
│   ├── eclipselinkmodelgen
│   │   └── eclipselink-jpa-modelgen-2.3.0.jar
│   └── nblibraries.properties
├── manifest.mf
├── nbproject
│   ├── build-impl.xml
│   ├── genfiles.properties
│   ├── private
│   │   ├── config.properties
│   │   └── private.properties
│   ├── project.properties
│   └── project.xml
└── src
    ├── javaapplication13
    │   ├── Fud30Groups.java
    │   └── JavaApplication13.java
    └── META-INF
        └── persistence.xml

17 directories, 25 files
thufir@dur:~/NetBeansProjects$ 

区别显然是项目 13 有一个 ./lib 文件夹,而项目 12 使用的是“外部”JAR。

也许我的 Netbeans 安装已损坏,或者设置错误,或者我对项目 12 的方法有误?我想用外部 JAR 来做,就像项目 12 所做的那样,因为各种特性,比如库管理器,工作得更好。

于 2012-05-08T12:27:38.780 回答