Jetty Jndi Development Practice (UP)

Source: Internet
Author: User

Jetty Jndi Development Combat (ON) Chszs, all rights reserved, without consent, not reproduced. Blogger Home page: Http://blog.csdn.net/chszs, Jndi Introduction

Jndi, the Java naming and directory Interface,java naming and directory interface, is a standard Java naming system interface provided by Oracle, allowing Java clients to discover or query data and objects by name. The JNDI specification provides a standard set of APIs that are independent of the naming system, built on the drivers associated with the naming system, to help separate the application from the actual data source, so that regardless of whether the application accesses LDAP, RMI, DNS, or other directory services. such as data sources, mail servers, message queues, etc. can be found through Jndi, and Jndi's query strategy abstracts applications from external resources and makes external resources easier to configure.
This article details the use of Jndi queries in jetty. We first register a JDBC data source and then query and access this data source through Jndi. You can then see how the Jndi resources are configured in the standalone jetty.

Second, the development environment

The tools used in this article are listed below:
1) JDK 8.0.25
2) Maven 3.3.3
3) Eclipse JEE 4.5.0 (Mars edition)
4) Jetty 9.3.2
5) H2 Database Engine 1.4.188

Note that the H2 database can be run with a single jar package without additional installation.
Also, suppose we want to create a JCGEXAMLE data table, which has two columns, the ID column and the article_name column, respectively.

C:\jtools\h2\bin>java -cp h2-1.4.188.jar org.h2.tools.ServerTCP server running at tcp://192.168.1.103:9092 (only local connections)PG server running at pg://192.168.1.103:5435 (only local connections)Web Console server running at http://192.168.1.103:8082 (only local connections)

This command immediately launches the server mode of the H2 database and automatically opens the browser, connecting to the H2 Web console, allowing the user to create and configure the H2 database.

Select the Chinese (Simplified) language and fill in
JDBC Url:jdbc:h2:tcp://localhost/~/jcgdb
User name: SA
Click the Test Connection button to return to the "test succeeded" message. At this point, the H2 database engine automatically creates a database file named Jcgdb.mv.db in the file system's home directory, and then we can run the following script to create the data table Jcgexamle and insert two rows of records:

CREATE CACHED TABLE PUBLIC.JCGEXAMPLE(  ID INTEGER,  ARTICLE_NAME VARCHAR(255));insert into JCGEXAMPLE values(1,‘Jetty JNDI Example‘);insert into JCGEXAMPLE values(2,‘Jetty JMX Example‘);

So far, the database is ready.

Iii. Building a Demo project 1, creating a MAVEN project in the Eclipse environment

Group Id:com.ch.snippets.enterprise
Artifact Id:jetty-jndi-demo
Packaging:war

2. Add a Dependency package

Add the following dependency packages in the Pom.xml configuration file:
Org.eclipse.jetty:jetty-server
Org.eclipse.jetty:jetty-webapp
Org.eclipse.jetty:jetty-plus
Org.eclipse.jetty:jetty-jndi
Com.h2database:h2

The Pom.xml configuration file is as follows:

<project xmlns= "http://maven.apache.org/POM/4.0.0" xmlns:xsi= "Http://www.w3.org/2001/XMLSchema-instance" xsi: schemalocation= "http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" > < Modelversion>4.0.0</modelversion> <groupId>com.ch.snippets.enterprise</groupId> < Artifactid>jetty-jndi-demo</artifactid> <version>0.0.1-SNAPSHOT</version> <packaging> war</packaging> <dependencies> <dependency> <groupid>org.eclipse.jetty</gr Oupid> <artifactId>jetty-server</artifactId> <version>9.3.2.v20150730</versi            on> </dependency> <dependency> <groupId>org.eclipse.jetty</groupId>        <artifactId>jetty-webapp</artifactId> <version>9.3.2.v20150730</version> </dependency> <dependency> <groupid>org.eclipse.jetty</groupid> <artifactId>jetty-plus</artifactId> <ve rsion>>9.3.2.v20150730</version> </dependency> <dependency> &LT;GROUPID&G T;org.eclipse.jetty</groupid> <artifactId>jetty-jndi</artifactId> <version>& gt;9.3.2.v20150730</version> </dependency> <dependency> <groupid>com.h2da Tabase</groupid> <artifactId>h2</artifactId> <version>1.4.188</version&gt        ; </dependency> </dependencies></project>

Copyright NOTICE: This article for Bo Master Chszs original article, without Bo Master permission not reproduced.

Jetty Jndi Development Practice (UP)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.