Chapter 2 compiles but doesn't run - ClassNotFoundException for javax.persistence.Persistence

  5 posts   Feedicon  
Replies: 4 - Last Post: December 30, 2010 09:09
by: agoncal
showing 1 - 5 of 5
 
Posted: August 31, 2010 22:05 by cwienands
Hey guys,

Alexis, thanks for replying to my post on the Java forum. Heeding your advice I just retrieved the very latest source code. Building chapter 2 works out of the box. However, running chapter 2 does not.

I'm getting the message:

Caused by: java.lang.ClassNotFoundException: javax.persistence.Persistence
at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
at java.lang.ClassLoader.loadClass(ClassLoader.java:248)
... 7 more


Any idea why Maven can compile against JPA but not run the example?

Thanks a lot,

Christoph
 
Posted: September 01, 2010 15:02 by cwienands
One more thing that came to my mind after reading through other Maven-related posts...

Because the scope of javax.persistence is 'provided', Maven can compile the Chapter 2 code but it will not include the JEE jars with the compiled code (if I understood the book correctly). At runtime usually a container would provide the JEE spec implementations such as for JPA. However, Chapter 2 does not run the example in GlassFish but from the command line. So where does the reference to the JEE spec implementations come in?

Thanks, Christoph
 
Posted: September 16, 2010 17:18 by chrissorens
If you have the original code from the Apress site this is the problem:
The source code for chapter 2 contains references to chapter04 in the Main.java and persistence.xml files. If the references are changed from 4 to 2 it does compile. I reported the problem to Apress in April and got the response that the book was not scheduled to be published until July (so their database must have had a problem as well).
 
Posted: November 15, 2010 09:17 by ankur debnath
I'm getting a fatal error Error building POM (may not be this project's POM) while trying to run Chapter 2 in the command prompt . It also says unable to find resource

1. I used the updated 2nd Edition SOURCE CODE for Chapter 2 .
2. Please have a look at my command prompt HERE
This is what I have done
I'm using windows and placed the project in C>chapter02 (which contains the pom and the source files)
In the book Mr. Goncalves talks about the root directory . [ I assume it to be any directory that has the pom.xml] ... Is there a specific root where we have to place the file like HTDOCS in XAMPP which is used in php ?

Do we have to download EclipseLink separately ? [ I did not download it separately, dependencies are good enough I thought ]






 
Posted: December 30, 2010 09:09 by agoncal
Try mvn clean install for the root of the project (the very top root, not the chapter02 root)
Replies: 4 - Last Post: December 30, 2010 09:09
by: agoncal
  • Mysql
  • Glassfish
  • Jruby
  • Rails
  • Nblogo
Terms of Use; Privacy Policy;
© 2010, Oracle Corporation and/or its affiliates
(revision 20120518.3c65429)
 
 
Close
loading
Please Confirm
Close