How to develop JNDI in Linux Jetty environment

  

JNDI is a standardized Java naming system interface. In the Jetty container, JNDI can be compiled and developed. You can also configure JNDI resources into Jetty. Here's how to develop JNDI in the Linux system Jetty environment.

First, the development environment

The tools used in this article can be listed as follows:

1) JDK 8.0.25

2)Maven 3.3.3< Br>

3) Eclipse JEE 4.5.0 (mars version)

4) Jetty 9.3.2

5) H2 Database Engine 1.4.188

Note that The H2 database can be run through a single JAR package without additional installation.

Also, suppose we want to create a jcgexamle data table with two columns, the ID column and the ARTICLE_NAME column.

C:\\jtools\\h2\\bin"java -cp h2-1.4.188.jar org.h2.tools.Server

TCP 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 starts the server mode of the H2 database and automatically opens the browser to connect to the H2 web console, allowing the user to create and configure the H2 database.

Select Chinese (Simplified) language, and fill

JDBC URL: jdbc: h2: tcp: //localhost /~ /jcgdb

Username: Sa

Click the Test Connection button to return the message "Test Success". At this point, the H2 database engine will automatically create a database file named jcgdb.mv.db in the home directory of the file system, 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’);

At this point, the database is ready.

Second, build the Demo project

1, create 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 package to 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/groupId

artifactId jetty-server/artifactId

"version" 9.3.2.v20150730 "/version"

"/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"

"version" 9.3.2.v20150730 "/version"

"/dependency"

"dependency"

"groupId" org.eclipse.jetty "/groupId"

"artifactId" jetty-jndi "/artifactId"

"version" 9.3.2.v20150730 "/version"

"/dependency"

"dependency"

"groupId" com.h2database "/groupId 》

"artifactId" h2 "/artifactId"

"version" 1.4.188 "/version"

"/dependency"

"/dependencies

"/project"

The above is how to develop JNDI in the Linux Jetty environment. The resources defined in jetty need to be declared in web.xml. So jetty will map the resources in the default context to java:comp/env.

Copyright © Windows knowledge All Rights Reserved