ci228-database - University of Brighton

CI228 CatShop
Compiling & running
1. The Apache Derby database
‹
In these instructions the directory jdk_1.8.0_20 is
named after the version 'number' of the
distribution. Oracle tend to issue many new
versions of the JDK/ JRE each year. It is highly
likely that any version you download will have a
higher version number.
‹
Apache Derby is an open source relational
database implemented entirely in Java. It now
forms part of the normal JDK distribution.
‹
The Apache Derby database is installed in the
directory db in the top level of the Java JDK
directory hierarchy.
For example on windows 7 (64 bit) as used at the
University:
The 64 bit version of the JDK has Apache Derby
at:
c:\Program Files\Java\jdk_1.8.0_20\db
If you run a 32 bit version of windows then when
you install the 32 bit version of the JDK then
Apache Derby will also be at:
c:\Program Files\Java\jdk_1.8.0_20\db
Note:
Apache Derby is not part of the JRE.
© M A Smith University of Brighton
November 12, 2014
Page 1
Compiling & running
CI228 CatShop
1.1 32/ 64 bit versions of Java
‹
Some points
Do remember, the 64 bit version of Java will not
run (directly) on a 32 bit operating system.
Many browsers currently only come in a 32 bit
version, so you would need to separately install
the 32 bit version of the JRE for the browser, if
you install the 64 bit version of the JDK.
Of course this will change as more machines run a
64 bit operating system and 64 bit software.
© M A Smith University of Brighton
November 12, 2014
Page 2
Compiling & running
CI228 CatShop
2. Using the Apache Derby database
2.1 Using BlueJ on Windows
‹
To use the Apache Derby database, unzip the
BlueJ project jd3.zip into an empty directory in
your file system.
This will be the project directory that you will
open in BlueJ (Project -> Open Project).
In the resultant file hierarchy created, the file
DataBase.txt is used to select at runtime the
appropriate driver, to connect to the database. In
this 'version of the CatShop system it contains a
single line with the text Derby. When the
CatShop system is run code in the system will
read this file and know to select the Derby
database drive to use to connect to the database.
‹
Then in Tools -> Preferences -> Libraries
add the following libraries
DERBY_HOME\lib\derby.jar
DERBY_HOME\lib\derbytools.jar
Replacing DERBY_HOME with the path to the base
of the Derby database. This is in the Java JDK
installed files. For example at the University on
windows 7 (64 bit) it will be at:
c:\Program Files\Java\jdk_1.8.0_20\db
© M A Smith University of Brighton
November 12, 2014
Page 3
Compiling & running
CI228 CatShop
2.2 Using Eclipse on Windows
‹
To use the Apache Derby database, after
importing the jd3.tgz archive into the src
directory of an empty project.
Copy (^C) the file DataBase.txt (At package
level) and then Paste (^V) into the top level
directory of your project
(This level contains the 'directories' src and the
JRE System library).
In the resultant file hierarchy created, the file
DataBase.txt is used ay run time to select the
appropriate driver, to connect to the database. In
this 'version of the CatShop system it contains a
single line with the text Derby. When the
CatShop system is run code in the system will
read this file and know to select the Derby
database drive to connect to the database.
‹
Copy (^C) the directory Images (in the directory
src) and Paste (^V) into the same top level
directory as DataBase.txt
‹
Then in
Project -> Properties -> Java Build Path -> Libraries
Select Add external JARs and add the
libraries
DERBY_HOME\lib\derby.jar
DERBY_HOME\lib\derbytools.jar
Replacing DERBY_HOME with the path to the base
of the Derby database. This is in the Java JDK
installed files. For example at the University on
windows 7 (64 bit) it will be at:
c:\Program Files\Java\jdk_1.8.0_20\db
© M A Smith University of Brighton
November 12, 2014
Page 4
CI228 CatShop
Compiling & running
2.3 Project not compiling - file OrderTest.java
‹
In the package orders is the JUnit test
OrderTest.java Eclipse will not recognise this
initially as a JUnit test.
Copy (^C) the contents of the file
OrderTest.java and then delete this file
(OrderTest.java )
Now create a JUnit test in the same package
orders.
Select orders (click on package orders)
Right click and select new -> JUnit Test Case call
this OrderTest.
Now paste the code that you previously copied
over the default code in this Java class file.
© M A Smith University of Brighton
November 12, 2014
Page 5
Compiling & running
CI228 CatShop
2.4 Using BlueJ/Eclipse on Linux
‹
Follow the appropriate instructions for the IDE
you are using as above.
Except, use the appropriate Linux path for
installing the Jar files.
DERBY_HOME/lib/derby.jar
DERBY_HOME/lib/derbytools.jar
Replacing DERBY_HOME with the path to the base
of the Apache Derby database
© M A Smith University of Brighton
November 12, 2014
Page 6
CI228 CatShop
Compiling & running
2.5 To run the CatShop application (BlueJ & Eclipse)
‹
Start-up BlueJ/ Eclipse
First run Setup (In package clients)
This will create a database (or overwrite an
existing database) and populated with example
data to use in the CatShop application.
You can of course modify the program Setup to
change the initial values held in the database.
Now exit and close BlueJ/ Eclipse
‹
Start-up BlueJ/ Eclipse
Now run Main (In package clients)
This will run the CatShop application.
‹
Remember, you only need to run Setup (In
package clients) if you want to create a new
copy of the database that the CatShop application
uses.
Running the aplication Setup will delete any
previous held data.
© M A Smith University of Brighton
November 12, 2014
Page 7
CI228 CatShop
Compiling & running
3. Running from the command line
‹
This assumes that the Apache Derby database is
installed on your computer.
‹
That the java JDK is installed on your computer.
That you can run java & javac by typing there
names in any directory. This means that the bin
directory for the JDK is set in the PATH variable.
‹
That you have unpacked the CatShop distribution
jd3.tgz into your file system.
© M A Smith University of Brighton
November 12, 2014
Page 8
CI228 CatShop
Compiling & running
3.1 Using Windows
‹
The file cat_defs.bat will need editing to set
the environment variables DERBY_HOME and
JUNIT to where the JDK and JUnit files are
respectively.
‹
The file cat_compile.bat will compile the
applications and applet.
‹
The file cat_database.bat will create and
populate the database used by the application.
‹
The file cat_run.bat will run the system as a
single application.
‹
The file cat_run_dist.bat will run the system
as a distributed system. This is simulated on a
single machine with multiple independent
windows.
Press return only after the server has started
The file webCustomerClient.html when
loaded in a web browser will run the applet.
© M A Smith University of Brighton
November 12, 2014
Page 9
Compiling & running
CI228 CatShop
3.2 Using Unix/ Linux / cygwin
‹
The Makefile will need editing to set the
environment variables DERBY_HOME and JUNIT
to where the JDK and JUnit files are
respectively. In addition SEP should be set to the
appropriate separator.
‹
make compile
Will compile the applications and applet.
‹
make database
Will create and populate the database used by the
system.
‹
make run
Will run the system as a single application.
‹
make distributed
Will run the system as a distributed system. This
is simulated on a single machine with multiple
independent windows. Networking is used to
communicate between the separately executing
applications.
‹
The file webCustomerClient.html when
loaded in a web browser will run the applet.
© M A Smith University of Brighton
November 12, 2014
Page 10