The ServletJDBCEngine sample contains a server definition for basic servlet support, and illustrates a simple datasource definition using an included configuration file. It uses Apache Derby (an open source relational database). Also included is a servlet which gets a connection to the database using the defined datasource, creates a table, inserts some data, retrieves the data, and prints the data out to the browser.
Once the server is running, the application will be available under http://localhost:9080/JDBCApp.
- Clone this project and import into Eclipse as an 'Existing Maven Project'.
- Right-click the project and select Run As > Maven Clean.
- Right-click the project and select Run As > Maven Install.
- Right-click the project and select Run As -> Run on Server.
- You should see the following in the console:
CWWKZ0001I: Application JDBCApp started in XX.XX seconds.
In your browser, enter the URL for the application: http://localhost:9080/JDBCApp. In your browser, you should see the message:Text retrieved from database is: myHomeCounty
Eclipse will use the Eclipse Buildship Gradle Plugin for Gradle project management and accessibility to tasks.
- Go to Help > Eclipse Marketplace > Install Buildship Gradle Integration 2.0
- Clone this project and import into Eclipse as an 'Existing Gradle Project'.
- Go to Window > Show View > Other > Gradle Executions & Gradle Tasks
- Go to Gradle Tasks view and run
clean
in build folder, thenbuild
in build folder, thenlibertyStart
in liberty folder. - You should see the following in the console:
CWWKZ0001I: Application JDBCApp started in XX.XX seconds.
In your browser, enter the URL for the application: http://localhost:9080/JDBCApp. In your browser, you should see the message:Text retrieved from database is: myHomeCounty
This project can be built with Apache Maven. The project uses the Liberty Maven Plug-in to automatically download and install the Liberty Java EE Web Profile 7 from Maven Central. The Liberty Maven Plug-in is also used to create, configure, and run the application on the Liberty server.
Use the following steps to run the application with Maven:
-
Execute full Maven build. The Liberty Maven Plug-in will download and install the Liberty server.
$ mvn clean install
-
To run the server with the Servlet sample execute:
$ mvn liberty:run-server
This project can also be built and run using Gradle. The provided build.gradle
file applies the Liberty Gradle Plug-in and is configured to automatically download and install the Liberty Java EE Web Profile 7 runtime from Maven Central. The Liberty Gradle Plug-in also has tasks that create, configure, and run applications on a Liberty server.
Use the following steps to run the application with the Gradle wrapper. (Windows machines use gradlew.bat
):
-
Execute the full Gradle build. The Liberty Gradle Plug-in will download and install the Liberty server.
$ ./gradlew clean build
-
To start the server with the JDBCApp sample run:
$ ./gradlew libertyStart
Alternatively, execute the run command:
$ ./gradlew libertyRun --no-daemon
-
To stop the server, execute:
$ ./gradlew libertyStop
Please refer to the Liberty Gradle Plug-in repository for documentation and configuration examples for the plug-in.
© Copyright IBM Corporation 2017.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.