chapter 1. installation and setup -...
TRANSCRIPT
-
1 / 18Prof. Youngchan KIM, Dept of Computer Engineering, Hanbat National University
Database Programming
Chapter 1. Installation and Setup
Gradle ( Ant)
HSQLDB
Hibernate Core
Project Hierarchy
-
2 / 18Prof. Youngchan KIM, Dept of Computer Engineering, Hanbat National University
Database Programming
Getting an Gradle Distribution
Why do I care?
– Ant vs Maven vs Gradle
How do I do that?
– http://www.gradle.org/
Download and unzipa binary release of Gradle tod:\javatool\gradle-2.6 folder
– gradle-2.6-all.zip
Add the bin directory to your path
– add “d:\javatool\gradle-2.6\bin” to PATH
-
3 / 18Prof. Youngchan KIM, Dept of Computer Engineering, Hanbat National University
Database Programming
Check Your Java, and Gradle Version
$ java –version
openjdk version "1.8.0_51"
OpenJDK Runtime Environment (build 1.8.0_51-b16)
OpenJDK 64-Bit Server VM (build 25.51-b03, mixed mode)
$ gradle –version
------------------------------------------------------------
Gradle 2.6
------------------------------------------------------------
Build time: 2015-08-10 13:15:06 UTC
Build number: none
Revision: 233bbf8e47c82f72cb898b3e0a96b85d0aad166e
Groovy: 2.3.10
Ant: Apache Ant(TM) version 1.9.3 compiled on December 23 2013
JVM: 1.8.0_51 (Oracle Corporation 25.51-b03)
OS: Linux 4.1.6-200.fc22.x86_64 amd64
-
4 / 18Prof. Youngchan KIM, Dept of Computer Engineering, Hanbat National University
Database Programming
Using the HSQLDB / H2 Database Engine
How do I do that?
– http://hsqldb.org/
– http://www.h2database.com/
When you build the examples in this book,
the ‘gradle’ will automatically download the HSQLDB and/or H2 JARs (and any other JARs you need)
from the Maven repository at http://search.maven.org/.
-
5 / 18Prof. Youngchan KIM, Dept of Computer Engineering, Hanbat National University
Database Programming
Using Hibernate Core
How do I do that?
– http://www.hibernate.org/
Our chosen release
– Hibernate Core
• 3.3.2.GA 3.6.10.Final 4.3.11.Final
– Hibernate Tools
• 3.2.4.GA
When you build the examples in this book,
the ‘gradle’ will automatically downloadthe Hibernate JARs (and any other JARs you need)
from the Maven repository.
-
6 / 18Prof. Youngchan KIM, Dept of Computer Engineering, Hanbat National University
Database Programming
Setting Up a Project Hierarchy for Gradle
How do I do that?
com.oreilly.hh
– The example classes we're going to createare all going to live in here com.oreilly.hh.
com.oreilly.hh.data
– We'll have our data beans in the com.oreilly.hh.data package
$ mkdir
$ cd
(Linux/Unix only)
$ mkdir -p src/{main,test}/{java,resources}
$ mkdir -p src/{main,test}/java/com/oreilly/hh/data
-
7 / 18Prof. Youngchan KIM, Dept of Computer Engineering, Hanbat National University
Database Programming
A quick test (Gradle build.gradle) …
apply plugin: 'java'
sourceSets {
main.resources.srcDir 'src/main/java'
test.resources.srcDir 'src/test/java'
}
repositories {
jcenter()
//mavenCentral()
}
dependencies {
compile 'org.hibernate:hibernate-core:3.6.+'
compile 'org.slf4j:slf4j-api:1.+'
runtime 'ch.qos.logback:logback-core:1.+'
runtime 'ch.qos.logback:logback-classic:1.+'
runtime 'org.javassist:javassist:3.+'
runtime 'org.hsqldb:hsqldb:2.+‘
runtime ‘com.h2database:h2:1.+'
testCompile 'junit:junit:4.+'
testCompile 'org.hamcrest:hamcrest-library:1.+'
}
task db( dependsOn: classes, type: JavaExec ) {
main = 'org.hsqldb.util.DatabaseManagerSwing'
args '--driver', 'org.hsqldb.jdbcDriver',
'--url', 'jdbc:hsqldb:file:build/music',
'--user', 'sa'
classpath = sourceSets.main.runtimeClasspath
}
-
8 / 18Prof. Youngchan KIM, Dept of Computer Engineering, Hanbat National University
Database Programming
A quick test (Dependency Search) …
-
9 / 18Prof. Youngchan KIM, Dept of Computer Engineering, Hanbat National University
Database Programming
A quick test (Dependency Search) …
-
10 / 18Prof. Youngchan KIM, Dept of Computer Engineering, Hanbat National University
Database Programming
A quick test (Dependency Search) …
-
11 / 18Prof. Youngchan KIM, Dept of Computer Engineering, Hanbat National University
Database Programming
A quick test (Gradle build.gradle) …
$ gradle db
:ch01:compileJava UP-TO-DATE
:ch01:processResources UP-TO-DATE
:ch01:classes UP-TO-DATE
:ch01:db
Download https://repo1.maven.org/maven2/org/hibernate/hibernate-
core/3.6.10.Final/hibernate-core-3.6.10.Final.jar
Download https://repo1.maven.org/maven2/org/javassist/javassist/3.18.2-
GA/javassist-3.18.2-GA.jar
... (repeating)
-
12 / 18Prof. Youngchan KIM, Dept of Computer Engineering, Hanbat National University
Database Programming
A quick test (hsqldb Database Files)
$ ls data
music.log music.properties music.script
-
13 / 18Prof. Youngchan KIM, Dept of Computer Engineering, Hanbat National University
Database Programming
Printing the dependency class path (Gradle build.gradle)
build.gradle:
task printClasspath println file.name }
}
$ gradle pprintClasspath
$ gradle clean
-
14 / 18Prof. Youngchan KIM, Dept of Computer Engineering, Hanbat National University
Database Programming
Exercise #1: Learn Gradle (ex01/build.gradle)
apply plugin: 'java'
repositories {
jcenter()
//mavenCentral()
}
dependencies {
compile 'org.slf4j:slf4j-api:1.+'
runtime 'ch.qos.logback:logback-classic:1.+'
testCompile 'junit:junit:4.11'
testCompile 'org.hamcrest:hamcrest-library:1.+'
}
test {
testLogging {
events "passed", "skipped", "failed", "standardOut", "standardError"
outputs.upToDateWhen {false}
exceptionFormat = 'full'
}
afterSuite { desc, result ->
if (!desc.parent) {
println "\nResults: ${result.resultType} (${result.testCount}
tests, " +
"${result.successfulTestCount} successes, " +
"${result.failedTestCount} failures, " +
"${result.skippedTestCount} skipped)"
} }
}
task helloworld(dependsOn: classes, type: JavaExec) {
main = 'exercise.HelloWorld'
classpath = sourceSets.main.runtimeClasspath
}
task slf4j(dependsOn: classes, type: JavaExec) {
main = 'exercise.Slf4jLogback'
classpath = sourceSets.main.runtimeClasspath
}
-
15 / 18Prof. Youngchan KIM, Dept of Computer Engineering, Hanbat National University
Database Programming
Exercise #1: Learn Gradle … (compile and run App)
$ cd ex1
$ gradle classes
$ gradle helloworld
:compileJava UP-TO-DATE
:processResources UP-TO-DATE
:classes UP-TO-DATE
:helloworld
Hello World!
BUILD SUCCESSFUL
$ gradle slf4j
-
16 / 18Prof. Youngchan KIM, Dept of Computer Engineering, Hanbat National University
Database Programming
Exercise #1: Learn Gradle … (JUnit)
$ gradle test
:processTestResources UP-TO-DATE
:testClasses
:test
. . .
exercise.JUnitTest STANDARD_OUT
@BeforeClass setUpClass()
exercise.JUnitTest > testSomethingElse STANDARD_OUT
@Before setUp()
@Test tesetSomethingElse()
@After tearDown()
exercise.JUnitTest > testSomethingElse PASSED
exercise.JUnitTest > testOneThing STANDARD_OUT
@Before setUp()
@Test tesetOneThing()
@After tearDown()
exercise.JUnitTest > testOneThing PASSED
exercise.JUnitTest > testAnotherThing STANDARD_OUT
@Before setUp()
@Test tesetAnotherThing()
@After tearDown()
exercise.JUnitTest > testAnotherThing PASSED
exercise.JUnitTest STANDARD_OUT
@AfterClass tearDownClass()
BUILD SUCCESSFUL
-
17 / 18Prof. Youngchan KIM, Dept of Computer Engineering, Hanbat National University
Database Programming
Exercise #1: Learn Gradle … (JUnit and Hamcrest)
$ gradle test
:processTestResources UP-TO-DATE
:testClasses
:test
exercise.HamcrestTest > testNumber PASSED
exercise.HamcrestTest > testCollection PASSED
. . .
BUILD SUCCESSFUL
-
18 / 18Prof. Youngchan KIM, Dept of Computer Engineering, Hanbat National University
Database Programming
Materials for Further Study
Ant Home
– http://ant.apache.org/
– http://ant.apache.org/manual/index.html
Maven Home
– http://maven.apache.org/
Gradle Home
– http://www.gradle.org/