Inline ...
I'm using Jetty 12.1.1 and I'm trying to add a MailSession with JNDI.
I added a JNDI Datasource and it was simple, like the documentation said.
Tried the MailSession and I haven't been able to make it work.
--- First problem ---
I thought that adding the ee10-jndi module was supposed to add the
factories (jetty-ee10-jndi-12.1.1.jar). For some reason it is not adding it.
It is adding it to the ee10 environment.
When I do list-config the jar does not show up and when I start it gives
me a ClassNotFoundException which is understandable since its not
adding the jar. Don't know what I'm doing wrong.
The core layer has no Jakarta EE support.
The fact that it shows up in the ee10 environment is the correct thing.
I tried adding the jar manually to the lib/ext directory and it creates
the JNDI resource.
The lib/ext directory is for the core layer, which has no Jakarta EE support.
That's the wrong place for it.
-- Second problem ---
After creating the JNDI resource I cant get a jakarta.mail.Session
it returns the MailSessionReference. The only difference from the
example is that I'm creating the session in the server, not the webapp.
The documentation says:
"The web application performs a lookup for java:comp/env/mail/Session at runtime and obtains a jakarta.mail.Session that has the correct configuration to permit it to send email via SMTP."
I'm getting the MailSessionReference instead of a jakarta.mail.Session like the documentation says.
Hope someone can tell me what I'm doing wrong.
My JNDI config looks like this:
<New class="org.eclipse.jetty.plus.jndi.Resource">
<Arg></Arg>
<Arg>mail/Session</Arg>
<Arg>
<New class="org.eclipse.jetty.ee10.jndi.factories.MailSessionReference">
<Set name="user">???</Set>
<Set name="password">
???</Set> <Set name="properties">
<New class="java.util.Properties">
<Put name="mail.smtp.host">
???</Put> <Put name="mail.from">
???</Put> <Put name="mail.debug">true</Put>
</New>
</Set>
</New>
</Arg>
</New>
This configuration exists in the ee10 layer, more specifically in your webapp's configuration.
Here's an example setup ...
$ mkdir demos-12-ee10
$ cd demos-12-ee10
$ java -jar ~/code/jetty/distros/jetty-home-12.1.1/start.jar --add-modules=http,ee10-deploy,ee10-demo-jndi
INFO : mkdir ${jetty.base}/start.d
..(snip)..
INFO : Base directory was modified
$ tree -F
./
├── environments/
├── lib/
│ ├── ee10/
│ │ ├── jakarta.activation-api-2.1.3.jar
│ │ ├── jakarta.mail-api-2.1.3.jar
│ │ └── jetty-servlet5-demo-mock-resources-12.1.1.jar
│ └── ext/
├── resources/
│ └── jetty-logging.properties
├── start.d/
│ ├── bytebufferpool.ini
│ ├── deployer-standard.ini
│ ├── deployment-scanner.ini
│ ├── ee10-demo-jndi.ini
│ ├── ee10-deploy.ini
│ ├── ee10-webapp.ini
│ ├── ee-webapp.ini
│ ├── http-config.ini
│ ├── http.ini
│ ├── scheduler.ini
│ ├── server.ini
│ ├── sessions.ini
│ └── threadpool.ini
└── webapps/
├── ee10-demo-jndi.properties
├── ee10-demo-jndi.war
└── ee10-demo-jndi.xml
This is a common setup.
Now let's take a look at where org.eclipse.jetty.ee10.jndi.factories.MailSessionReference is setup ...
$ cat webapps/ee10-demo-jndi.xml
<?xml version="1.0"?><!DOCTYPE Configure PUBLIC "-//Jetty//Configure//EN" "https://jetty.org/configure_10_0.dtd">
<!-- =============================================================== -->
<!-- Configure the test-jndi webapp -->
<!-- =============================================================== -->
<Configure id="wac" class="org.eclipse.jetty.ee10.webapp.WebAppContext">
<New id="tx" class="org.eclipse.jetty.plus.jndi.Transaction">
<Arg><Property name="environment" default="ee10"/></Arg>
<Arg>
<New class="org.example.MockUserTransaction" />
</Arg>
</New>
<Set name="contextPath">/ee10-test-jndi</Set>
<Set name="war"><Property name="jetty.webapps" default="." />/ee10-demo-jndi.war
</Set>
<Set name="extractWAR">true</Set>
<Set name="copyWebDir">false</Set>
<Set name="configurationDiscovered">true</Set>
<!-- Define an env entry with ee10 environment scope for java:comp/env -->
<New id="woggle" class="org.eclipse.jetty.plus.jndi.EnvEntry">
<Arg>
<Property name="environment" default="ee10"/>
</Arg>
<Arg>woggle</Arg>
<Arg type="java.lang.Integer">4000</Arg>
<Arg type="boolean">false</Arg>
</New>
<!-- Define an env entry with webapp scope for java:comp/env -->
<New id="wiggle" class="org.eclipse.jetty.plus.jndi.EnvEntry">
<Arg>
<Ref refid="wac" />
</Arg>
<Arg>wiggle</Arg>
<Arg type="java.lang.Double">100</Arg>
<Arg type="boolean">true</Arg>
</New>
<!-- Mail Session setup -->
<New id="xxxmail" class="org.eclipse.jetty.plus.jndi.Resource">
<Arg>
<Ref refid="wac" />
</Arg>
<Arg>mail/Session</Arg>
<Arg>
<New class="org.eclipse.jetty.ee10.jndi.factories.MailSessionReference">
<Set name="user">CHANGE-ME</Set>
<Set name="password">CHANGE-ME</Set>
<Set name="properties">
<New class="java.util.Properties">
<Put name="mail.smtp.auth">false</Put> <!-- change to true if you want to authenticate -->
<Put name="mail.smtp.host">CHANGE-ME</Put>
<Put name="mail.from">CHANGE-ME</Put>
<Put name="mail.debug">false</Put>
</New>
</Set>
</New>
</Arg>
</New>
<!-- A mock DataSource -->
<New id="mydatasource" class="org.eclipse.jetty.plus.jndi.Resource">
<Arg>
<Ref refid="wac" />
</Arg>
<Arg>jdbc/mydatasource</Arg>
<Arg>
<New class="org.example.MockDataSource" />
</Arg>
</New>
</Configure>
This is the context specific XML configuration file for the webapp at id "ee10-demo-jndi" at the configured context-path of "/ee10-test-jndi"
You probably noticed that we didn't manually declare the "ee10-jndi" module on the command line.
And that it isn't listed in the start.d/ directory as well.
That's because it's a transitive dependency of `${jetty.home}/modules/ee10-demo-jndi.mod`
We could have specified `ee10-jndi` on the command line, in fact I probably should have.
Lets take alook at the configuration.
$ java -jar ~/code/jetty/distros/jetty-home-12.1.1/start.jar --list-config
Enabled Modules:
----------------
0) resources transitive provider of resources for logging-jetty
1) logging/slf4j transitive provider of logging/slf4j for logging-jetty
dynamic dependency of logging-jetty
2) logging-jetty transitive provider of logging for threadpool
transitive provider of logging for bytebufferpool
transitive provider of logging for scheduler
3) bytebufferpool ${jetty.base}/start.d/bytebufferpool.ini
4) ext transitive provider of ext for ee10-demo-jndi
5) http-config ${jetty.base}/start.d/http-config.ini
6) scheduler ${jetty.base}/start.d/scheduler.ini
7) threadpool ${jetty.base}/start.d/threadpool.ini
8) server ${jetty.base}/start.d/server.ini
9) annotations transitive provider of annotations for ee10-annotations
10) deployer-standard ${jetty.base}/start.d/deployer-standard.ini
11) deployment-scanner ${jetty.base}/start.d/deployment-scanner.ini
12) sessions ${jetty.base}/start.d/sessions.ini
13) ee10-servlet transitive provider of ee10-servlet for ee10-webapp
transitive provider of ee10-servlet for ee10-security
14) security transitive provider of security for ee10-security
15) ee10-security transitive provider of ee10-security for ee10-webapp
transitive provider of ee10-security for ee10-plus
16) ee-webapp ${jetty.base}/start.d/ee-webapp.ini
17) ee10-webapp ${jetty.base}/start.d/ee10-webapp.ini
18) jndi transitive provider of jndi for ee10-plus
19) plus transitive provider of plus for ee10-plus
20) ee10-plus transitive provider of ee10-plus for ee10-demo-jndi
21) ee10-annotations transitive provider of ee10-annotations for ee10-demo-mock-resources
22) jdbc transitive provider of jdbc for ee10-demo-jndi
23) ee10-demo-mock-resources transitive provider of ee10-demo-mock-resources for ee10-demo-jndi
24) ee10-deploy ${jetty.base}/start.d/ee10-deploy.ini
25) ee10-jndi transitive provider of ee10-jndi for ee10-demo-jndi
26) ee10-demo-jndi ${jetty.base}/start.d/ee10-demo-jndi.ini
27) http ${jetty.base}/start.d/http.ini
JVM Version & Properties:
-------------------------
java.home = /home/joakim/java/jvm/jdk-17.0.15+6
java.vm.vendor = Eclipse Adoptium
java.vm.version = 17.0.15+6
java.vm.name = OpenJDK 64-Bit Server VM
java.vm.info = mixed mode, sharing
java.runtime.name = OpenJDK Runtime Environment
java.runtime.version = 17.0.15+6
java.io.tmpdir = /tmp
user.dir = /home/joakim/code/jetty/distros/bases/demos-12-ee10
user.language = en
user.country = US
Jetty Version & Properties:
---------------------------
jetty.version = 12.1.1
jetty.tag.version = jetty-12.1.1
jetty.build = b7068950f9afa5f1df80e46053eda1d982895b03
jetty.home = /home/joakim/code/jetty/distros/jetty-home-12.1.1
jetty.base = /home/joakim/code/jetty/distros/bases/demos-12-ee10
Config Search Order:
--------------------
<command-line>
${jetty.base} -> /home/joakim/code/jetty/distros/bases/demos-12-ee10
${jetty.home} -> /home/joakim/code/jetty/distros/jetty-home-12.1.1
System Properties:
------------------
(no system properties specified)
Properties: Jetty
-----------------
asm.version = 9.8
java.version = 17.0.15
java.version.platform = 17
jetty.base = /home/joakim/code/jetty/distros/bases/demos-12-ee10
jetty.base.uri = file:///home/joakim/code/jetty/distros/bases/demos-12-ee10
jetty.home = /home/joakim/code/jetty/distros/jetty-home-12.1.1
jetty.home.uri = file:///home/joakim/code/jetty/distros/jetty-home-12.1.1
jetty.webapp.addHiddenClasses = org.eclipse.jetty.logging.,${jetty.home.uri}/lib/logging/,org.slf4j.
runtime.feature.alpn = true
slf4j.version = 2.0.17
Classpath: Jetty
----------------
Version Information on 19 entries in the classpath.
Note: order presented here is how they would appear on the classpath.
changes to the --module=name command line options will be reflected here.
0: (dir) | ${jetty.base}/resources
1: 2.0.17 | ${jetty.home}/lib/logging/slf4j-api-2.0.17.jar | https://opensource.org/license/mit
2: 12.1.1 | ${jetty.home}/lib/logging/jetty-slf4j-impl-12.1.1.jar | EPL-2.0 OR Apache-2.0
3: 12.1.1 | ${jetty.home}/lib/jetty-http-12.1.1.jar | EPL-2.0 OR Apache-2.0
4: 12.1.1 | ${jetty.home}/lib/jetty-util-12.1.1.jar | EPL-2.0 OR Apache-2.0
5: 12.1.1 | ${jetty.home}/lib/jetty-server-12.1.1.jar | EPL-2.0 OR Apache-2.0
6: 12.1.1 | ${jetty.home}/lib/jetty-xml-12.1.1.jar | EPL-2.0 OR Apache-2.0
7: 12.1.1 | ${jetty.home}/lib/jetty-io-12.1.1.jar | EPL-2.0 OR Apache-2.0
8: 12.1.1 | ${jetty.home}/lib/jetty-annotations-12.1.1.jar | EPL-2.0 OR Apache-2.0
9: 9.8 | ${jetty.home}/lib/annotations/asm-9.8.jar | BSD-3-Clause;link=https://asm.ow2.io/LICENSE.txt
10: 9.8 | ${jetty.home}/lib/annotations/asm-analysis-9.8.jar | BSD-3-Clause;link=https://asm.ow2.io/LICENSE.txt
11: 9.8 | ${jetty.home}/lib/annotations/asm-commons-9.8.jar | BSD-3-Clause;link=https://asm.ow2.io/LICENSE.txt
12: 9.8 | ${jetty.home}/lib/annotations/asm-tree-9.8.jar | BSD-3-Clause;link=https://asm.ow2.io/LICENSE.txt
13: 12.1.1 | ${jetty.home}/lib/jetty-deploy-12.1.1.jar | EPL-2.0 OR Apache-2.0
14: 12.1.1 | ${jetty.home}/lib/jetty-session-12.1.1.jar | EPL-2.0 OR Apache-2.0
15: 12.1.1 | ${jetty.home}/lib/jetty-security-12.1.1.jar | EPL-2.0 OR Apache-2.0
16: 12.1.1 | ${jetty.home}/lib/jetty-ee-webapp-12.1.1.jar | EPL-2.0 OR Apache-2.0
17: 12.1.1 | ${jetty.home}/lib/jetty-jndi-12.1.1.jar | EPL-2.0 OR Apache-2.0
18: 12.1.1 | ${jetty.home}/lib/jetty-plus-12.1.1.jar | EPL-2.0 OR Apache-2.0
Active XMLs: Jetty
------------------
${jetty.home}/etc/jetty-bytebufferpool.xml
${jetty.home}/etc/jetty-http-config.xml
${jetty.home}/etc/jetty-scheduler.xml
${jetty.home}/etc/jetty-threadpool.xml
${jetty.home}/etc/jetty.xml
${jetty.home}/etc/jetty-deployer-standard.xml
${jetty.home}/etc/jetty-deployment-scanner.xml
${jetty.home}/etc/sessions/id-manager.xml
${jetty.home}/etc/jetty-ee-webapp.xml
${jetty.home}/etc/jetty-http.xml
Properties: ee10
----------------
(no properties specified)
Classpath: ee10
---------------
Version Information on 15 entries in the classpath.
Note: order presented here is how they would appear on the classpath.
changes to the --module=name command line options will be reflected here.
0: 6.0.0 | ${jetty.home}/lib/jakarta.servlet-api-6.0.0.jar | http://www.eclipse.org/legal/epl-2.0, https://www.gnu.org/software/classpath/license.html
1: 12.1.1 | ${jetty.home}/lib/jetty-ee10-servlet-12.1.1.jar | EPL-2.0 OR Apache-2.0
2: 12.1.1 | ${jetty.home}/lib/jetty-ee10-webapp-12.1.1.jar | EPL-2.0 OR Apache-2.0
3: 12.1.1 | ${jetty.home}/lib/jetty-ee10-plus-12.1.1.jar | EPL-2.0 OR Apache-2.0
4: 2.0.1 | ${jetty.home}/lib/jakarta.transaction-api-2.0.1.jar | http://www.eclipse.org/legal/epl-2.0, https://www.gnu.org/software/classpath/license.html
5: 2.1.0 | ${jetty.home}/lib/jakarta.interceptor-api-2.1.0.jar | http://www.eclipse.org/legal/epl-2.0, https://www.gnu.org/software/classpath/license.html
6: 4.0.1 | ${jetty.home}/lib/jakarta.enterprise.cdi-api-4.0.1.jar | https://www.apache.org/licenses/LICENSE-2.0
7: 2.0 | ${jetty.home}/lib/jakarta.inject-api-2.0.1.jar | http://www.apache.org/licenses/LICENSE-2.0.txt
8: 4.0.1 | ${jetty.home}/lib/jakarta.enterprise.lang-model-4.0.1.jar | https://repository.jboss.org/licenses/apache-2.0.txt
9: 12.1.1 | ${jetty.home}/lib/jetty-ee10-annotations-12.1.1.jar | EPL-2.0 OR Apache-2.0
10: 2.1.1 | ${jetty.home}/lib/ee10-annotations/jakarta.annotation-api-2.1.1.jar | http://www.eclipse.org/legal/epl-2.0, https://www.gnu.org/software/classpath/license.html
11: 12.1.1 | ${jetty.base}/lib/ee10/jetty-servlet5-demo-mock-resources-12.1.1.jar | EPL-2.0 OR Apache-2.0
12: 12.1.1 | ${jetty.home}/lib/jetty-ee10-jndi-12.1.1.jar | EPL-2.0 OR Apache-2.0
13: 2.1.3 | ${jetty.base}/lib/ee10/jakarta.mail-api-2.1.3.jar | http://www.eclipse.org/legal/epl-2.0, https://www.gnu.org/software/classpath/license.html, http://www.eclipse.org/org/documents/edl-v10.php
14: 2.1.3 | ${jetty.base}/lib/ee10/jakarta.activation-api-2.1.3.jar | http://www.eclipse.org/org/documents/edl-v10.php
Active XMLs: ee10
-----------------
${jetty.home}/etc/jetty-ee10-webapp.xml
${jetty.home}/etc/jetty-ee10-deploy.xml
You'll see several sections here.
The first section shows you which modules are enabled.
The next few sections talk about your JVM
Then there's the layers being shown.
Each layer shows you the Properties, Classpath, and XML used for each layer.
The first layer you see is "Jetty", as that's the core layer, it has no Jakarta EE support.
The next layer you see is "ee10", that's the Jakarta EE 10 support layer.
Notice that the "Classpath: ee10" shows you that the 12th entry is your jetty-ee10-jndi-12.1.1.jar?
Hopefully this level of detail and example is enough to get you going.
- Joakim