{"id":26385,"date":"2015-08-25T11:00:18","date_gmt":"2015-08-25T08:00:18","guid":{"rendered":"http:\/\/examples.javacodegeeks.com\/?p=26385"},"modified":"2019-04-10T13:06:48","modified_gmt":"2019-04-10T10:06:48","slug":"jetty-jndi-example","status":"publish","type":"post","link":"https:\/\/examples.javacodegeeks.com\/java-development\/enterprise-java\/jetty\/jetty-jndi-example\/","title":{"rendered":"Jetty JNDI Example"},"content":{"rendered":"<p>The <b>Java Naming and Directory Interface<\/b> (<b>JNDI<\/b>) is a Java API for a directory service that allows Java clients to discover and lookup data and objects via name. Data sources, Mail Servers or Messaging queues are among the common objects that can be discovered through JNDI. JNDI lookup strategy abstracts applications from the external resources and makes them more configurable.<\/p>\n<p>In this example, we are going to enable Jetty for JNDI lookups. As in the previous examples, we will start with embedded Jetty and programmatically enable JNDI lookups. We will register a JDBC datasource and demonstrate how we can lookup and access this datasource through JNDI. Thereafter we will see how JNDI resources can be configured in a Standalone Jetty.\n<\/p>\n<h2>1. Environment<\/h2>\n<p>In the example, following programming environment will be used:<\/p>\n<ul>\n<li>Java 8 (Java 7 is also OK)<\/li>\n<li>Maven 3.x.y<\/li>\n<li>Eclipse Luna(as the IDE)<\/li>\n<li>Jetty v9.2.11 (In Embedded Jetty example, we will add Jetty libraries through Maven)<\/li>\n<li>H2 Database v1.4.x<\/li>\n<\/ul>\n<p>As mentioned above, &nbsp;we are going to register a JDBC datasource to the JNDI. &nbsp;In this example, we haven chosen H2 database, which is very convenient for prototyping. But any other database platform can be used as well.<\/p>\n<p>H2 runs through a single JAR file, which can be obtained from central <a href=\"http:\/\/mvnrepository.com\/artifact\/com.h2database\/h2\"> Maven Repository<\/a>.<\/p>\n<h2>2. Structure of the Example<\/h2>\n<p>In this example, we assume that we have JCG Example records that are stored in an H2 database. There is a single table named <code>JCGEXAMPLE<\/code> with only two columns (<code>ID<\/code> and <code>ARTICLE_NAME<\/code>). For simplicity we have skipped other types of integrity&nbsp;and database constraints. We will query content of this table through a Servlet deployed in a Jetty web application. We will access the datasource through a JNDI lookup.<\/p>\n<h2>3. Setting the H2 Database<\/h2>\n<p>As we have mentioned earlier, H2 is very convenient for prototyping and development environments. It is very easy&nbsp;to have a running H2 database once we have the JAR file . All we have to do is, running the simple shell command in the directory of the JAR file.<\/p>\n<pre class=\"brush:bash\">java -cp h2*.jar org.h2.tools.Server<\/pre>\n<p>This command immediately starts an H2 in server mode. In addition to this, it fires a browser window that gives us a Web based console to create and configure H2 databases.<\/p>\n<p><figure id=\"attachment_26389\" aria-describedby=\"caption-attachment-26389\" style=\"width: 678px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2015\/08\/jnd1.jpg\"><img decoding=\"async\" class=\"size-full wp-image-26389\" src=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2015\/08\/jnd1.jpg\" alt=\"H2 Web Console\" width=\"678\" height=\"509\" srcset=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2015\/08\/jnd1.jpg 678w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2015\/08\/jnd1-300x225.jpg 300w\" sizes=\"(max-width: 678px) 100vw, 678px\" \/><\/a><figcaption id=\"caption-attachment-26389\" class=\"wp-caption-text\">H2 Web Console<\/figcaption><\/figure><\/p>\n<p>On the browser window, we can connect the database altering the following infomation:<\/p>\n<ul>\n<li><strong>JDBC URL:<\/strong> jdbc:h2:tcp:\/\/localhost\/~\/jcgdb<\/li>\n<li><strong>User Name:<\/strong> sa<\/li>\n<\/ul>\n<p>If it is the first time that we connect to this url, H2 creates a database file named <i>jcgdb.mv.db<\/i> in our home directory and opens a console that enables us to execute SQL scripts.<\/p>\n<p>We can create our <code>JCGEXAMPLE<\/code> table running the following SQL command:<\/p>\n<pre class=\"brush:sql\">CREATE CACHED TABLE PUBLIC.JCGEXAMPLE(\n  ID INTEGER,\n  ARTICLE_NAME VARCHAR(255)\n)\n<\/pre>\n<p>Then we insert two rows to this table:<\/p>\n<pre class=\"brush:sql\">insert into JCGEXAMPLE values( 1,'Jetty JNDI Example');\ninsert into JCGEXAMPLE values(2,'Jetty JMX Example');\n<\/pre>\n<p>Now our database is ready with one table and two rows, which will suffice for this example.<\/p>\n<h2>4. JNDI in Embedded Jetty<\/h2>\n<h3>4.1 Creating the Maven Project in Eclipse<\/h3>\n<p>We will create the Maven project in Eclipse, applying the steps below:<\/p>\n<ol>\n<li>Go to File -&gt; New -&gt;Other -&gt; Maven Project<\/li>\n<li>Tick Create a simple project and press \u201cNext\u201d.<\/li>\n<li>Enter groupId as: <em>com.javacodegeeks.snippets.enterprise<\/em><\/li>\n<li>Enter artifactId as: <em>jetty-jndi-example<\/em><\/li>\n<li>Select packaging as \u201c<em>war<\/em>\u201d.<\/li>\n<li>Press \u201cFinish\u201d.<\/li>\n<\/ol>\n<p>After creating our project, we are going to add following dependencies to our <i>pom.xml<\/i>:<\/p>\n<ol>\n<li>org.eclipse.jetty:jetty-server<\/li>\n<li>org.eclipse.jetty:jetty-webapp<\/li>\n<li>org.eclipse.jetty:jetty-plus<\/li>\n<li>org.eclipse.jetty:jetty-jndi<\/li>\n<li>com.h2database:h2<\/li>\n<\/ol>\n<p>The first two dependencies are common for almost all embedded Jetty applications. <i>jetty-plus<\/i> and <i>jetty-jndi<\/i> are required for JNDI lookups. Finally, <i>h2<\/i> is required for the &nbsp;H2 database driver and datasource.<div style=\"display:inline-block; margin: 15px 0;\"> <div id=\"adngin-JavaCodeGeeks_incontent_video-0\" style=\"display:inline-block;\"><\/div> <\/div><\/p>\n<p>After adding these, the dependencies section of our pom looks like:<\/p>\n<pre class=\"brush:xml\">\t&lt;dependencies&gt;\n\t\t&lt;dependency&gt;\n\t\t\t&lt;groupId&gt;org.eclipse.jetty&lt;\/groupId&gt;\n\t\t\t&lt;artifactId&gt;jetty-server&lt;\/artifactId&gt;\n\t\t\t&lt;version&gt;9.2.11.v20150529&lt;\/version&gt;\n\t\t&lt;\/dependency&gt;\n\n\t\t&lt;dependency&gt;\n\t\t\t&lt;groupId&gt;org.eclipse.jetty&lt;\/groupId&gt;\n\t\t\t&lt;artifactId&gt;jetty-webapp&lt;\/artifactId&gt;\n\t\t\t&lt;version&gt;9.2.11.v20150529&lt;\/version&gt;\n\n\t\t&lt;\/dependency&gt;\n\n\t\t&lt;dependency&gt;\n\t\t\t&lt;groupId&gt;org.eclipse.jetty&lt;\/groupId&gt;\n\t\t\t&lt;artifactId&gt;jetty-plus&lt;\/artifactId&gt;\n\t\t\t&lt;version&gt;9.2.11.v20150529&lt;\/version&gt;\n\t\t&lt;\/dependency&gt;\n\n\t\t&lt;dependency&gt;\n\t\t\t&lt;groupId&gt;org.eclipse.jetty&lt;\/groupId&gt;\n\t\t\t&lt;artifactId&gt;jetty-jndi&lt;\/artifactId&gt;\n\t\t\t&lt;version&gt;9.2.11.v20150529&lt;\/version&gt;\n\t\t&lt;\/dependency&gt;\n\n\n\t\t&lt;dependency&gt;\n\t\t\t&lt;groupId&gt;com.h2database&lt;\/groupId&gt;\n\t\t\t&lt;artifactId&gt;h2&lt;\/artifactId&gt;\n\t\t\t&lt;version&gt;1.4.188&lt;\/version&gt;\n\t\t&lt;\/dependency&gt;\n\n\t&lt;\/dependencies&gt;\n<\/pre>\n<h3>4.2 Registering resources in JNDI<\/h3>\n<p>In embedded Jetty, we register our dependencies to the server programmatically. In order to keep things simple, we will run our Server through the main Java class, which is named <code>JettyJndiExampleMain<\/code>. In our main class, we will initialize a Jetty Server, append a web application context and register a datasource for JNDI.<\/p>\n<p>The source code of <code>JettyJndiExampleMain<\/code> decorated with source comments is below:<\/p>\n<p><span style=\"text-decoration: underline\"><em>JettyJndiExampleMain.java<\/em><\/span><\/p>\n<pre class=\"brush:java\">package com.javacodegeeks.snippets.enterprise.jettyjndi;\n\nimport org.eclipse.jetty.server.Server;\nimport org.eclipse.jetty.util.resource.Resource;\nimport org.eclipse.jetty.webapp.WebAppContext;\nimport org.eclipse.jetty.xml.XmlConfiguration;\nimport org.h2.jdbcx.JdbcDataSource;\n\npublic class JettyJndiExampleMain {\n\n\tpublic static void main(String[] args) {\n\t\ttry {\n\t\t\t\/\/ 1.We are creating the service\n\t\t\tServer server = new Server(8080);\n\n\t\t\t\/\/ 2.We are enabling Jetty-plus configuration\n\t\t\torg.eclipse.jetty.webapp.Configuration.ClassList classlist = org.eclipse.jetty.webapp.Configuration.ClassList.setServerDefault(server);\n\t\t\tclasslist.addAfter(\"org.eclipse.jetty.webapp.FragmentConfiguration\", \"org.eclipse.jetty.plus.webapp.EnvConfiguration\", \"org.eclipse.jetty.plus.webapp.PlusConfiguration\");\n\n\t\t\t\/\/ 3.We are creating the web-application context\n\t\t\tWebAppContext ctx = new WebAppContext();\n\t\t\tctx.setResourceBase(\"src\/main\/webapp\");\n\t\t\tctx.setContextPath(\"\/jetty-jndi-example\");\n\n\t\t\t\/\/ 4.We are creating the data-source here\n\t\t\tJdbcDataSource dataSource = new JdbcDataSource();\n\t\t\tdataSource.setUrl(\"jdbc:h2:tcp:\/\/localhost\/~\/jcgdb\");\n\t\t\tdataSource.setUser(\"sa\");\n\n\t\t\t\/\/ 5.Here we are registring the datasource for our server\n\t\t\tnew org.eclipse.jetty.plus.jndi.Resource(server, \"jdbc\/jcgDS\", dataSource);\n\n\t\t\t\/\/ 6.Handler setting and application registration code\n\t\t\tserver.setHandler(ctx);\n\t\t\tserver.start();\n\t\t\tserver.join();\n\t\t} catch (Exception exc) {\n\t\t\texc.printStackTrace();\n\t\t}\n\n\t}\n}\n\n<\/pre>\n<ol>\n<li>In the first step, we create a server for port 8080.<\/li>\n<li>In step 2, we enable Jetty-plus configuration which is required for additional Jetty features which include JNDI.<\/li>\n<li>Step 3 is the part where we initialize a web application with the context path \u2018jetty-jndi-example\u2019<\/li>\n<li>In Step 4, we define the H2 Datasource for the database we have created in the previous section.<\/li>\n<li>In Step 5, we register the data source to the server with the name \u201c<i>jdbc\/jcgDS<\/i>\u201d.<\/li>\n<li>After step 6, we attach the web application to the server and start the server.<\/li>\n<\/ol>\n<h3>4.3 Configuring the Web Application<\/h3>\n<p>Our web application is a simple web application, with a Servlet that queries the database and returns the result as the HTTP response.<\/p>\n<p>The web application can be configured following the steps below:<\/p>\n<ol>\n<li>Create the directory <i>src\/main\/webapp<\/i> (if not exists)<\/li>\n<li>Create the directory <i>WEB-INF<\/i> under <i>src\/main\/webapp.<\/i><\/li>\n<li>Create web.xml file under <i>src\/main\/webapp\/WEB-INF<\/i> (The content of web.xml will be presented below.)<\/li>\n<li>Implement the <code>JndiExampleServlet<\/code> which queries the datasource.<\/li>\n<\/ol>\n<p>Our <i>web.xml<\/i> file looks like as follows:<\/p>\n<p><span style=\"text-decoration: underline\"><em>web.xml<\/em><\/span><\/p>\n<pre class=\"brush:xml\">&lt;web-app xmlns=\"http:\/\/java.sun.com\/xml\/ns\/javaee\" xmlns:xsi=\"http:\/\/www.w3.org\/2001\/XMLSchema-instance\"\n\txsi:schemaLocation=\"http:\/\/java.sun.com\/xml\/ns\/javaee http:\/\/java.sun.com\/xml\/ns\/javaee\/web-app_2_5.xsd\"\n\tversion=\"2.5\"&gt;\n\t&lt;display-name&gt;JSP Example Application&lt;\/display-name&gt;\n\n\t&lt;servlet&gt;\n\t\t&lt;servlet-name&gt;jndiservlet&lt;\/servlet-name&gt;\n\t\t&lt;servlet-class&gt;com.javacodegeeks.snippets.enterprise.jettyjndi.JndiExampleServlet&lt;\/servlet-class&gt;\n\n\t&lt;\/servlet&gt;\n\n\t&lt;servlet-mapping&gt;\n\t\t&lt;servlet-name&gt;jndiservlet&lt;\/servlet-name&gt;\n\t\t&lt;url-pattern&gt;\/*&lt;\/url-pattern&gt;\n\t&lt;\/servlet-mapping&gt;\n\n\t&lt;resource-ref&gt;\n\t\t&lt;res-ref-name&gt;jdbc\/jcgDS&lt;\/res-ref-name&gt;\n\t\t&lt;res-type&gt;org.h2.jdbcx.JdbcDataSource&lt;\/res-type&gt;\n\t\t&lt;res-auth&gt;Container&lt;\/res-auth&gt;\n\t&lt;\/resource-ref&gt;\n&lt;\/web-app&gt;\n<\/pre>\n<p>Here we have defined a Servlet named <code>JndiExampleServlet<\/code> and mapped it to the all URLs under our application. In the bottom part, we have mentioned the JNDI resource that we are going to use in this application.[ulp id=&#8217;xFHGZUmgemwCMrAR&#8217;]<\/p>\n<p><code>JndiExampleServlet<\/code> is a simple Servlet that uses the class <code>DatabaseUtil<\/code> and returns the query result as the response.<\/p>\n<p><span style=\"text-decoration: underline\"><em>JndiExampleServlet.java<\/em><\/span><\/p>\n<pre class=\"brush:java\">package com.javacodegeeks.snippets.enterprise.jettyjndi;\n\nimport java.io.IOException;\nimport java.util.List;\n\nimport javax.servlet.ServletException;\nimport javax.servlet.http.HttpServlet;\nimport javax.servlet.http.HttpServletRequest;\nimport javax.servlet.http.HttpServletResponse;\n\nimport com.javacodegeeks.snippets.enterprise.jettyjndi.dbutils.DatabaseUtil;\n\npublic class JndiExampleServlet extends HttpServlet {\n\n\t@Override\n\tprotected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {\n\n\t\tList&lt;String&gt; articleNames = DatabaseUtil.getArticleNames();\n\t\tfor (String articleName : articleNames) {\n\t\t\tresp.getOutputStream().println(articleName);\n\t\t}\n\t}\n}\n<\/pre>\n<p><code>DatabaseUtil<\/code> is a Data Access Object like class that handles all database related operations including the JNDI lookup.<\/p>\n<p><span style=\"text-decoration: underline\"><em>DatabaseUtil.java<\/em><\/span><\/p>\n<pre class=\"brush:java\">package com.javacodegeeks.snippets.enterprise.jettyjndi.dbutils;\nimport java.sql.Connection;\nimport java.sql.ResultSet;\nimport java.sql.Statement;\nimport java.util.ArrayList;\nimport java.util.List;\n\nimport javax.naming.InitialContext;\nimport javax.sql.DataSource;\n\npublic class DatabaseUtil {\n\n\tpublic static void main(String[] args) {\n\n\t\tList&lt;String&gt; articleNames = getArticleNames();\n\n\t\tSystem.out.println(articleNames);\n\n\t}\n\n\tprivate static Connection createConnection() {\n\t\ttry {\n\t\t\tInitialContext ctx = new InitialContext();\n\t\t\t\/\/ Here we lookup the datasource with the name\n\t\t\t\/\/ \"java:comp\/env\/jdbc\/jcgDS\"\n\t\t\tDataSource ds = (DataSource) ctx.lookup(\"java:comp\/env\/jdbc\/jcgDS\");\n\t\t\treturn ds.getConnection();\n\t\t} catch (Exception exc) {\n\t\t\texc.printStackTrace();\n\t\t\treturn null;\n\t\t}\n\t}\n\n\tpublic static List&lt;String&gt; getArticleNames() {\n\n\t\tConnection conn = createConnection();\n\t\tList&lt;String&gt; articleNames = new ArrayList&lt;String&gt;();\n\t\ttry {\n\t\t\tStatement stmt = conn.createStatement();\n\t\t\tResultSet rs = stmt.executeQuery(\"SELECT * from JCGEXAMPLE\");\n\t\t\twhile (rs.next()) {\n\t\t\t\tString articleName = rs.getString(\"ARTICLE_NAME\");\n\t\t\t\tif (articleName != null) {\n\t\t\t\t\tarticleNames.add(articleName);\n\t\t\t\t}\n\t\t\t}\n\t\t\tconn.close();\n\n\t\t} catch (Exception e) {\n\t\t\tthrow new RuntimeException(e);\n\t\t}\n\t\treturn articleNames;\n\t}\n\n}\n<\/pre>\n<p>In the source code, you can see that, the datasource is retrieved from JNDI through the following snippet:<\/p>\n<pre class=\"brush:java\">InitialContext ctx = new InitialContext();\n\/\/ Here we lookup the datasource with the name \"java:comp\/env\/jdbc\/jcgDS\"\nDataSource ds = (DataSource) ctx.lookup(\"java:comp\/env\/jdbc\/jcgDS\");\n<\/pre>\n<p>You should notice that, JNDI configuration abstracts the datasource from the application so that our application does not know (and care) about the URL,username and password and driver and in most cases the vendor of the datasource.<\/p>\n<h3>4.4 Demo<\/h3>\n<p>When we run our main class and try to access <a href=\"http:\/\/localhost:8080\/jetty-jndi-example\">http:\/\/localhost:8080\/jetty-jndi-example<\/a>, we can see the Servlet response below:<\/p>\n<p><figure id=\"attachment_26412\" aria-describedby=\"caption-attachment-26412\" style=\"width: 666px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2015\/08\/jnd2.jpg\"><img decoding=\"async\" class=\"size-full wp-image-26412\" src=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2015\/08\/jnd2.jpg\" alt=\"Servlet Response\" width=\"666\" height=\"295\" srcset=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2015\/08\/jnd2.jpg 666w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2015\/08\/jnd2-300x133.jpg 300w\" sizes=\"(max-width: 666px) 100vw, 666px\" \/><\/a><figcaption id=\"caption-attachment-26412\" class=\"wp-caption-text\">Servlet Response<\/figcaption><\/figure><\/p>\n<h2>5. JNDI in Standalone Jetty<\/h2>\n<p>Configuring JNDI for standalone Jetty is easy. The required steps can be summarized as follows:<\/p>\n<ol>\n<li>Enable <i>jetty-plus<\/i> module in <i>JETTY_HOME\/start.ini<\/i> file.<\/li>\n<li>Add the datasource configuration in <i>JETTY_HOME\/jetty.xml<\/i> file.<\/li>\n<li>Copy the H2 jar und <i>er JETTY_HOME\/lib\/ext <\/i>directory.<\/li>\n<\/ol>\n<p>The module <i>jetty-plus<\/i> can be enabled by adding the following line to <i>start.ini:<\/i><\/p>\n<pre class=\"brush:bash\">--module=plus<\/pre>\n<p>The configuration for the datasource in <i>jetty.xml<\/i> file is as follows:<\/p>\n<pre class=\"brush:xml\">&lt;Configure id=\"Server\" class=\"org.eclipse.jetty.server.Server\"&gt;\n\n    &lt;New id=\"jcgdatasource\" class=\"org.eclipse.jetty.plus.jndi.Resource\"&gt;\n\t\t&lt;Arg&gt;&lt;\/Arg&gt;\n\t\t&lt;Arg&gt;jdbc\/jcgDS&lt;\/Arg&gt;\n\t\t&lt;Arg&gt;\n\t\t\t&lt;New class=\"org.h2.jdbcx.JdbcDataSource\"&gt;\n\t\t\t\t&lt;Set name=\"url\"&gt;jdbc:h2:tcp:\/\/localhost\/~\/jcgdb&lt;\/Set&gt;\n\t\t\t\t&lt;Set name=\"user\"&gt;sa&lt;\/Set&gt;\n\t\t\t&lt;\/New&gt;\n\t\t&lt;\/Arg&gt;\n\t&lt;\/New&gt;\n...\n&lt;\/Configure&gt;\n<\/pre>\n<p>After we copy H2 jar to<em> JETTY_HOME\/lib\/ext<\/em> and drop our application WAR under <em>JETTY_HOME\/webapps<\/em> directory; we can run Jetty and see that our application can seamlessly access the datasource through JNDI.<\/p>\n<h2>6. Final Remarks<\/h2>\n<p>JNDI provides a mechanism that enables application programmers to access objects through lookups. In this example. we have configured Jetty to access JNDI objects both for standalone and embedded modes of Jetty.<\/p>\n<div class=\"download\"><strong>Download<\/strong><br \/>\nYou can download the full source code of this example here: <strong><a href=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2015\/08\/jetty-jndi-example.zip\">Jetty JNDI Example<\/a><\/strong><\/div>\n","protected":false},"excerpt":{"rendered":"<p>The Java Naming and Directory Interface (JNDI) is a Java API for a directory service that allows Java clients to discover and lookup data and objects via name. Data sources, Mail Servers or Messaging queues are among the common objects that can be discovered through JNDI. JNDI lookup strategy abstracts applications from the external resources &hellip;<\/p>\n","protected":false},"author":54,"featured_media":1239,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[18],"tags":[1190,1189],"class_list":["post-26385","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-jetty","tag-datasource","tag-jndi"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v26.5 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Jetty JNDI Example - Java Code Geeks<\/title>\n<meta name=\"description\" content=\"The Java Naming and Directory Interface (JNDI) is a Java API for a directory service that allows Java clients to discover and lookup data and objects via\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/examples.javacodegeeks.com\/java-development\/enterprise-java\/jetty\/jetty-jndi-example\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Jetty JNDI Example - Java Code Geeks\" \/>\n<meta property=\"og:description\" content=\"The Java Naming and Directory Interface (JNDI) is a Java API for a directory service that allows Java clients to discover and lookup data and objects via\" \/>\n<meta property=\"og:url\" content=\"https:\/\/examples.javacodegeeks.com\/java-development\/enterprise-java\/jetty\/jetty-jndi-example\/\" \/>\n<meta property=\"og:site_name\" content=\"Examples Java Code Geeks\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/javacodegeeks\" \/>\n<meta property=\"article:published_time\" content=\"2015-08-25T08:00:18+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2019-04-10T10:06:48+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2012\/12\/codehaus-jetty-logo.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"150\" \/>\n\t<meta property=\"og:image:height\" content=\"150\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"Ibrahim Tasyurt\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@itasyurt\" \/>\n<meta name=\"twitter:site\" content=\"@javacodegeeks\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Ibrahim Tasyurt\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"10 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/java-development\/enterprise-java\/jetty\/jetty-jndi-example\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/java-development\/enterprise-java\/jetty\/jetty-jndi-example\/\"},\"author\":{\"name\":\"Ibrahim Tasyurt\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/#\/schema\/person\/b2b2c4a3762c4d2e0072b831fb6900f5\"},\"headline\":\"Jetty JNDI Example\",\"datePublished\":\"2015-08-25T08:00:18+00:00\",\"dateModified\":\"2019-04-10T10:06:48+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/java-development\/enterprise-java\/jetty\/jetty-jndi-example\/\"},\"wordCount\":1179,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/#organization\"},\"image\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/java-development\/enterprise-java\/jetty\/jetty-jndi-example\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2012\/12\/codehaus-jetty-logo.jpg\",\"keywords\":[\"datasource\",\"jndi\"],\"articleSection\":[\"jetty\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/examples.javacodegeeks.com\/java-development\/enterprise-java\/jetty\/jetty-jndi-example\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/java-development\/enterprise-java\/jetty\/jetty-jndi-example\/\",\"url\":\"https:\/\/examples.javacodegeeks.com\/java-development\/enterprise-java\/jetty\/jetty-jndi-example\/\",\"name\":\"Jetty JNDI Example - Java Code Geeks\",\"isPartOf\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/java-development\/enterprise-java\/jetty\/jetty-jndi-example\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/java-development\/enterprise-java\/jetty\/jetty-jndi-example\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2012\/12\/codehaus-jetty-logo.jpg\",\"datePublished\":\"2015-08-25T08:00:18+00:00\",\"dateModified\":\"2019-04-10T10:06:48+00:00\",\"description\":\"The Java Naming and Directory Interface (JNDI) is a Java API for a directory service that allows Java clients to discover and lookup data and objects via\",\"breadcrumb\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/java-development\/enterprise-java\/jetty\/jetty-jndi-example\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/examples.javacodegeeks.com\/java-development\/enterprise-java\/jetty\/jetty-jndi-example\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/java-development\/enterprise-java\/jetty\/jetty-jndi-example\/#primaryimage\",\"url\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2012\/12\/codehaus-jetty-logo.jpg\",\"contentUrl\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2012\/12\/codehaus-jetty-logo.jpg\",\"width\":150,\"height\":150},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/java-development\/enterprise-java\/jetty\/jetty-jndi-example\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/examples.javacodegeeks.com\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Java Development\",\"item\":\"https:\/\/examples.javacodegeeks.com\/category\/java-development\/\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"Enterprise Java\",\"item\":\"https:\/\/examples.javacodegeeks.com\/category\/java-development\/enterprise-java\/\"},{\"@type\":\"ListItem\",\"position\":4,\"name\":\"jetty\",\"item\":\"https:\/\/examples.javacodegeeks.com\/category\/java-development\/enterprise-java\/jetty\/\"},{\"@type\":\"ListItem\",\"position\":5,\"name\":\"Jetty JNDI Example\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/#website\",\"url\":\"https:\/\/examples.javacodegeeks.com\/\",\"name\":\"Java Code Geeks\",\"description\":\"Java Examples and Code Snippets\",\"publisher\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/#organization\"},\"alternateName\":\"JCG\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/examples.javacodegeeks.com\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/#organization\",\"name\":\"Exelixis Media P.C.\",\"url\":\"https:\/\/examples.javacodegeeks.com\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png\",\"contentUrl\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png\",\"width\":864,\"height\":246,\"caption\":\"Exelixis Media P.C.\"},\"image\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/www.facebook.com\/javacodegeeks\",\"https:\/\/x.com\/javacodegeeks\"]},{\"@type\":\"Person\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/#\/schema\/person\/b2b2c4a3762c4d2e0072b831fb6900f5\",\"name\":\"Ibrahim Tasyurt\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2015\/06\/Ibrahim-Tasyurt-96x96.jpg\",\"contentUrl\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2015\/06\/Ibrahim-Tasyurt-96x96.jpg\",\"caption\":\"Ibrahim Tasyurt\"},\"description\":\"Ibrahim is a Senior Software Engineer residing in Ankara,Turkey. He holds BSc and MS degrees in Computer Engineering from Middle East Technical University(METU). Throughout his professional carrier, he has worked in Enterprise Web Application projects for public sector and telecommunications domains. Java EE, Web Services and Enterprise Application Integration are the areas he is primarily involved with.\",\"sameAs\":[\"http:\/\/www.javacodegeeks.com\/\",\"https:\/\/x.com\/itasyurt\"],\"url\":\"https:\/\/examples.javacodegeeks.com\/author\/ibrahim-tasyurt\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Jetty JNDI Example - Java Code Geeks","description":"The Java Naming and Directory Interface (JNDI) is a Java API for a directory service that allows Java clients to discover and lookup data and objects via","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/examples.javacodegeeks.com\/java-development\/enterprise-java\/jetty\/jetty-jndi-example\/","og_locale":"en_US","og_type":"article","og_title":"Jetty JNDI Example - Java Code Geeks","og_description":"The Java Naming and Directory Interface (JNDI) is a Java API for a directory service that allows Java clients to discover and lookup data and objects via","og_url":"https:\/\/examples.javacodegeeks.com\/java-development\/enterprise-java\/jetty\/jetty-jndi-example\/","og_site_name":"Examples Java Code Geeks","article_publisher":"https:\/\/www.facebook.com\/javacodegeeks","article_published_time":"2015-08-25T08:00:18+00:00","article_modified_time":"2019-04-10T10:06:48+00:00","og_image":[{"width":150,"height":150,"url":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2012\/12\/codehaus-jetty-logo.jpg","type":"image\/jpeg"}],"author":"Ibrahim Tasyurt","twitter_card":"summary_large_image","twitter_creator":"@itasyurt","twitter_site":"@javacodegeeks","twitter_misc":{"Written by":"Ibrahim Tasyurt","Est. reading time":"10 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/examples.javacodegeeks.com\/java-development\/enterprise-java\/jetty\/jetty-jndi-example\/#article","isPartOf":{"@id":"https:\/\/examples.javacodegeeks.com\/java-development\/enterprise-java\/jetty\/jetty-jndi-example\/"},"author":{"name":"Ibrahim Tasyurt","@id":"https:\/\/examples.javacodegeeks.com\/#\/schema\/person\/b2b2c4a3762c4d2e0072b831fb6900f5"},"headline":"Jetty JNDI Example","datePublished":"2015-08-25T08:00:18+00:00","dateModified":"2019-04-10T10:06:48+00:00","mainEntityOfPage":{"@id":"https:\/\/examples.javacodegeeks.com\/java-development\/enterprise-java\/jetty\/jetty-jndi-example\/"},"wordCount":1179,"commentCount":0,"publisher":{"@id":"https:\/\/examples.javacodegeeks.com\/#organization"},"image":{"@id":"https:\/\/examples.javacodegeeks.com\/java-development\/enterprise-java\/jetty\/jetty-jndi-example\/#primaryimage"},"thumbnailUrl":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2012\/12\/codehaus-jetty-logo.jpg","keywords":["datasource","jndi"],"articleSection":["jetty"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/examples.javacodegeeks.com\/java-development\/enterprise-java\/jetty\/jetty-jndi-example\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/examples.javacodegeeks.com\/java-development\/enterprise-java\/jetty\/jetty-jndi-example\/","url":"https:\/\/examples.javacodegeeks.com\/java-development\/enterprise-java\/jetty\/jetty-jndi-example\/","name":"Jetty JNDI Example - Java Code Geeks","isPartOf":{"@id":"https:\/\/examples.javacodegeeks.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/examples.javacodegeeks.com\/java-development\/enterprise-java\/jetty\/jetty-jndi-example\/#primaryimage"},"image":{"@id":"https:\/\/examples.javacodegeeks.com\/java-development\/enterprise-java\/jetty\/jetty-jndi-example\/#primaryimage"},"thumbnailUrl":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2012\/12\/codehaus-jetty-logo.jpg","datePublished":"2015-08-25T08:00:18+00:00","dateModified":"2019-04-10T10:06:48+00:00","description":"The Java Naming and Directory Interface (JNDI) is a Java API for a directory service that allows Java clients to discover and lookup data and objects via","breadcrumb":{"@id":"https:\/\/examples.javacodegeeks.com\/java-development\/enterprise-java\/jetty\/jetty-jndi-example\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/examples.javacodegeeks.com\/java-development\/enterprise-java\/jetty\/jetty-jndi-example\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/examples.javacodegeeks.com\/java-development\/enterprise-java\/jetty\/jetty-jndi-example\/#primaryimage","url":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2012\/12\/codehaus-jetty-logo.jpg","contentUrl":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2012\/12\/codehaus-jetty-logo.jpg","width":150,"height":150},{"@type":"BreadcrumbList","@id":"https:\/\/examples.javacodegeeks.com\/java-development\/enterprise-java\/jetty\/jetty-jndi-example\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/examples.javacodegeeks.com\/"},{"@type":"ListItem","position":2,"name":"Java Development","item":"https:\/\/examples.javacodegeeks.com\/category\/java-development\/"},{"@type":"ListItem","position":3,"name":"Enterprise Java","item":"https:\/\/examples.javacodegeeks.com\/category\/java-development\/enterprise-java\/"},{"@type":"ListItem","position":4,"name":"jetty","item":"https:\/\/examples.javacodegeeks.com\/category\/java-development\/enterprise-java\/jetty\/"},{"@type":"ListItem","position":5,"name":"Jetty JNDI Example"}]},{"@type":"WebSite","@id":"https:\/\/examples.javacodegeeks.com\/#website","url":"https:\/\/examples.javacodegeeks.com\/","name":"Java Code Geeks","description":"Java Examples and Code Snippets","publisher":{"@id":"https:\/\/examples.javacodegeeks.com\/#organization"},"alternateName":"JCG","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/examples.javacodegeeks.com\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/examples.javacodegeeks.com\/#organization","name":"Exelixis Media P.C.","url":"https:\/\/examples.javacodegeeks.com\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/examples.javacodegeeks.com\/#\/schema\/logo\/image\/","url":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png","contentUrl":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png","width":864,"height":246,"caption":"Exelixis Media P.C."},"image":{"@id":"https:\/\/examples.javacodegeeks.com\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/javacodegeeks","https:\/\/x.com\/javacodegeeks"]},{"@type":"Person","@id":"https:\/\/examples.javacodegeeks.com\/#\/schema\/person\/b2b2c4a3762c4d2e0072b831fb6900f5","name":"Ibrahim Tasyurt","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/examples.javacodegeeks.com\/#\/schema\/person\/image\/","url":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2015\/06\/Ibrahim-Tasyurt-96x96.jpg","contentUrl":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2015\/06\/Ibrahim-Tasyurt-96x96.jpg","caption":"Ibrahim Tasyurt"},"description":"Ibrahim is a Senior Software Engineer residing in Ankara,Turkey. He holds BSc and MS degrees in Computer Engineering from Middle East Technical University(METU). Throughout his professional carrier, he has worked in Enterprise Web Application projects for public sector and telecommunications domains. Java EE, Web Services and Enterprise Application Integration are the areas he is primarily involved with.","sameAs":["http:\/\/www.javacodegeeks.com\/","https:\/\/x.com\/itasyurt"],"url":"https:\/\/examples.javacodegeeks.com\/author\/ibrahim-tasyurt\/"}]}},"_links":{"self":[{"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/posts\/26385","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/users\/54"}],"replies":[{"embeddable":true,"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/comments?post=26385"}],"version-history":[{"count":0,"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/posts\/26385\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/media\/1239"}],"wp:attachment":[{"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/media?parent=26385"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/categories?post=26385"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/tags?post=26385"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}