Enterprise Java Development@TOPIC@
Add the following to your .m2/settings.xml file. This will allow you to resolve the exercise archetype and set a default database for the exercise.
<profiles> <profile> <id>webdev-repositories</id> <repositories> <repository> <id>webdev</id> <name>ejava webdev repository</name> <url>http://webdev.jhuep.com/~jcs/maven2</url> <releases> <enabled>true</enabled> <updatePolicy>never</updatePolicy> </releases> <snapshots> <enabled>false</enabled> </snapshots> </repository> <repository> <id>webdev-snapshot</id> <name>ejava webdev snapshot repository</name> <url>http://webdev.jhuep.com/~jcs/maven2-snapshot</url> <releases> <enabled>false</enabled> </releases> <snapshots> <enabled>true</enabled> <updatePolicy>daily</updatePolicy> </snapshots> </repository> </repositories> </profile> </profiles> <activeProfiles> <activeProfile>h2db</activeProfile> <!-- <activeProfile>h2srv</activeProfile> --> </activeProfiles>
Use the ejava.jpa:jpa-queryex-archetype to setup a new Maven project for this exercise. Activate the webdev-repositories profile (-Pwebdev-repositories) so that you can resolve the archetype off the Internet. The following should be run outside of the class example tree.
This archetype is specific to this exercise and is a different profile than what was used by the previous exercises.
$ mvn archetype:generate -B -DarchetypeGroupId=info.ejava.examples.jpa -DarchetypeArtifactId=jpa-queryex-archetype -DarchetypeVersion=5.0.0-SNAPSHOT -DgroupId=myorg.queryex -DartifactId=queryEx -Pwebdev-repositories INFO] ---------------------------------------------------------------------------- [INFO] Using following parameters for creating project from Archetype: jpa-queryex-archetype:5.0.0-SNAPSHOT [INFO] ---------------------------------------------------------------------------- [INFO] Parameter: groupId, Value: myorg.queryex [INFO] Parameter: artifactId, Value: queryEx [INFO] Parameter: version, Value: 1.0-SNAPSHOT [INFO] Parameter: package, Value: myorg.queryex [INFO] Parameter: packageInPathFormat, Value: myorg/queryex [INFO] Parameter: version, Value: 1.0-SNAPSHOT [INFO] Parameter: package, Value: myorg.queryex [INFO] Parameter: groupId, Value: myorg.queryex [INFO] Parameter: artifactId, Value: queryEx [INFO] Project created from Archetype in dir: /Users/jim/proj/784/queryEx [INFO] ------------------------------------------------------------------------ [INFO] BUILD SUCCESS [INFO] ------------------------------------------------------------------------ [INFO] Total time: 2.797 s [INFO] Finished at: 2018-08-18T14:47:41-04:00 [INFO] Final Memory: 15M/223M [INFO] ------------------------------------------------------------------------
You should now have an instantiated template for a JPA project
queryEx/ |-- pom.xml `-- src |-- main | `-- java | `-- myorg | `-- queryex | |-- Actor.java | |-- Director.java | |-- Movie.java | |-- MoviePK.java | |-- MovieRating.java | |-- MovieRole.java | |-- MovieRolePK.java | `-- Person.java `-- test |-- java | `-- myorg | `-- queryex | |-- BulkUpdateTest.java | |-- MovieFactory.java | |-- QueryBase.java | |-- QueryLocksTest.java | |-- QueryTest.java | `-- SQLQueryTest.java `-- resources |-- hibernate.properties |-- log4j.xml `-- META-INF `-- persistence.xml
Verify the instantiated template builds in your environment
Activate the h2db profile (and deactivate the h2srv profile) to use an embedded file as your database. This option does not require a server but is harder to inspect database state in between tests. Remember that the "!" character must be escaped ("\!") for bash shells.
queryEx> mvn clean test -Ph2db -P\!h2srv ... -HHH000401: using driver [org.h2.Driver] at URL [jdbc:h2:/Users/jim/proj/784/queryEx/target/h2db/ejava] ... [INFO] ------------------------------------------------------------------------ [INFO] BUILD SUCCESS [INFO] ------------------------------------------------------------------------
Start your database server
$ java -jar M2_REPO/com/h2database/h2/1.4.197/h2-1.4.197.jar
Activate the h2srv profile (and deactivate the h2db profile) to use a running H2 database server. This option provides more interaction with your database but does require the server to be running.
queryEx]$ mvn clean test -P\!h2db -Ph2srv ... -HHH000401: using driver [org.h2.Driver] at URL [jdbc:h2:tcp://127.0.0.1:9092/./h2db/ejava] ... [INFO] ------------------------------------------------------------------------ [INFO] BUILD SUCCESS [INFO] ------------------------------------------------------------------------
You may now import the instantiated template into Eclipse as an "Existing Maven Project"