缺少默认 Java 包?
Missing Default Java Package?
我正在尝试从 here 编译一些经过编辑的源代码,但是我不断收到关于名为 "javax.persistence".
的包的许多错误
这是我的 IDE 版本 -
IntelliJ IDEA 2016.2.4
Build #IC-162.2032.8, built on September 9, 2016
JRE: 1.8.0_112-release-b343 x86
JVM: OpenJDK Server VM by JetBrains s.r.o
我的 JDK 似乎不包括这个包,因为我在 SDK 选项卡中链接了整个 JDK。有谁知道我做错了什么?这是我的消息 window -
的输出
Information:Using javac 1.8.0_101 to compile java sources
Information:java: Errors occurred while compiling module 'BctalkBumpBot-1.0'
Information:2/10/2016 9:10 PM - Compilation completed with 37 errors and 3 warnings in 3s 3ms
Warning:java: source value 1.5 is obsolete and will be removed in a future release
Warning:java: target value 1.5 is obsolete and will be removed in a future release
Warning:java: To suppress warnings about obsolete options, use -Xlint:-options.
C:\Users\gabri\Desktop\BctalkBumpBot-1.0\src\com\achow101\bumpbot\BumpEntry.java
Error:(21, 1) java: package javax.persistence does not exist
Error:(26, 2) java: cannot find symbol
symbol: class Entity
Error:(29, 6) java: cannot find symbol
symbol: class Id
location: class com.achow101.bumpbot.BumpEntry
C:\Users\gabri\Desktop\BctalkBumpBot-1.0\src\com\achow101\bumpbot\DoBumps.java
Error:(26, 25) java: package javax.persistence does not exist
Error:(27, 25) java: package javax.persistence does not exist
Error:(28, 25) java: package javax.persistence does not exist
Error:(29, 25) java: package javax.persistence does not exist
Error:(30, 34) java: package javax.persistence.criteria does not exist
Error:(31, 34) java: package javax.persistence.criteria does not exist
Error:(32, 34) java: package javax.persistence.criteria does not exist
Error:(48, 9) java: cannot find symbol
symbol: class EntityManagerFactory
location: class com.achow101.bumpbot.DoBumps
Error:(48, 36) java: cannot find symbol
symbol: variable Persistence
location: class com.achow101.bumpbot.DoBumps
Error:(49, 9) java: cannot find symbol
symbol: class EntityManager
location: class com.achow101.bumpbot.DoBumps
Error:(50, 9) java: cannot find symbol
symbol: class CriteriaBuilder
location: class com.achow101.bumpbot.DoBumps
Error:(56, 17) java: cannot find symbol
symbol: class CriteriaQuery
location: class com.achow101.bumpbot.DoBumps
Error:(57, 17) java: cannot find symbol
symbol: class Root
location: class com.achow101.bumpbot.DoBumps
Error:(59, 17) java: cannot find symbol
symbol: class TypedQuery
location: class com.achow101.bumpbot.DoBumps
C:\Users\gabri\Desktop\BctalkBumpBot-1.0\src\com\achow101\bumpbot\BumpBot.java
Error:(40, 25) java: package javax.persistence does not exist
Error:(41, 25) java: package javax.persistence does not exist
Error:(42, 25) java: package javax.persistence does not exist
Error:(43, 25) java: package javax.persistence does not exist
Error:(44, 34) java: package javax.persistence.criteria does not exist
Error:(45, 34) java: package javax.persistence.criteria does not exist
Error:(46, 34) java: package javax.persistence.criteria does not exist
Error:(113, 9) java: cannot find symbol
symbol: class EntityManagerFactory
location: class com.achow101.bumpbot.BumpBot
Error:(113, 36) java: cannot find symbol
symbol: variable Persistence
location: class com.achow101.bumpbot.BumpBot
Error:(114, 9) java: cannot find symbol
symbol: class EntityManager
location: class com.achow101.bumpbot.BumpBot
Error:(117, 9) java: cannot find symbol
symbol: class CriteriaBuilder
location: class com.achow101.bumpbot.BumpBot
Error:(118, 9) java: cannot find symbol
symbol: class CriteriaQuery
location: class com.achow101.bumpbot.BumpBot
Error:(119, 9) java: cannot find symbol
symbol: class Root
location: class com.achow101.bumpbot.BumpBot
Error:(121, 9) java: cannot find symbol
symbol: class TypedQuery
location: class com.achow101.bumpbot.BumpBot
Error:(165, 17) java: cannot find symbol
symbol: class EntityManagerFactory
Error:(165, 44) java: cannot find symbol
symbol: variable Persistence
Error:(166, 17) java: cannot find symbol
symbol: class EntityManager
Error:(287, 17) java: cannot find symbol
symbol: class EntityManagerFactory
Error:(287, 44) java: cannot find symbol
symbol: variable Persistence
Error:(288, 17) java: cannot find symbol
symbol: class EntityManager
感谢任何帮助。
学习阅读错误信息。您正在尝试编译需要 javax.persistence 类 的内容。这些不包含在标准库中(它们曾在某个时候包含但多年未包含)。
另外,您确实没有安装实际的 JDK,而是安装了 JRE。 IntelliJ 显然并不那么介意,这让我有点吃惊。似乎它正在使用内部编译器。
安装 JDK,从某个地方获取 JEE 或至少一个 JPA 实现(Hibernate 或 Eclipselink 都不错),然后就可以了。
显然,有时主 Java 包不包含 javax.persistence
,具体取决于您使用的 Java 版本。在这种情况下,您将收到错误 java: package javax.persistence does not exist
。
在这种情况下,您所要做的就是为 javax.persistence
添加另一个依赖项
<!-- https://mvnrepository.com/artifact/javax.persistence/javax.persistence-api -->
<dependency>
<groupId>javax.persistence</groupId>
<artifactId>javax.persistence-api</artifactId>
<version>2.2</version>
</dependency>
来源:https://ranvir.xyz/blog/building-restful-apis-with-java-spring-boot-framework-for-beginners/
我正在尝试从 here 编译一些经过编辑的源代码,但是我不断收到关于名为 "javax.persistence".
的包的许多错误这是我的 IDE 版本 -
IntelliJ IDEA 2016.2.4
Build #IC-162.2032.8, built on September 9, 2016
JRE: 1.8.0_112-release-b343 x86
JVM: OpenJDK Server VM by JetBrains s.r.o
我的 JDK 似乎不包括这个包,因为我在 SDK 选项卡中链接了整个 JDK。有谁知道我做错了什么?这是我的消息 window -
的输出Information:Using javac 1.8.0_101 to compile java sources
Information:java: Errors occurred while compiling module 'BctalkBumpBot-1.0'
Information:2/10/2016 9:10 PM - Compilation completed with 37 errors and 3 warnings in 3s 3ms
Warning:java: source value 1.5 is obsolete and will be removed in a future release
Warning:java: target value 1.5 is obsolete and will be removed in a future release
Warning:java: To suppress warnings about obsolete options, use -Xlint:-options.
C:\Users\gabri\Desktop\BctalkBumpBot-1.0\src\com\achow101\bumpbot\BumpEntry.java
Error:(21, 1) java: package javax.persistence does not exist
Error:(26, 2) java: cannot find symbol
symbol: class Entity
Error:(29, 6) java: cannot find symbol
symbol: class Id
location: class com.achow101.bumpbot.BumpEntry
C:\Users\gabri\Desktop\BctalkBumpBot-1.0\src\com\achow101\bumpbot\DoBumps.java
Error:(26, 25) java: package javax.persistence does not exist
Error:(27, 25) java: package javax.persistence does not exist
Error:(28, 25) java: package javax.persistence does not exist
Error:(29, 25) java: package javax.persistence does not exist
Error:(30, 34) java: package javax.persistence.criteria does not exist
Error:(31, 34) java: package javax.persistence.criteria does not exist
Error:(32, 34) java: package javax.persistence.criteria does not exist
Error:(48, 9) java: cannot find symbol
symbol: class EntityManagerFactory
location: class com.achow101.bumpbot.DoBumps
Error:(48, 36) java: cannot find symbol
symbol: variable Persistence
location: class com.achow101.bumpbot.DoBumps
Error:(49, 9) java: cannot find symbol
symbol: class EntityManager
location: class com.achow101.bumpbot.DoBumps
Error:(50, 9) java: cannot find symbol
symbol: class CriteriaBuilder
location: class com.achow101.bumpbot.DoBumps
Error:(56, 17) java: cannot find symbol
symbol: class CriteriaQuery
location: class com.achow101.bumpbot.DoBumps
Error:(57, 17) java: cannot find symbol
symbol: class Root
location: class com.achow101.bumpbot.DoBumps
Error:(59, 17) java: cannot find symbol
symbol: class TypedQuery
location: class com.achow101.bumpbot.DoBumps
C:\Users\gabri\Desktop\BctalkBumpBot-1.0\src\com\achow101\bumpbot\BumpBot.java
Error:(40, 25) java: package javax.persistence does not exist
Error:(41, 25) java: package javax.persistence does not exist
Error:(42, 25) java: package javax.persistence does not exist
Error:(43, 25) java: package javax.persistence does not exist
Error:(44, 34) java: package javax.persistence.criteria does not exist
Error:(45, 34) java: package javax.persistence.criteria does not exist
Error:(46, 34) java: package javax.persistence.criteria does not exist
Error:(113, 9) java: cannot find symbol
symbol: class EntityManagerFactory
location: class com.achow101.bumpbot.BumpBot
Error:(113, 36) java: cannot find symbol
symbol: variable Persistence
location: class com.achow101.bumpbot.BumpBot
Error:(114, 9) java: cannot find symbol
symbol: class EntityManager
location: class com.achow101.bumpbot.BumpBot
Error:(117, 9) java: cannot find symbol
symbol: class CriteriaBuilder
location: class com.achow101.bumpbot.BumpBot
Error:(118, 9) java: cannot find symbol
symbol: class CriteriaQuery
location: class com.achow101.bumpbot.BumpBot
Error:(119, 9) java: cannot find symbol
symbol: class Root
location: class com.achow101.bumpbot.BumpBot
Error:(121, 9) java: cannot find symbol
symbol: class TypedQuery
location: class com.achow101.bumpbot.BumpBot
Error:(165, 17) java: cannot find symbol
symbol: class EntityManagerFactory
Error:(165, 44) java: cannot find symbol
symbol: variable Persistence
Error:(166, 17) java: cannot find symbol
symbol: class EntityManager
Error:(287, 17) java: cannot find symbol
symbol: class EntityManagerFactory
Error:(287, 44) java: cannot find symbol
symbol: variable Persistence
Error:(288, 17) java: cannot find symbol
symbol: class EntityManager
感谢任何帮助。
学习阅读错误信息。您正在尝试编译需要 javax.persistence 类 的内容。这些不包含在标准库中(它们曾在某个时候包含但多年未包含)。
另外,您确实没有安装实际的 JDK,而是安装了 JRE。 IntelliJ 显然并不那么介意,这让我有点吃惊。似乎它正在使用内部编译器。
安装 JDK,从某个地方获取 JEE 或至少一个 JPA 实现(Hibernate 或 Eclipselink 都不错),然后就可以了。
显然,有时主 Java 包不包含 javax.persistence
,具体取决于您使用的 Java 版本。在这种情况下,您将收到错误 java: package javax.persistence does not exist
。
在这种情况下,您所要做的就是为 javax.persistence
<!-- https://mvnrepository.com/artifact/javax.persistence/javax.persistence-api -->
<dependency>
<groupId>javax.persistence</groupId>
<artifactId>javax.persistence-api</artifactId>
<version>2.2</version>
</dependency>
来源:https://ranvir.xyz/blog/building-restful-apis-with-java-spring-boot-framework-for-beginners/