Hi All, 

I would like to run a JPA Derby packaged tutorial in MySQL. This pre-configured 
exercise runs fine with Derby using Ant built script. However, it would failed 
to build after having attempted to replace the Derby properties with MySQL. 
Below are some configuration files used by this exercise: 

1.       C:\ProJPA2\examples\Chapter2\employeeService\build.xml   
2.       <?xml version="1.0" encoding="iso-8859-1"?>   
3.         
4.       <project name="example" default="run">   
5.           
6.           <property file="../../../config/common.properties"/>   
7.           <import file="../../../config/common.xml" />   
8.         
9.           
<target name="run" depends="init,build,run_sql,run_client,clean" /> 
  
10.   
    <target name="interactive_client" depends="init,build,run_sql,run_interactive_client,clean" />
   
11.     
12.       <target name="init">   
13.           <property name="example_name" value="employeeService_ch2" />   
14.           <property name="DB_NAME" value="EmpServDB" />   
15.       </target>   
16.     
17.       <target name="build" depends="setup,build_jar">   
18.            <javac srcdir="src/client" destdir="build/client" debug="on">   
19.               <classpath>   
20.                  <pathelement path="${J2EE_CLASSPATH}" />   
21.                  <pathelement location="dist/lib/${example_name}.jar" />   
22.               </classpath>   
23.           </javac>   
24.           <jar jarfile="dist/${example_name}_client.jar" update="yes">   
25.               <fileset dir="build/client"/>   
26.           </jar>   
27.       </target>   
28.          
29.       <target name="run_client">   
30.       <java classname="examples.client.EmployeeTest" fork="true">   
31.   
            <sysproperty key="derby.system.home" value="${DERBY_SYSTEM_HOME}"/> 
  
32.               <classpath>   
33.                   <pathelement location="dist/lib/${example_name}.jar" />   
34.                   
<pathelement location="dist/${example_name}_client.jar" /> 
  
35.                   <pathelement path="${CLIENT_CLASSPATH}"/>   
36.               </classpath>   
37.           </java>   
38.       </target>   
39.     
40.       <target name="run_interactive_client" depends="setup">   
41.       
<java classname="examples.client.EmployeeTestInteractive" fork="true"> 
  
42.   
            <sysproperty key="derby.system.home" value="${DERBY_SYSTEM_HOME}"/> 
  
43.               <sysproperty key="ddl-generation" value="dropandcreate"/>   
44.               <classpath>   
45.                   <pathelement location="dist/lib/${example_name}.jar" />   
46.                   
<pathelement location="dist/${example_name}_client.jar" /> 
  
47.                   <pathelement path="${CLIENT_CLASSPATH}"/>   
48.               </classpath>   
49.           </java>   
50.       </target>   
51.   </project>   
52.     
53.   C:\ProJPA2\Config\common.properties   
54.     
55.   ##################################################   
56.   # Installation properties    
57.   ##################################################   
58.     
59.   EXAMPLES_HOME="C:/ProJPA2"  
60.   SERVER_HOME=C:/glassfish3   
61.     
62.   ##################################################   
63.   # Glassfish properties   
64.   ##################################################   
65.     
66.   ADMIN_USER=admin   
67.     
68.   PASSWORD_PREFIX=   
69.   PASSWORD_FILE=   
70.     
71.   # Uncomment out the following 2 lines if GlassFish was installed with an  
  
72.   # admin password, and enter the password in the password.txt file.   
73.   #PASSWORD_PREFIX=--passwordfile   
74.   #PASSWORD_FILE="${EXAMPLES_HOME}/config/password.txt"  
75.     
76.   ##################################################   
77.   # Derby Database properties    
78.   ##################################################   
79.     
80.   DERBY_INSTALL=${SERVER_HOME}/javadb   
81.   DERBY_PORT=1527  
82.   DERBY_HOST=localhost   
83.   DERBY_USER=APP   
84.   DERBY_PWD=APP   
85.   DERBY_SYSTEM_HOME=${EXAMPLES_HOME}/database   
86.   
DERBY_CLASSPATH=${DERBY_INSTALL}/lib/derby.jar;${DERBY_INSTALL}/lib/derbynet.jar;${DERBY_INSTALL}/lib/derbyclient.jar;${DERBY_INSTALL}/lib/derbytools.jar
   
87.     
88.   ##################################################   
89.   # Additional library properties    
90.   ##################################################   
91.     
92.   
ECLIPSELINK_CLASSPATH=${SERVER_HOME}/glassfish/modules/javax.persistence.jar;${SERVER_HOME}/glassfish/modules/org.eclipse.persistence.oracle.jar;${SERVER_HOME}/glassfish/modules/org.eclipse.persistence.core.jar;${SERVER_HOME}/glassfish/modules/org.eclipse.persistence.jpa.jar;${SERVER_HOME}/glassfish/modules/org.eclipse.persistence.asm.jar;${SERVER_HOME}/glassfish/modules/org.eclipse.persistence.antlr.jar;${SERVER_HOME}/glassfish/modules/org.eclipse.persistence.jpa.modelgen.jar;
   
93.   
SPRING_CLASSPATH=${EXAMPLES_HOME}/lib/spring.jar;${EXAMPLES_HOME}/lib/commons-logging.jar
   
94.   J2EE_CLASSPATH=${SERVER_HOME}/glassfish/lib/javaee.jar   
95.   JPA_CLASSPATH=${SERVER_HOME}/glassfish/modules/javax.persistence.jar   
96.   
#CLIENT_CLASSPATH=${ECLIPSELINK_CLASSPATH};${J2EE_CLASSPATH};${DERBY_CLASSPATH} 
  
97.   
CLIENT_CLASSPATH=${ECLIPSELINK_CLASSPATH};${J2EE_CLASSPATH};E:/Oracle/glassfish-persistence-installer-v2.1-b60.jar;E:/Oracle/mysql-connector-java-5.1.6-bin.jar;
   
98.     
99.   C:\ProJPA2\examples\Chapter2\employeeService\run.bat   
100.                        @echo OFF   
101.                        call %ANT_HOME%/bin/ant %1  
102.                          
103.                        
C:\ProJPA2\examples\Chapter2\employeeService\etc\persistence\META-INF\persistence.xml
   
104.                          
105.                        
                                     Changed the content from   
106.                          
107.                        
<persistence xmlns="http://java.sun.com/xml/ns/persistence" version="1.0";>   
108.                        
    <persistence-unit name="EmployeeService" transaction-type="RESOURCE_LOCAL"> 
  
109.                                <class>examples.model.Employee</class>   
110.                                <validation-mode>NONE</validation-mode>   
111.                                <properties>   
112.                        
            <property name="javax.persistence.jdbc.driver" value="org.apache.derby.jdbc.ClientDriver"/>
   
113.                        
            <property name="javax.persistence.jdbc.url" value="jdbc:derby://localhost:1527/EmpServDB;create=true"/>
   
114.                        
            <property name="javax.persistence.jdbc.user" value="APP"/>   
115.                        
            <property name="javax.persistence.jdbc.password" value="APP"/>   
116.                        
            <!-- enable this property to see SQL and other logging -->   
117.                        
            <!-- property name="eclipselink.logging.level" value="FINE"/ -->   
118.                                </properties>   
119.                            </persistence-unit>   
120.                        </persistence>   
121.                          
122.                                                                          
to 
  
123.                          
124.                        <?xml version="1.0" encoding="UTF-8"?>   
125.                        
<persistence version="2.0" xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd";>
   
126.                        
  <persistence-unit name="EmployeeService" transaction-type="RESOURCE_LOCAL">   
127.                        
    <provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>   
128.                            <shared-cache-mode>ALL</shared-cache-mode>   
129.                            <validation-mode>NONE</validation-mode>   
130.                            <properties>   
131.                        
      <property name="javax.persistence.jdbc.driver" value="com.mysql.jdbc.Driver"/>
   
132.                        
      <property name="javax.persistence.jdbc.url" value="jdbc:mysql://localhost:3306/EmployeeDB"/>
   
133.                        
      <property name="javax.persistence.jdbc.password" value="abcdefg"/>   
134.                        
      <property name="javax.persistence.jdbc.user" value="applicationuser"/>   
135.                        
      <property name="eclipselink.ddl-generation" value="drop-and-create-tables"/>
   
136.                        
      <!--  enable this property to see SQL and other logging  -->   
137.                        
      <property name="eclipselink.logging.level" value="FINE"/>   
138.                            </properties>   
139.                          </persistence-unit>   
140.                        </persistence>  
 
Also tried to include the latest EclipseJPA 
(E:/Oracle/glassfish-persistence-installer-v2.1-b60.jar) & MySQL JDBCdriver 
(E:/Oracle/mysql-connector-java-5.1.6-bin.jar) in CLIENT_CLASSPATH of 
common.properties file. This same example would run properly after having built 
it into Netbeans 6.9.1 project which include these jar files in its CLASSPATH. 


Some system environmental variables used by Java & Ant are: 
ANT_HOME=C:\Ant\apache-ant-1.8.2 
CLASSPATH=.;C:\Program Files\Java\jre6\lib\ext\QTJava.zip 
JAVA_HOME=C:\Program Files\Java\jdk1.6.0_20 
Path=C:\Program 
Files\Java\jdk1.6.0_20\bin;C:\Ant\apache-ant-1.8.2\bin;C:\Program 
Files\MySQL\MySQL Server 5.1\bin;C:\glassfish3\bin;C:\glassfish3\glassfish\bin 


However, the following exception kept occurring and I am can do with some 
advice 
on how to correctly update these configuration files in order to persist the 
data into MySQL: 

1.       C:\ProJPA2\examples\Chapter2\employeeService>dir   
2.        Volume in drive C has no label.   
3.        Volume Serial Number is 6473-5938  
4.         
5.        Directory of C:\ProJPA2\examples\Chapter2\employeeService   
6.         
7.       10/02/2011  05:31 PM    <DIR>          .   
8.       10/02/2011  05:31 PM    <DIR>          ..   
9.       30/01/2010  11:03 PM             2,022 build - original.bak   
10.   30/01/2010  11:03 PM             2,022 build.xml   
11.   01/02/2011  04:33 PM    <DIR>          etc   
12.   09/02/2011  05:49 PM    <DIR>          lib   
13.   09/02/2011  05:21 PM                42 run.bat   
14.   07/01/2010  06:02 PM                52 runInteractive.bat   
15.   01/02/2011  04:33 PM    <DIR>          src   
16.                  4 File(s)          4,138 bytes   
17.                  5 Dir(s)  13,030,256,640 bytes free   
18.     
19.   C:\ProJPA2\examples\Chapter2\employeeService>run.bat   
20.   Buildfile: C:\ProJPA2\examples\Chapter2\employeeService\build.xml   
21.     
22.   init:   
23.     
24.   setup:   
25.   
    [mkdir] Created dir: C:\ProJPA2\examples\Chapter2\employeeService\build\model
   
26.   
    [mkdir] Created dir: C:\ProJPA2\examples\Chapter2\employeeService\build\client
   
27.   
    [mkdir] Created dir: C:\ProJPA2\examples\Chapter2\employeeService\build\test
 
  
28.   
    [mkdir] Created dir: C:\ProJPA2\examples\Chapter2\employeeService\build\servlet\WEB-INF\classes
   
29.       
[mkdir] Created dir: C:\ProJPA2\examples\Chapter2\employeeService\dist 
  
30.   
    [mkdir] Created dir: C:\ProJPA2\examples\Chapter2\employeeService\dist\lib 
  
31.     
32.   build_jar:   
33.   
     [copy] Copying 2 files to C:\ProJPA2\examples\Chapter2\employeeService\build\model
   
34.   
    [javac] C:\ProJPA2\config\common.xml:38: warning: 'includeantruntime' was not set, defaulting to build.sysclasspath=last; set to false for repeatable builds
   
35.   
    [javac] Compiling 2 source files to C:\ProJPA2\examples\Chapter2\employeeService\build\model
   
36.   
    [javac] Note: C:\ProJPA2\examples\Chapter2\employeeService\src\model\examples\model\EmployeeService.java uses unchecked or unsafe operations.
   
37.       [javac] Note: Recompile with -Xlint:unchecked for details.   
38.   
      [jar] Building jar: C:\ProJPA2\examples\Chapter2\employeeService\dist\lib\employeeService_ch2.jar
   
39.     
40.   build:   
41.   
    [javac] C:\ProJPA2\examples\Chapter2\employeeService\build.xml:17: warning: 'includeantruntime' was not set, defaulting to build.sysclasspath=last; set to false for repeatable builds
   
42.   
    [javac] Compiling 2 source files to C:\ProJPA2\examples\Chapter2\employeeService\build\client
   
43.   
      [jar] Building jar: C:\ProJPA2\examples\Chapter2\employeeService\dist\employeeService_ch2_client.jar
   
44.     
45.   run_sql:   
46.     
47.   BUILD FAILED   
48.   
C:\ProJPA2\config\common.xml:144: java.sql.SQLNonTransientConnectionException: java.net.ConnectException : Error connecting to server localhost on port 152  

49.   7 with message Connection refused: connect.   
50.   
        at org.apache.derby.client.am.SQLExceptionFactory40.getSQLException(Unknown Source)
   
51.   
        at org.apache.derby.client.am.SqlException.getSQLException(Unknown Source)
   
52.           at org.apache.derby.jdbc.ClientDriver.connect(Unknown Source)   
53.   
        at org.apache.tools.ant.taskdefs.JDBCTask.getConnection(JDBCTask.java:370)
   
54.   
        at org.apache.tools.ant.taskdefs.SQLExec.getConnection(SQLExec.java:942)
 
  
55.           
at org.apache.tools.ant.taskdefs.SQLExec.execute(SQLExec.java:614) 
  
56.   
        at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:291) 
  
57.           at sun.reflect.GeneratedMethodAccessor4.invoke(Unknown Source)   
58.   
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
   
59.           at java.lang.reflect.Method.invoke(Method.java:597)   
60.   
        at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:106)
   
61.           at org.apache.tools.ant.Task.perform(Task.java:348)   
62.           at org.apache.tools.ant.Target.execute(Target.java:390)   
63.           at org.apache.tools.ant.Target.performTasks(Target.java:411)   
64.   
        at org.apache.tools.ant.Project.executeSortedTargets(Project.java:1399) 
  
65.           at org.apache.tools.ant.Project.executeTarget(Project.java:1368) 
  
66.   
        at org.apache.tools.ant.helper.DefaultExecutor.executeTargets(DefaultExecutor.java:41)
   
67.           at org.apache.tools.ant.Project.executeTargets(Project.java:1251) 
  
68.           at org.apache.tools.ant.Main.runBuild(Main.java:809)   
69.           at org.apache.tools.ant.Main.startAnt(Main.java:217)   
70.           at org.apache.tools.ant.launch.Launcher.run(Launcher.java:280)   
71.           at org.apache.tools.ant.launch.Launcher.main(Launcher.java:109)   
72.   
Caused by: org.apache.derby.client.am.DisconnectException: java.net.ConnectException : Error connecting to server localhost on port 1527 with message Connection refused: connect.
   
73.           at org.apache.derby.client.net.NetAgent.<init>(Unknown Source)   
74.   
        at org.apache.derby.client.net.NetConnection.newAgent_(Unknown Source) 
  
75.           at org.apache.derby.client.am.Connection.<init>(Unknown Source)   
76.   
        at org.apache.derby.client.net.NetConnection.<init>(Unknown Source)   
77.   
        at org.apache.derby.client.net.NetConnection40.<init>(Unknown Source)   
78.   
        at org.apache.derby.client.net.ClientJDBCObjectFactoryImpl40.newNetConnection(Unknown Source)
   
79.           ... 20 more   
80.   Caused by: java.net.ConnectException: Connection refused: connect   
81.           at java.net.PlainSocketImpl.socketConnect(Native Method)   
82.           at java.net.PlainSocketImpl.doConnect(PlainSocketImpl.java:333)   
83.   
        at java.net.PlainSocketImpl.connectToAddress(PlainSocketImpl.java:195) 
  
84.           at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:182)   
85.           at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:366)   
86.           at java.net.Socket.connect(Socket.java:529)   
87.           at java.net.Socket.connect(Socket.java:478)   
88.           at java.net.Socket.<init>(Socket.java:375)   
89.           at java.net.Socket.<init>(Socket.java:189)   
90.   
        at javax.net.DefaultSocketFactory.createSocket(SocketFactory.java:206) 
  
91.   
        at org.apache.derby.client.net.OpenSocketAction.run(Unknown Source)   
92.           at java.security.AccessController.doPrivileged(Native Method)   
93.           ... 26 more  
 
The issue is how to replace Derbyproperties & driver with MySQL equivalents. 

C:\ProJPA2\examples\Chapter2\employeeService\etc\sql\db.sql is made up of: 

DROP TABLE EMPLOYEE; 
CREATE TABLE EMPLOYEE (ID INTEGER NOT NULL, NAME VARCHAR(255), SALARY BIGINT, 
NUMBER INTEGER, PRIMARY KEY (ID)); 


Also C:\ProJPA2\examples\Chapter2\employeeService\lib is made up of the 
following files: 


eclipselink.jar, 
glassfish-persistence-installer-v2.1-b60.jar, 
mysql-connector-java-5.1.6-bin.jar.
 
I am running JDK1.6.0_20, GF3.1, Ant 1.8.2 on Windows XP. 

Your suggestion would be much appreciated. 

Thanks, 

Jack 




---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscr...@ant.apache.org
For additional commands, e-mail: user-h...@ant.apache.org

Reply via email to