This week's book giveaway is in the Mac OS forum.
We're giving away four copies of a choice of "Take Control of Upgrading to Yosemite" or "Take Control of Automating Your Mac" and have Joe Kissell on-line!
See this thread for details.
The moose likes EJB Certification (SCBCD/OCPJBCD) and the fly likes Anybody ever faced this problem running client of chapter 2 of pro ejb 3 java persistence api Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Certification » EJB Certification (SCBCD/OCPJBCD)
Bookmark "Anybody ever faced this problem running client of chapter 2 of pro ejb 3 java persistence api" Watch "Anybody ever faced this problem running client of chapter 2 of pro ejb 3 java persistence api" New topic
Author

Anybody ever faced this problem running client of chapter 2 of pro ejb 3 java persistence api

nav katoch
Ranch Hand

Joined: May 02, 2008
Posts: 246

Hi all,

Thanks for your time. I am running an example of chapter 2 of Pro EJB 3 java persistence api and got the following errors:-

C:\EXAMPLES_HOME\examples\Chapter2\employeeService>ant
Buildfile: build.xml

init:

setup:

build_jar:
[javac] Compiling 2 source files to C:\EXAMPLES_HOME\examples\Chapter2\employeeService\build\model
[javac] C:\EXAMPLES_HOME\examples\Chapter2\employeeService\src\model\examples\model\Employee.java:3: package javax.persistence does not exist
[javac] import javax.persistence.Entity;
[javac] ^
[javac] C:\EXAMPLES_HOME\examples\Chapter2\employeeService\src\model\examples\model\Employee.java:4: package javax.persistence does not exist
[javac] import javax.persistence.Id;
[javac] ^
[javac] C:\EXAMPLES_HOME\examples\Chapter2\employeeService\src\model\examples\model\Employee.java:6: cannot find symbol
[javac] symbol: class Entity
[javac] @Entity
[javac] ^
[javac] C:\EXAMPLES_HOME\examples\Chapter2\employeeService\src\model\examples\model\EmployeeService.java:5: package javax.persistence does not exist
[javac] import javax.persistence.EntityManager;
[javac] ^
[javac] C:\EXAMPLES_HOME\examples\Chapter2\employeeService\src\model\examples\model\EmployeeService.java:6: package javax.persistence does not exist
[javac] import javax.persistence.Query;
[javac] ^
[javac] C:\EXAMPLES_HOME\examples\Chapter2\employeeService\src\model\examples\model\EmployeeService.java:10: cannot find symbol
[javac] symbol : class EntityManager
[javac] location: class examples.model.EmployeeService
[javac] protected EntityManager em;
[javac] ^
[javac] C:\EXAMPLES_HOME\examples\Chapter2\employeeService\src\model\examples\model\EmployeeService.java:12: cannot find symbol
[javac] symbol : class EntityManager
[javac] location: class examples.model.EmployeeService
[javac] public EmployeeService(EntityManager em) {
[javac] ^
[javac] C:\EXAMPLES_HOME\examples\Chapter2\employeeService\src\model\examples\model\Employee.java:8: cannot find symbol
[javac] symbol : class Id
[javac] location: class examples.model.Employee
[javac] @Id
[javac] ^
[javac] C:\EXAMPLES_HOME\examples\Chapter2\employeeService\src\model\examples\model\EmployeeService.java:44: cannot find symbol
[javac] symbol : class Query
[javac] location: class examples.model.EmployeeService
[javac] Query query = em.createQuery("SELECT e FROM Employee e");
[javac] ^
[javac] 9 errors

BUILD FAILED
C:\EXAMPLES_HOME\config\common.xml:29: Compile failed; see the compiler error output for details.

I have all packages in place. So, anybody has any clue or somebody has run these examples. Please share your exerience regarding running these examples. I searched the forum but no help.

Thanks again for your reply and thoughts,

Naveen Katoch
nav katoch
Ranch Hand

Joined: May 02, 2008
Posts: 246

Any inputs, Naveen.
Ross Crockett
Ranch Hand

Joined: Aug 25, 2009
Posts: 30
Looks like no JPA classes are being found when ant compiles your code, it's likely you don't have the JPA classes or they aren't on the classpath.

Look into this first and reply if still in trouble.
nav katoch
Ranch Hand

Joined: May 02, 2008
Posts: 246

Hi Ross,

Thanks for your reply. I appreciate it. I have been trying for the last 2 days but no success. I asked the auther of this book and he replied with this following message "You need to install the Glassfish server, which comes with TopLink Essentials and the javax.persistence interfaces that you need to compile with". I tried following this message but failed.

Please give me your suggestions.

Thanks again,

Naveen
Ross Crockett
Ranch Hand

Joined: Aug 25, 2009
Posts: 30
Hey nav,

I tried following this message but failed.


The more info you post here will increase your chances of finding a solution, check out Tell The Details.

Since I assumed you couldn't install Glassfish, try the following steps:

1. In a web browser go to https://glassfish.dev.java.net/public/downloadsindex.html#top
2. Download the latest stable version (think its 2.1.1).
3. Also on that page is a link to a quick start guide. You should read this to get a familiarity with the server etc.
4. The installation should be pretty self explanatory, from memory I don't think there was anything that required special knowledge to complete.
5. Once setup make sure you set all the appropriate environment variables (JAVA_HOME, J2EE_HOME etc).
6. From memory, EJB3 in Action requires you to possibly change some things in the Ant script. Check the readme (if there is one) that comes with the examples on what needs to be set before running examples.

Hope that helps. If your still struggling, post a bit more info about what you have installed (e.g. your CLASSPATH, JDK etc.) and the exact details of the problems your facing (e.g. error messages, can't understand a step)

Cheers,
Ross
nav katoch
Ranch Hand

Joined: May 02, 2008
Posts: 246

Hi Ross,

Thanks for your response with details. The following are the main files:-

1. File - GettingStarted.txt
- Assume you've downloaded the examples and unzipped them to <EXAMPLES_HOME>.

- download a copy of glassfish from https://glassfish.dev.java.net/public/downloadsindex.html

- copy the downloaded .jar file to <EXAMPLES_HOME>

- edit <EXAMPLES_HOME>/config/setenv.bat to point to your JDK 5.0 directory. The JDK is available for download at http://java.sun.com/j2se/1.5.0/download.jsp

- edit <EXAMPLES_HOME>/config/common.properties and set the EXAMPLES_HOME variable (location where you unzipped the examples jar). NOTE: make sure you use '/' and NOT '\'

- run <EXAMPLES_HOME>/bin/installserver.bat to install glassfish. Read and accept the licensing agreement that pops up.

- you can now run the examples. Double-click <EXAMPLES_HOME>/examples/examples.html to get started

2 File - common.properties
# EXAMPLES_HOME=d:/book/examples
EXAMPLES_HOME=C:/EXAMPLES_HOME/examples

##################################################
# properties for the Glassfish application server
##################################################
SERVER_HOME=${EXAMPLES_HOME}/glassfish
ADMIN_USER=admin
PASSWORD_FILE="${EXAMPLES_HOME}/config/password.txt"

##################################################
# properties for the Derby Database
##################################################
DERBY_INSTALL=${SERVER_HOME}/javadb
DERBY_PORT=1527
DERBY_HOST=localhost
DERBY_USER=APP
DERBY_PWD=APP
DERBY_SYSTEM_HOME=${EXAMPLES_HOME}/database
DERBY_CLASSPATH=${DERBY_INSTALL}/lib/derby.jar;${DERBY_INSTALL}/lib/derbynet.jar;${DERBY_INSTALL}/lib/derbyclient.jar;${DERBY_INSTALL}/lib/derbytools.jar



ESSENTIALS_CLASSPATH=${SERVER_HOME}/lib/toplink-essentials.jar
SPRING_CLASSPATH=${EXAMPLES_HOME}/lib/spring.jar;${EXAMPLES_HOME}/lib/commons-logging.jar
J2EE_CLASSPATH=${SERVER_HOME}/lib/javaee.jar
CLIENT_CLASSPATH="${ESSENTIALS_CLASSPATH};${J2EE_CLASSPATH};${DERBY_CLASSPATH}

3 File - examples.html
<html>
<head><title>Pro EJB 3: Java Persistence API Examples</title></head>
<body>
<h1>Pro EJB 3: Java Persistence API Examples</h1>
<h3>Java SE Examples</h3>
The SE examples (Chapter 2) do not require a running server. Simply go to the chapter's
example folder and run the batch file for the example.


<h3>Java EE Examples</h3>
The other examples require a running application server. Go to the 'bin' folder and start
the Glassfish application server using the batch file (startserver.bat). Once started, go
to the desired chapter's example folder and build/deploy the application using the deploy.bat
batch file. Once that is done, come back to this page and click on the link of the desired
example. This will provide you with a web client to run the example.

  • Chapter 2: Getting Started

    • These examples demonstate the Java Persistence API in an SE environment. To run,
      go to the Chapter2 folder and run the batch file for the example. It provides both
      a simple interactive client to create/list/remove employees and a basic test like
      the one found in the chapter.


    • Currently, I am running examples from EJB 3 in action book, they are working fine using JBoss 4.2.2 using ant scripts upto chapters 12. These examples are from Pro EJB3 Java Persistence API.

      Thanks again for your input,

      Naveen Katoch
Ross Crockett
Ranch Hand

Joined: Aug 25, 2009
Posts: 30
Thanks Naveen,
I haven't used Pro EJB 3: Java Persistence API so i'm not familiar with there example format. Your post below though suggests that the Chapter 2 examples simply require you to run a batch file. Is there a *.bat file in that directory? Or do they mean an Ant script (hence output in your original post)?

Just looking at the details, maybe check if EXAMPLES_HOME should be "C:/EXAMPLES_HOME/" instead of "C:/EXAMPLES_HOME/examples".

Does your C:/EXAMPLES_HOME directory look something like:

EXAMPLES_HOME
|
+ examples
+ config
+ bin
+ lib

or is everything under C:/EXAMPLES_HOME/examples? Might just be a path issue...
nav katoch
Ranch Hand

Joined: May 02, 2008
Posts: 246

Hi Ross,

Thank you so much for your time. I reinstalled everything from the beginning and It's working now. Learned a lots by trying again and again with different ways.

Thanks again,

Naveen
 
 
subject: Anybody ever faced this problem running client of chapter 2 of pro ejb 3 java persistence api