在Linux Jetty环境下进行JNDI的开发图文教程
时间:2023-05-14 16:04:53
众所周知,JNDI是标准化的Java命名系统接口,在Jetty容器中,可以对JNDI进行编译和开发。也可以把JNDI的资源配置到Jetty中,那么如何操作呢?下面,我们一起来看看在Linux Jetty环境下进行JNDI的开发图文教程。
JNDI
一、开发环境
本文使用到的工具可列表如下:
1)JDK 8.0.25
2)Maven 3.3.3
3)Eclipse JEE 4.5.0(mars版)
4)Jetty 9.3.2
5)H2 Database Engine 1.4.188
注意,H2数据库可以通过单个JAR包运行,无需另外安装。
另外,假定我们要创建jcgexamle的数据表,它有两列,分别为ID列和ARTICLE_NAME列。
C:jtoolsh2in》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)
此命令立即启动H2数据库的服务器模式,并自动打开浏览器,连接到H2的Web控制台,让用户创建和配置H2数据库。
选择中文(简体)语言,并填入
JDBC URL:jdbc:h2:tcp://localhost/~/jcgdb
用户名:sa
点击测试连接按钮,返回“测试成功”的信息。此时,H2数据库引擎会自动在文件系统的home目录中创建名为jcgdb.mv.db的数据库文件,然后我们可以运行下面的脚本来创建数据表jcgexamle,并插入两行记录:
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’);
至此,数据库已经准备好了。
二、构建Demo项目
1、在Eclipse环境创建Maven项目
Group Id:com.ch.snippets.enterprise
Artifact Id:jetty-jndi-demo
Packaging:war
2、添加依赖包
在pom.xml配置文件中添加以下依赖包:
org.eclipse.jetty:jetty-server
org.eclipse.jetty:jetty-webapp
org.eclipse.jetty:jetty-plus
org.eclipse.jetty:jetty-jndi
com.h2database:h2
pom.xml配置文件具体如下:
《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》
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
在word中,如何将文字置于图片上方?
![](https://img.aspxhome.com/file/2023/8/35798_0s.jpg)
Win10用户账户控制怎么打开?Win10用户账户控制打不开解决方法
![](https://img.aspxhome.com/file/2023/28/a240535_0s.jpg)
如何在excel中插入欧元符号
word文档中的表格如何设置数字的小数位数
![](https://img.aspxhome.com/file/2023/9/31739_0s.png)
Excel中进行自然对数函数的操作方法
Win10打开Edge浏览器提示“糟糕!我们的连接似乎断了”怎么办?
![](https://img.aspxhome.com/file/2023/26/a224840_0s.jpg)
Win8.1 RTM 中按住电源键大约4秒会出现滑动关机
![](https://img.aspxhome.com/file/2023/29/a256444_0s.jpg)
Win10如何开启多核优化?Win10开启多核优化的方法
![](https://img.aspxhome.com/file/2023/3/52933_0s.png)
Win10助手小娜怎么关闭?Win10助手小娜关闭教程介绍
![](https://img.aspxhome.com/file/2023/4/51684_0s.png)
alipaladin64.sys无法从电脑上删除怎么办?
![](https://img.aspxhome.com/file/2023/30/a269883_0s.png)
Edge浏览器如何设置启动时默认打开新标签页?
![](https://img.aspxhome.com/file/2023/7/a329008_0s.jpg)
Win10卸载WiFi共享精灵后联网失败的解决方法
![](https://img.aspxhome.com/file/2023/26/a225982_0s.jpg)
轻松配置Windows7/Ubuntu9双系统
屏蔽机房壳体龙骨安装焊接技巧
![](https://img.aspxhome.com/file/2023/9/a342475_0s.jpg)
word2003的"绘图"工具栏的具体使用教程
![](https://img.aspxhome.com/file/2023/1/21101_0s.jpg)
英雄联盟分辨率调节后进不去游戏黑屏
![](https://img.aspxhome.com/file/2023/9/48439_0s.png)
word怎么快速制作一份收据? word收据的制作方法
![](https://img.aspxhome.com/file/2023/8/30178_0s.png)
excel表格超链接失效怎么处理
wps office怎么把添加字体?
![](https://img.aspxhome.com/file/2023/0/a168290_0s.png)
Mac特殊符号使用快捷方式
![](https://img.aspxhome.com/file/2023/5/a211445_0s.png)