4

I'm trying to compile some edited source code from here, however I keep getting many errors regarding a package named "javax.persistence".

This is my IDE version -

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

My JDK seems to not include this package, as I have linked the whole JDK in the SDK tab. Does anyone know what i'm doing wrong? This is the output of my messages 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

Any help is appreciated.

2 Answers 2

2

Learn to read error messages. You're trying to compile something that requires javax.persistence classes. These are not included in the standard libraries (they were at some point but haven't been for years).
Also, you indeed don't have an actual JDK installed, but a JRE. IntelliJ apparently doesn't mind all that much, which kinda surprises me. Seems it is using an internal compiler.
Install a JDK, get a JEE or at least a JPA implementation from somewhere (Hibernate or Eclipselink are good), and away you go.

4
  • I installed the JRE, but then after IntelliJ requested a JDK, I installed the JDK on top of it. I thought this means I have a JDK? Commented Oct 2, 2016 at 11:03
  • you should, if it's properly configured. Remove java*.exe from windows/system32 as well. And add Hibernate or Eclipselink to your project to get JPA functionality.
    – jwenting
    Commented Oct 2, 2016 at 11:26
  • Is my IntelliJ install broken? Instead of Eclipselink, I previously installed objectdb. Here are some screenshots - imgur.com/a/lymM8 Commented Oct 3, 2016 at 6:11
  • Add the libraries at project level, not global. Objectdb afaik is not a JPA provider anyway, so wouldn't give you the classes you need.
    – jwenting
    Commented Oct 3, 2016 at 6:24
0

Apparently, sometimes the main Java package doesn't contain javax.persistence depending on the version of Java that you're using. In that case you will get an error java: package javax.persistence does not exist. All you have to do in that case is add another dependency for 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>

Source: https://ranvir.xyz/blog/building-restful-apis-with-java-spring-boot-framework-for-beginners/

Not the answer you're looking for? Browse other questions tagged or ask your own question.